PLUS+1 User Forum

PLUS+1 Hardware => Controllers => Topic started by: jrward1977 on March 25, 2025, 10:25:34 PM

Title: Accurate Frequency, but Inaccurate pulse Count
Post by: jrward1977 on March 25, 2025, 10:25:34 PM
I have an MC050-010 with a simple speed sensor and I'm trying to get speed and distance.  The speed (frequency) is accurate but when I get over 25hz the pulse count is not keeping up.  What am I doing wrong?
Title: Re: Accurate Frequency, but Inaccurate pulse Count
Post by: Lukey on March 25, 2025, 11:57:09 PM
What pin are you using for the input?

Can you please share a snippet of your code?
Title: Re: Accurate Frequency, but Inaccurate pulse Count
Post by: jrward1977 on April 01, 2025, 11:07:41 PM
Apologies for the delayed response. 
I'm using pin 19, standard Danfoss speed sensor.  I have verified that it is properly adjusted.  I have attached a drive link to the .p1p file.  Many thanks for taking a look at it.

https://drive.google.com/file/d/1Y3IBoqeR5lJAkIsWtt3FziyghowtcL7y/view?usp=sharing
Title: Re: Accurate Frequency, but Inaccurate pulse Count
Post by: acmall on April 02, 2025, 09:53:12 AM
How are you counting the pulses?
I don't see anything on Pin 19. Is it the same as Pin 18 where there is a Carriage_Count signal connected from the DigIn to a loop counter in software?
This will be limited by the program loop time and any pin de-bouncing, etc. that may be done behind the scenes by the controller firmware.

You can use the Count signal from the pin which will report the number of pulses in the last program loop. You can add this each loop to keep a total count. See example in the image.

Forum is refusing to attach an image, so here is a link.
https://mallaghan-my.sharepoint.com/:i:/g/personal/alastair_cardwell_mallaghangroup_com/ERBvHI_ze29OiOCi19p-EW8B4ccK9Mk167E5wFAXvEP9SQ?e=1bjgWe (https://mallaghan-my.sharepoint.com/:i:/g/personal/alastair_cardwell_mallaghangroup_com/ERBvHI_ze29OiOCi19p-EW8B4ccK9Mk167E5wFAXvEP9SQ?e=1bjgWe)
Title: Re: Accurate Frequency, but Inaccurate pulse Count
Post by: G30RG3 on April 02, 2025, 02:30:01 PM
Your loop counter with 999999 as Max value in U16 will go in overflow, and rather soon.
Also you're using the DIgIN signal which will count once every program loop. If your program loop is longer than 40ms, the counter will add 1 for every program loop where the DIGIn value is seen as "high".
Use the .Count, and add them every program loop instead.
Title: Re: Accurate Frequency, but Inaccurate pulse Count (Solved)
Post by: jrward1977 on April 02, 2025, 11:19:52 PM
Thank you to everyone who replied! I believe we can mark this down as solved.  Acmall, your example was tremendously helpful.  I was under the impression that the digital input worked like an interrupt on a simple micro controller.  Thank you G30RG3 for your explanation.