Been searching for answers on how to control the TC/Elcon chargers with CAN, especially the new UHF chargers you can get for cheap for the amount of power they put out. If you don't know or are familiar, they are high voltage battery chargers for electric vehicle battery packs. I’ve got the spec for the byte structure, and I’ve got some beginner knowledge in sending the CAN data packet with an Arduino microcontroller, like a nano or such. Now I read on the net that in CAN, every byte of the 8 bytes of data are in hexadecimal, makes sense. But also when you convert that hexadecimal value you decimal, it cannot exceed 255. But in the CAN spec from TC charger, it says for example the max charging voltage input is formatted at “3021” which would be equivalent to “302.1V”.
So 1. I don’t understand how to fit that large number when a byte can only be up to 255.
Check the attached spec, but they also state the max voltage in byte 1 and 2, and they call it the high and low byte. I just don’t know what that means. Like if my charge to voltage is 302.1 and the corresponding value is 3021 that needs to be sent, do I send “30” in byte 1 and “21” in byte two? Obviously those numbers converted into hex..
If anyone has any insight on this, that would be a HUGE help. I’m not a high level programmer, just an amateur. I’m trying to make a simple way to control these chargers since normally they aren't very user friendly.
I'll attach the byte spec sheet if anyone wants to take a look. Any help would be greatly appreciated!
The voltage is being encoded in two bytes. Byte 1 is the maximum terminal voltage high byte and byte 2 is the low byte. To extract the high and low bytes of a two byte integer, you're going to do something like:
int voltage = 3021;
byte v_low, v_high;
v_low = voltage & 0xff;
v_high = voltage >> 8;
Thank you both for the replies. This kinda makes more sense, I see how to split those hex values into the high and low.
That helps with the voltage adjustment of the charger but now about the current. The current for example if I want to set at 58.2 amps, I need to send a decimal value of 582. 582 converted to hex is 0x246
My question now is how do you split that into two bytes? I can split the other hex values, but this is an odd number and kinda throwing me off. Anyone know how to split that hex value into the high and low byte?
Thanks for the reply. I kinda understand how to split it up, but can you explain your bit of code some? Meaning just what each line does to help me understand a little better? Thanks!
This uses the bitwise AND operator, &, to keep the lowest eight bits of the 16 bit integer and force the high bits to be 0.
amperage >> 8
This uses the logical right bit shift operator to move the high eight bits down to the low eight positions (and throw away the former low 8 bits) yielding an 8 bit byte with just the high byte of amperage in it.