CANOPEN SYNC timeout after enable Operation

614 views Asked by At

I am a newbie in CANOPEN. I wrote a program that read actual position via PDO1 (default is statusword + actual position).

void canopen_init() {
// code1 setup PDO mapping
nmtPreOperation();
disablePDO(PDO_TX1_CONFIG_COMM);
setTransmissionTypePDO(PDO_TX1_CONFIG_COMM, 1);
setInhibitTimePDO(PDO_TX1_CONFIG_COMM, 0);
setEventTimePDO(PDO_TX1_CONFIG_COMM, 0);
enablePDO(PDO_TX1_CONFIG_COMM);

setCyclePeriod(1000);
setSyncWindow(100);

//code 2: enable OPeration
readyToSwitchOn();
switchOn();
enableOperation();    
motionStart();

// code 3
nmtActiveNode();
}


int main (void) {
  canopen_init();   
  while {
    delay_ms(1);
    send_sync();
  }
} 

If I remove "code 2" (the servo is in Switch_on_disable status), i can read position each time sync send. But if i use "code 2", the driver has error "sync frame timeout". I dont know driver has problem or my code has problem. Does my code has problem? thank you!

2

There are 2 answers

0
HoanTV On BEST ANSWER

Problem fixed. Due to much EMI from servo, that make my controller didn't work properly. After isolating, it worked very well :)!

3
Lundin On

I don't know what protocol stack this is or how it works, but these:

setCyclePeriod(1000);
setSyncWindow(100);

likely correspond to these OD entries :

  • Object 1006h: Communication cycle period (CiA 301 7.5.2.6)
  • Object 1007h: Synchronous window length (CiA 301 7.5.2.7)

They set the SYNC interval and time window for synchronous PDOs respectively. The latter is described by the standard as:

If the synchronous window length expires all synchronous TPDOs may be discarded and an EMCY message may be transmitted; all synchronous RPDOs may be discarded until the next SYNC message is received. Synchronous RPDO processing is resumed with the next SYNC message.

Now if you set this sync time window to 100us but have a sloppy busy-wait delay delay_ms(1), then that doesn't add up. If you write zero to Object 1007h, you disable the sync window feature. I suppose setSyncWindow(0); might do that. You can try to do that to see if that's the issue. If so, you have to drop your busy-wait in favour for proper hardware timers, one for the SYNC period and one for PDO timeout (if you must use that feature).