Hi there,
I'm attempting to write a little program that controls a car wiper motor via CAN bus. The way that it works is that I send 3 extended CAN frames which control various things on the motor. Each particular function has a value, a start bit and a length in the frame, so for example in the first frame I have the following:
-
Wipe Frequency (this is a number between 15 and 63). Start bit 0, length 6.
Example 25 = 011001 in binary -
Interval time (0, 1, 2, or 3). Start bit 6, length 2
Example 2 = 10 in binary -
Wipe command (0, 1, 2, 3, 4, 5, 6 or 7). Start bit 8, length 3
Example 6 = 110 in binary
Once I have decided the value for each function and converted to binary of the length I require, I then join these together into a complete frame (up to 64 bits) like this:
0000010100001111000000000111100000001010001110011010100000100000
Then I will slice the complete frame into bytes of 8 to send as packets on the CAN bus.
Most of this is no problem, but I'm struggling to find a neat function to do what I'm doing in Excel using the following formula: "=BASE(DEC2BIN(I28),10,K28)"
Where DEC2BIN converts the value to binary, then the BASE function adds any zeros required to ensure I have the correct length to fit in the allocated slot in the frame.
Is anyone able to recommend an efficient way of doing this? Since I have quite a lot of values to process, I'd like to make the code nice and short but a quick trawl through google hasn't revealed an obvious solution or equivalent function.