2

I am attempting to interface an Arduino Mega 2560 with a system of four Black Jaguar motor controllers connected in CAN. I'm using the CAN shield from SeeedStudios to accomplish this.

The way Jaguars in CAN mode are configured, you must send a message every 100 ms to the network to keep the link active. However, I'm also getting input from Serial to another Arduino as well as sending other commands to the Jaguars, but not regularly enough to specifically time it out.

Is it possible to have the link message sent asynchronously in the background while I perform other code? I have looked into timers and interrupts, however I am unsure if this would truly solve the issue considering I have other processes that take more than 100 ms to complete.

Here's my loop statement:

loop() {
  CAN.sendMsgBuf(HEARTBEAT,1,0,volModeEnable); //HEARTBEAT keeps CAN link active
  setVoltage(3,.5); //Sets voltage of Motor by percent
  setVoltage(4,.5);
  setVoltage(6,.5);
  setVoltage(8,.5);
  //GrabFromSerial(); Takes longer than 100ms
  //Control Statement for Additional Commands goes here... (also necessary to be > 100ms)
}
dda
  • 1,595
  • 1
  • 12
  • 17

1 Answers1

1

I see several options:

  1. Change your code to achieve lower delays on the other functions
  2. Use interrupts at a set frequency to trigger the sending (and maybe the automatic transmission trigger pins, see MCP2515 datasheet, depending on pin use & schematic of your specific shield)
  3. Use a basic scheduler/rtos

It is hard to tell what is going on without the rest of your code, if it is a good idea to try to achieve faster functions.

I am not 100% sure the CAN-lib would will work well in the context of an interrupt.

Greenonline
  • 3,152
  • 7
  • 36
  • 48
CQuinson
  • 123
  • 7