Counting pulses with digital input
I want to count the cycle of an engine. I am using a proximity switch. It sends a pulse every round to DC522. I want to count to 800 rpm. I am trying to way;
1) I just count these pulses with CTU for 10 seconds. Than I'm multiplying by 6. But it is a very slow method and high fault tolerance.
2) I 'm measuring the time between two pulses. And doing this;
rpm=60000(ms)/time (ms) By this method, the results constantly change. Especially at high speeds.
What can i do? Is there anybody who has different idea?
Voted best answer
On DC522 you have 2 fast counting channels and these channels are 4.0 and 4.1 (C8 and C9), when using the module with AC500 CPU - may be you know that.
I used such modules and counters for higher speed and it is working good. In my application, I use method 1 - counting of pulses for defined period.
But depends on measured speed, I switch over the scan time for better precision:
for speed under 300 rpm I'm using scan time 1 s with multiplier 6, and for speed over 400 rpm I use scan time 2 s with multiplier 3. In this way also ensure hystereis between 300 and 400 rpm.
All this of course depends on how many pulses per revolution you have mechanically.
If you want, I can send you print of this code.
You can't use a digital input for this. You MUST use a pulse input channel.
DI channels have anti alias filtering to remove high frequency noise from on off transitions and are totally dependant on the scan rate of your program. Alwaus use a dedicated pulse input channel where the counting is done in hardware. For high frequency signals you might still need a filter as the value will have some noise. 1 to 2 seconds should be enough. If it's more than 10 secs or so you have a problem in the input that you should try to resolve.