Bad Timing when writing Messages
Bad Timing when writing Messages
Hello guys,
I just implemented my first Program in C# using the PCAN Basic API.
I use a seperate Thread with a Stopwatch in order to send out messages with an accuracy of about 1 ms.
When I hooked up 2 PCAN-CAN-USB Devices together, one linked to my program, the other one connected to PCAN-Explorer 6 I discovered really bad timing on the receiving messages in PCAN-Explorer 6 (See attached picture).
Is there any way to send out messages more precise?
Thanks a lot for your help,
developer
I just implemented my first Program in C# using the PCAN Basic API.
I use a seperate Thread with a Stopwatch in order to send out messages with an accuracy of about 1 ms.
When I hooked up 2 PCAN-CAN-USB Devices together, one linked to my program, the other one connected to PCAN-Explorer 6 I discovered really bad timing on the receiving messages in PCAN-Explorer 6 (See attached picture).
Is there any way to send out messages more precise?
Thanks a lot for your help,
developer
- Attachments
-
- PCAN_Explorer6_received.JPG (99.2 KiB) Viewed 14827 times
Re: Bad Timing when writing Messages
Hello,
it seems as you have a sending average of 500 milliseconds. Please check your sending thread, for instance, the way how you calculate the sending pause between messages. Do you use any kind of sleep function, e.g.System.Threading.Thread.Sleep(xxx)?
it seems as you have a sending average of 500 milliseconds. Please check your sending thread, for instance, the way how you calculate the sending pause between messages. Do you use any kind of sleep function, e.g.System.Threading.Thread.Sleep(xxx)?
I'm not quite sure how you are using an Stopwatch for message sending. The Stopwatch has no "Elapsed" event (or any other event); it is thought to be used as diagnostic tool, for instance, for time measurement in your code (e.g. the time it takes to execute a function).developer wrote:I use a seperate Thread with a Stopwatch in order to send out messages with an accuracy of about 1 ms.
You need to use so called high resolution timers (also known as multimedia timers).developer wrote:Is there any way to send out messages more precise?
Best regards,
Keneth
Keneth
Re: Bad Timing when writing Messages
thank you for your reply!
Yes correct, as a first test I wanted to sent out a test frame each 500ms. I tried implementing such a High resolution timer but that didn't improve the timing by much.
I fixed this issue by generating a List of TPCANMsg objects and than having a High Priority thread just sending out these message structures. I now achieve a timing resolution of about 1-2 ms which works for me.
I use System.Threading.Thread.Sleep(xxx) for the waiting period between 2 frames. The Stopwatch was only implemented as a check
Yes correct, as a first test I wanted to sent out a test frame each 500ms. I tried implementing such a High resolution timer but that didn't improve the timing by much.
I fixed this issue by generating a List of TPCANMsg objects and than having a High Priority thread just sending out these message structures. I now achieve a timing resolution of about 1-2 ms which works for me.
I use System.Threading.Thread.Sleep(xxx) for the waiting period between 2 frames. The Stopwatch was only implemented as a check
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Bad Timing when writing Messages
If you need a 1ms timer on Windows which is accuracy, simply use the MultiMedia Timer. If you use C or C# we could send you a sample how to use. It works for us very fine in many applications.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: Bad Timing when writing Messages
Can you send me C# multimedia timer example to ****** thanks.
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Bad Timing when writing Messages
We have removed your mail address...and send you the sample
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
-
- Posts: 4
- Joined: Wed 10. Jul 2019, 22:01
Re: Bad Timing when writing Messages
I'm very interested in seeing that example as well if you don't mind.
from Admin: e-mail address removed - files send
Thanks.
from Admin: e-mail address removed - files send

Thanks.
Re: Bad Timing when writing Messages
Hi,
I would be interested to receive the multimedia timer files as well.
Email is the one used to register.
Thanks a lot!
I would be interested to receive the multimedia timer files as well.
Email is the one used to register.
Thanks a lot!
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Bad Timing when writing Messages
@horia: mail was send
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: Bad Timing when writing Messages
Thanks a lot for sending the example.
One followup :
Using PCAN Explorer, it is possible to send a CAN message in a loop, by setting "Cycle time", with <1ms timing accuracy(as far as I experimented)
Is this "loop" function available using pcanbasic, or in the "PEAK-Developer" package? Or it's specific to PCAN Explorer?
One followup :
Using PCAN Explorer, it is possible to send a CAN message in a loop, by setting "Cycle time", with <1ms timing accuracy(as far as I experimented)
Is this "loop" function available using pcanbasic, or in the "PEAK-Developer" package? Or it's specific to PCAN Explorer?