how to read signal from magnetic RPM sensor

merk

Member
I would like to connect motorcycle magnetic RPM sensor to PIC16F1827 MCU. Output signal is AC voltage in a range from 2 to 10V (measuring with multimeter, in reality signal goes from negativ to positiv voltage each time gear tooth passes the coil. I was thinking to first use a diode to rectify AC then drive this through the MOSFET and to the PIC CCP input. I would use PIC's ST input on CCP module in capture mode to measure time it takes the signal to change its state from high to low voltage. Also I would be reading hall effect speed sensor, but this sensor already has digital output. Please note the wiring diagram marked with red square.
 
Last edited:
Looks ok to me, assuming the coil never goes over 10V. You could diode-clamp it to the +12V rail if there's a possibility otherwise. Maybe add a 10μF filter cap on the 5V side, I don't trust the two .1's to do all the filtering even with just a 7-segment LED load. You are going to need to activate the weak pullups on RA0 and RA1... but you probably already know that. I would suggest doing the measurement from rising-edge to rising-edge instead of measuring the width of a positive pulse, you will get more accurate reads that way.
 
Last edited:
I worked on a tachometer a while ago. For low frequencies, someone recommended reading time between pulses. I tried that and found that as the frequency increases, the time between pulses shortens exponentially. Think about it, the difference between 1 RPM and 2 RPMs is 30 seconds. The difference between 10,001 RPMs and 10,002 RPMs is a whole lot less than 30 seconds.
 
I tried that and found that as the frequency increases, the time between pulses shortens exponentially.

Good point!

So it would probably make more sense to set a timer for 0.46875 seconds, count tach pulses during this interval, then multiply by 128 (left-shift 7x), and this will give you RPM.
 
then do one simple calc; RPM = (60000000 / period_in_uS)

Just check to make sure there's any room left for the code after you load the floating-point math library into that chip with 4k of memory and 384 bytes of RAM.
 
I get your point.

But it doesn't require floating point code, only an unsigned long (32bit) division. Maybe 200 words of ROM for the 32bit_unsigned_div function.

If ROM is limited, it can be done with almost no ROM by using successive division like this (a system I have used in the past);
Code:
unsigned long period_uS;
unsigned long math1;
unsigned long result;

// 32bit unsigned long division using minimal code size.
math1 = 60000000;
result = 0;
while(math1 >= period_uS)
{
  math1 -= period_uS;
  result++;
}

The whole thing ends up at about 40 to 50 ROM words or so.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…