PDA

View Full Version : Truth Tables



Rob Martin
- 13th April 2005, 17:35
(16f877 @20Mhz)
I 'm reading an incoming pulse and need to convert this to MPH.
I need to read the speed in under 250ms so I looked at using the code posted by Darrel Taylor

Pulse_Total = Pulse_High + Pulse_Low
RPM = 1000
RPM = RPM * RPM ' Preload internal registers with 1,000,000
RPM = DIV32 Pulse_Total ' 1,000,000 / Pulse_Total
RPM = RPM * 60 ' Per minute
RPM = Div32 40 ' 4 pulses per rev

Compared to using the COUNT function over a 1sec period the above method doesn't seem to give a very linear result. (although I'm not sure why)

So I was wondering if I could use the Pulsin to look at the high & low times then add these together and then search a table for the appropriate MPH.

I guess I would need 150ish entrys in the table is this feasable?

For the techies out there
I have a pic generating a test pulse of 488.8Hz and the signal is 50% duty cycle.

At 488.8Hz the Total_Pulse = 1021
At 247.1Hz the Total_Pulse = 2021
At 165.4Hz the Total_Pulse = 3022
At 124.3Hz the Total_Pulse = 4022
At 99.5Hz the Total_Pulse = 5022
At 76.6Hz the Total_Pulse = 6522
At 71.2Hz the Total_Pulse = 7022
At 62.3Hz the Total_Pulse = 8022
At 54.4Hz the Total_Pulse = 9022
At 49.8Hz the Total_Pulse = 10021
At 29.9Hz the Total_Pulse = 20021
At 20.0Hz the Total_Pulse = 25021
At 16.6Hz the Total_Pulse = 30022

Just as I was taking these readings I notice they all end in 21/22?
Am I doing something wrong?
If it makes any different I'm using PORTA.4

Rob