11-20-2014 03:38 AM
Hello
i have two while loops with each containint a case structure. i am using one while loop to transmit data over CAN and the other to recieve the CAN data.
i would like to sychronise the two loops so that the transmit and recieve while loops start at the same time
the reason i want this is because sometimes i see errors in the data transmitted due to an offset in time between the two loops operating. to me it seems like a slight time offeset builds up over time?
thanks
Brendan
11-22-2014 04:41 PM
Hi,
to synchronize 2 while loops you can use the "Rendezvous" functions (see attached picture). However, you might need to use a small delay in the receive loop in order to read the reply for the sent message.
11-22-2014 08:48 PM - edited 11-22-2014 08:50 PM
I can't envision what you are trying to do. In a case statement, only one loop will be running at a time because a case won't exit until the while loop inside has completed. How can you start them at the same time? Show us what you have. I'm not sure it's an optimal architecture? It sounds like an inside out state machine.
[edit]
Or maybe you meant they are in separate case structures? At any rate I'd like to see the code. Or at least a gutted version so I can see what you are trying to do.
[/edit]
11-24-2014 01:17 AM
Hi,
I think that "Master/Slave" or "Producer/Consumer" structure should be good for you. Idea with two while loops won't be work.
Try File -> New.. From templates to create the base structure for you.
Simyfren
11-24-2014 11:04 AM
So if you use wait until next ms multiple with a sufficiently long multiple, I don't think you'll see a ton of drift. However, to pull up a level -- what dyou want to do? I can't think of why you would ever want to synchronize an RX and TX loop, so it might help us help you if you give us a better explanation as to why the offset time is a bad thing.