eBIMMER
Posts: 7
Joined: Sat Jun 06, 2020 2:14 pm
Delivery Date: 06 Jun 2020

RPM CanBus Scaling 0x1DA

Wed Jan 20, 2021 10:56 pm

So CanBus message on bytes 4 and 5 of 0x1DA reads RPM. Does anybody know the proper scaling for this value to get actual RPM of motor?

I use the Leaf system in another vehicle without the gearbox so it is a little harder to figure it out mathematically.

Multiplying x10 is too high, as the value read 14,200 at one point.

Anybody? Thanks!

User avatar
Dala
Forum Supporter
Posts: 301
Joined: Sun Oct 28, 2018 11:24 am
Delivery Date: 01 Jan 2015
Leaf Number: 316851
Location: Finland
Contact: Website

Re: RPM CanBus Scaling 0x1DA

Thu Jan 21, 2021 12:39 am

Yes, it is a signed message with no scaling. Just pay attention to where it starts, and the signed bit indicating positive/negative rotation

Image
https://github.com/dalathegreat/leaf_can_bus_messages

eBIMMER
Posts: 7
Joined: Sat Jun 06, 2020 2:14 pm
Delivery Date: 06 Jun 2020

Re: RPM CanBus Scaling 0x1DA

Fri Jan 22, 2021 7:46 am

Thank you for the reply. I am very new to working with Canbus and interpreting bytes, etc.

Based on your input it sounds like the problem must be in my code and possibly the way I'm handling the values. I adjusted a bit shift, removed scaling, and will see what sorts of values I get.

I am using an Arduino to process the signals and then sending via serial to a display, so there are a few places where I could be skewing the number.

Thanks again!

eBIMMER
Posts: 7
Joined: Sat Jun 06, 2020 2:14 pm
Delivery Date: 06 Jun 2020

Re: RPM CanBus Scaling 0x1DA

Sat Jan 23, 2021 1:05 pm

I have been struggling a little bit to get my values to read properly. I hope somebody here who understand byte processing can help tell me what I'm doing wrong.

The Arduino code that interprets my RPM value is below:

Code: Select all

RPM = (rxBuf[4] << 2) | (rxBuf[5] >> 6);
But this outputs RPM values that hover around 35 and range from 0 up to about 60.

I am going to try the line below, which is my best guess at "gluing the byte values together" based on some tutorials I've read online:

Code: Select all

RPM = (rxBuf[4] << 8) | rxBuf[5];
I would be grateful for any advice on this from those who know.

Thanks! :mrgreen:

User avatar
Dala
Forum Supporter
Posts: 301
Joined: Sun Oct 28, 2018 11:24 am
Delivery Date: 01 Jan 2015
Leaf Number: 316851
Location: Finland
Contact: Website

Re: RPM CanBus Scaling 0x1DA

Sat Jan 23, 2021 2:47 pm

The most significant bit is the sign bit. The rest contains the data. Quick pseudocode to read RPM and disregard the sign would be

int rpm = ((frame4 & 0x7F ) << 7) | frame5 >> 1;

This might be wrong, it's 1AM and I'm tired :D

eBIMMER
Posts: 7
Joined: Sat Jun 06, 2020 2:14 pm
Delivery Date: 06 Jun 2020

Re: RPM CanBus Scaling 0x1DA

Sat Jan 23, 2021 4:28 pm

Dala wrote:
Thu Jan 21, 2021 12:39 am
Yes, it is a signed message with no scaling. Just pay attention to where it starts, and the signed bit indicating positive/negative rotation
I've downloaded the DB tool - thank you for linking me to this. It will be incredibly helpful!

I'm editing this post based on your last reply. Thank you for the help. My removed post suggested scaling by 0.641 so max value would be 10,500 which I believe is the max speed of the motor.

I'll hold off on scaling and try your code to bypass the sign bit. I should note that we may be using different Leaf systems. I'm using a ZEO and per the database for this vehicle, these bytes are listed as being an unsigned value. Anyway, per your reply, the line going onto my Arduino for test is below. I should have an update in a few hours or a day.

Code: Select all

RPM = (rxBuf[4] << 7) | (rxBuf[5] >> 1 );
Thanks again!

Return to “LEAF CANBus”