1

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!

Lundin
  • 195,001
  • 40
  • 254
  • 396
HoanTV
  • 23
  • 5
  • 1
    This is all higher layer API belonging to some CANopen protocol stack, so it's kind of hard to tell. Which stack is it? The sync mechanism of CANopen is mainly used to have PDOs respond upon getting the sync message, or within a specified time after getting sync. Or in real-time systems you can simply use it as a simple system clock and activate outputs at the point where you get the sync. Anyway, I suppose you should check what these "1000" and "100" values mean. CANopen OD isn't consistent with units - sometimes it means milliseconds, sometimes some other time unit. – Lundin Apr 28 '21 at 07:58
  • I read on a document from the manufacture. it said set transmision type is 1-240 and send sync. Both of sync period and sync window time are in micro second as document said – HoanTV Apr 28 '21 at 11:07

2 Answers2

0

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).

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • I use CANOPEN 402, because i send PDO immediately after SYNC, so i think 100us is enough. I tried setSyncWindow(0) and setSyncWindow(1000) ; but same, SYNC timeout still occurs. Here is the result: Sync sent 160 times and TX PDO send back 112 time before driver show alarm "sync frame timeout" – HoanTV Apr 28 '21 at 16:29
  • @HoanTV So maybe the problem isn't with the SYNC producer but some other node? – Lundin Apr 29 '21 at 06:46
  • After i set syncWindow(100), txpdo update 800 times when 900 sync sent. I am trying find other servo to test. – HoanTV Apr 29 '21 at 10:28
0

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

HoanTV
  • 23
  • 5