I would think so. At 100 MPH you should be getting 320 pulses per second, one every 3 milliseconds. That's pedestrian for an RP2.Am I over complicating this?
I am not sure why using interrupts wouldn't work to keep count of the pulses but I'm not familiar with Arduino coding. Maybe there's an issue with how you have implemented your code ?
The way I have considered doing it is to maintain an array of elapsed time from one reading to the next -
Code:
Pulses _|___|___|__|____|_____|_____|____|_____|__|_|___|__|___Time 0123456789-123456789-123456789-123456789-123456789-1234Interval 4 4 2 5 6 6 5 6 3 2 4 2
Assuming the intervals here were 10ms periods the above would indicate 12 pulses in 490ms. An average of 40.8ms per pulse. That works out at 24.5 pulses per second, about 7.7 MPH.
Proof of concept in Python / MicroPython - But check the maths !
Code:
intervals = [40, 40, 20, 50, 60, 60, 50, 60, 30, 20, 40, 20]pulses = len(intervals)period = 0for interval in intervals: period += intervalprint("{} pulses in {} ms".format(pulses, period))pulsesPerSecond = (1000.0 / period) * pulsesprint("{:5.2f} pulses per second".format(pulsesPerSecond))mph = (pulsesPerSecond / 8) * 2.5print("{:5.2f} MPH".format(mph))
Code:
12 pulses in 490 ms24.49 pulses per second7.65 MPH
It's also continuous, no need to wait for any time; just copy the array, add it up and use it whenever you want to show it.
This seemed more accurate to me than the chance of missing a pulse just before and just after any period being measured but I've never tried it.
Statistics: Posted by hippy — Sat Aug 17, 2024 5:44 pm