Bad Timing when writing Messages

The free CAN Software API (Application Programming Interface) for Windows®
developer
Posts: 4
Joined: Thu 7. Apr 2016, 15:54

Bad Timing when writing Messages

Post by developer » Wed 31. May 2017, 18:38

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
Attachments
PCAN_Explorer6_received.JPG
PCAN_Explorer6_received.JPG (99.2 KiB) Viewed 8451 times

K.Wagner
Software Development
Software Development
Posts: 767
Joined: Wed 22. Sep 2010, 13:36

Re: Bad Timing when writing Messages

Post by K.Wagner » Thu 1. Jun 2017, 08:51

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)?
developer wrote:I use a seperate Thread with a Stopwatch in order to send out messages with an accuracy of about 1 ms.
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:Is there any way to send out messages more precise?
You need to use so called high resolution timers (also known as multimedia timers).
Best regards,
Keneth

developer
Posts: 4
Joined: Thu 7. Apr 2016, 15:54

Re: Bad Timing when writing Messages

Post by developer » Tue 6. Jun 2017, 15:16

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

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1187
Joined: Fri 10. Sep 2010, 19:34

Re: Bad Timing when writing Messages

Post by U.Wilhelm » Wed 7. Jun 2017, 09:06

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@peak-system.com
-------------------------------

riscy00
Posts: 2
Joined: Sun 18. Aug 2019, 00:40

Re: Bad Timing when writing Messages

Post by riscy00 » Wed 21. Aug 2019, 06:02

Can you send me C# multimedia timer example to ****** thanks.

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1187
Joined: Fri 10. Sep 2010, 19:34

Re: Bad Timing when writing Messages

Post by U.Wilhelm » Wed 21. Aug 2019, 09:04

We have removed your mail address...and send you the sample
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

kieldowdle
Posts: 4
Joined: Wed 10. Jul 2019, 22:01

Re: Bad Timing when writing Messages

Post by kieldowdle » Thu 5. Sep 2019, 21:26

I'm very interested in seeing that example as well if you don't mind.

from Admin: e-mail address removed - files send :D

Thanks.

horia
Posts: 2
Joined: Tue 30. Jun 2020, 08:44

Re: Bad Timing when writing Messages

Post by horia » Tue 30. Jun 2020, 08:49

Hi,
I would be interested to receive the multimedia timer files as well.
Email is the one used to register.

Thanks a lot!

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1187
Joined: Fri 10. Sep 2010, 19:34

Re: Bad Timing when writing Messages

Post by U.Wilhelm » Tue 30. Jun 2020, 08:57

@horia: mail was send
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

horia
Posts: 2
Joined: Tue 30. Jun 2020, 08:44

Re: Bad Timing when writing Messages

Post by horia » Thu 2. Jul 2020, 01:08

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?

Post Reply