CAN communication

From openinverter.org wiki
Jump to navigation Jump to search

The Revision 2 main board supports CAN communication. The CAN bus can be used for configuration and for obtaining values like voltages, input states etc. The CAN messages are configurable and can be adjusted to be compatible with existing equipment.

Since firmware 3.75 throttle and digital inputs can be controlled via CAN.

Be aware that all CAN mapping uses decimal numbers. So COB ID 0x123 must be entered as 291

Controlling throttle via CAN

If you want to send the throttle and regen magnitude commands via CAN rather then via analog inputs you have to set "potmode" to "CAN" (=2). Next you have to map a CAN message to pot and optionally pot2. So say you have a digital throttle that sends values from 0 to 1000 for 0 to 100% travel on CAN-Id 100 in the first two bytes.

  • Configure potmin=0 and potmax=1000
  • Map CAN message to pot: can rx pot 100 0 16 32

The last parameter, 32, tells the CAN module to apply the internal fixed point scaling.

CAN messages must be received every 500ms, otherwise throttle times out and is set to 0.

Controlling Digital IO via CAN

6 signals, namely cruise, start, brake, forward, backward and bms can be controlled via CAN. The CAN message is ORed to the physical inputs so you can have mixed signals also. Digital CAN IO doesn't need to be explicitely configured, it works as soon as you map a CAN message to "canio". "canio" is bit-encoded:

  • Bit 0: cruise
  • Bit 1: start
  • Bit 2: brake
  • Bit 3: forward
  • Bit 4: reverse
  • Bit 5: bms

So say you have a BMS that transmits an over/under voltage bit on CAN Id 200, 2nd data bit

can rx canio 200 2 1 1024

Note the 1024x gain that shifts the bit into the correct position (5 fraction bits plus 5th data bit). In this case all other IOs remain traditional, only BMS is controlled via CAN. Note that you cannot map multiple CAN messages onto "canio" as they would overwrite each other.

If you have a managed to mangle all 6 bits into one message, say CAN Id 300, first 6 bits the mapping is done like so

can rx canio 300 0 6 32

The same timeout mechanism is used as for throttle control, so after 500ms with no message the CAN-mapped inputs are assumed off. Traditional inputs remain unaffected.

Setting and reading parameters via SDO

The abbreviation SDO is taken from the CANOpen protocol. It assigns a certain meaning to the 8 data bits of a CAN frame.

Note that SDO semantics (cmd) were changed since version 5.20.R of the inverter firmware. Old cmd value is in ()

Purpose CAN-Id Byte 1 (Cmd) Bytes 2-3 (Index) Byte 4 (Subindex) Bytes 5-8 (Data)
Set Value 0x601 0x23 (0x40) 0x2000 Value Index Value x 32
Set Value Reply 0x581 0x60 (0x23) 0x2000 Value Index Value x 32
Get Value 0x601 0x40 (0x22) 0x2000 Value Index don't care
Get Value Reply 0x581 0x43 0x2000 Value Index Value x 32
Map Value TX to COB ID yyy 0x601 0x40 0x3yyy Value Index Byte 5: bit offset, Byte 6: bit length, Bytes 7,8: scaling
Map Value RX to COB ID yyy 0x601 0x40 0x4yyy Value Index Byte 5: bit offset, Byte 6: bit length, Bytes 7,8: scaling
Abort - invalid index 0x581 0x80 Index of request Value Index Abort Code = 0x06020000
Abort - value out of range 0x581 0x80 Index of request Value Index Abort Code = 0x06090030
Set Param 0x601 0x23 (0x40) 0x21xx xx=MSB UID Param UID LSB Value x 32
Set Param Reply 0x581 0x60 (0x23) 0x21xx xx=MSB UID Param UID LSB Value x 32
Get Param 0x601 0x40 (0x22) 0x21xx xx=MSB UID Param UID LSB don't care
Get Param Reply 0x581 0x43 0x21xx xx=MSB UID Param UID LSB Value x 32

The value index must be determined by counting the output of the list command. E.g. "boost" at the very top has index 0, potnom has index 77. The indexes can change over firmware versions as new parameters are added somewhere in between.

The Get/Set Param commands use the unique parameter identifier assigned to each savable parameter. These do not vary between firmware versions. Only savable parameters not spot values can be read and written by these commands.

Examples

0x601 # 0x22 0x00 0x20 0x00 0 0 0 0 Get value of "boost"

0x601 # 0x40 0x00 0x20 0x01 0x80 0x0C 0 0 Set "fweak" to 100Hz (0xC80=3200 because scaled by 32)

0x601 # 0x40 0xAA 0x31 0x01 0x08 0x10 1 0 Map value of fweak to COB ID 0x1AA, starting at bit 8, stretching 16 bits, scaled by 1

0x601 # 0x22 0x10 0x20 0x0D 0 0 0 0 Get value of "pwmfrq" on any firmware version or build (0x0D = 13 from the PARAM_ENTRY() for "pwmfrq" in param_prj.h)

Mapping values to arbitrary CAN messages

Values can be mapped into a certain bit range of the 64 payload bits of a CAN message. They can either be read from the message or sent via a message. To do so enter

can tx udc 123 0 16 10

This maps the value of udc to a CAN message with id 123 bits 0..15 (start at bit 0, span over 16 bits) with a gain of 10.

can tx din_forward 123 24 1 1

would map the pin state of the forward input to bit 24 of CAN message with id 123.

If you want to clear all messages, type

can clear

If you want to remove only a specific signal (starting version 4.18.R) type

can del <name>

To save your can map simply type "save".


idcmin, idcmax example

Mapping Values through the web interface

Value can also be mapped through the web interface.

Spot values
Spot values
  • CAN Id
    • This is the Can Id assigned to the message.
  • Position
    • This is where in the 64 bit length of the CAN message the data should start.
  • Bits
    • How many bits are assigned to send the data.
  • Gain
    • This applies the internal fixed point scaling.
  • Map to CAN
    • TX to tell the control board to transmit the data onto the CANBUS
    • RX to tell the control board to expect to receive this data from the CANBUS

Limits

  • A maximum of 10 messages can be defined
  • Per message a maximum of 8 values can be mapped
  • a value can not span across the 32-bit boundary, i.e. it must be fully contained in the first or second 32 bits of the message. E.g. "can tx udc 123 16 32 10" is not allowed
  • A value can span maximum 32 bits

Endianness

CAN messages sent to, or received from the inverter are Little-endian.

If you are sending or receiving messages containing multi-byte values then the byte order must be taken into account.