how to use rpm sensor where frequency and amplitude of output varies [SOLVED]

I'm trying to use arduino to control a diesel motor EDC injection pump (and therefore the motor).
I already have the "power" part, where I can control the amount of fuel injected.
Now I want to read the motor RPM using a sensor that's already in the pump.
My electric/electronic skills are very limited, but from what I understood, it's a coil biased by a magnet that, when the teeth of a gear attached to the pump shaft pass by, induce a voltage.
The output looks roughly like a triangle-wave (maybe a sine?) in the oscilloscope, where both the amplitude and frequency varies with the rpm. Something from 2V (peak) to 7V and the frequency from 50Hz to 200Hz. I don't know how to use a oscilloscope very well, so this may be totally wrong, when I use a digital multimeter set to read AC, it varies from 1.5V to 6V (from the motor lowest rpm to very high).

I first thought to use a rectifier and capacitor (to smooth) and read the it using an analog pin. But now I think that if I'm able to read the frequency, by counting the peaks somehow, It will be a much better value. i.e. without noise or resolution problems, since it'd be digital by nature (I imagine).

I am a developer and coding is not the issue (I know interrupts, etc), my problem is the electronics: how do I hook it do my arduino?
If I do it directly, this high value (6V) for the higher speeds may damage it. And the lower value (1.5V) may not trigger the HIGH state on the pin. Are these assumptions right? How can I do this?

I can think of a couple of ways to measure the frequency:

  1. If the Arduino won't be doing much else, you can read the voltage continuously from an analog pin. If neither side of the sensor coil is grounded, I would connect one side to a 2.5v reference (1:1 voltage divider across the 5v supply) and the other to an Arduino analog input pin through a fairly high resistance (e.g. 100k). This resistance in conjunction with the protection diodes on the Arduino pin will prevent the voltage from damaging the Arduino. [Purists may object that the atmega328p doesn't specify an input clamp current rating. However, 70uA isn't going to harm it. If it worries you, use a voltage divider to reduce the voltage to 5 volts peak to peak.] Your sketch will need to do an analogRead on the pin at least every 1ms or so, looking for the polarity with respect to the 2.5v reference to change.

  2. If the Arduino is going to be busy with other tasks, then I would use a comparator IC with a little positive feedback to convert the input into a nice square wave. Feed that into a digital input pin, which can trigger an interrupt, and the interrupt servcie routine can either count pulses or track the time between pulses.

Purists may object that the atmega328p doesn't specify an input clamp current rating.

Yes it does it is 1mA but it is not in the data sheet.

I would feed the input into the base of a transistor through a 1K resistor. Emitter to ground, collector to arduino input and enable the internal pull up resistors. Put the other end of the coil to ground.

Grumpy_Mike:

Purists may object that the atmega328p doesn't specify an input clamp current rating.

Yes it does it is 1mA but it is not in the data sheet.

That's useful to know. Can you point me to a source for that information?

It says:-

It is not recommended that the clamping diodes are conducting more than maximum 1 mA

in Application note:- AVR182: Zero Cross Detector

thanks Mike!

It's in data sheet, paragraph 28 Electrical characteristics:

Injection Current at VCC = 5V ...................................... ±1.0mA

Most transistor wouldn't survive 7V reverse voltage on base-emitter junction, I'd add a protection diode to pass negative half-wave to ground.

Hi Magician,

Which datasheet is that? I'm using doc8271.pdf, downloaded from Atmel a few weeks ago, revision 8271D–AVR–05/11. On this sheet, "Electrical characteristics" is section 29, and the word "injection" isn't found in the document. I just searched the Atmel site again and it came up with the same document.

doc7810.pdf It's not clear what board OP has, but I think this parameter isn't varying much between other chips in this (8 - bit CPU) category, as it "technology" dependant.

Henrique,

dc42 suggested using a comparator in option 2 which is what I’d recommend. At my day job, I’m currently finishing a design where we needed to measure frequency off motors for aircraft. I used a comparator based circuit fed into a digital I/O pin, which I would recommend. If you’ve never used one before I’d recommend reading the wikipedia entry to get up to speed, http://en.wikipedia.org/wiki/Comparator. Depending on the noise in your signal you can add hysteresis and if you don’t know how, read this ap note http://www.maxim-ic.com/app-notes/index.mvp/id/3616 . If you have any questions after reading the ap notes or your specific implementation, feel free to ask.

Alan

Hi guys, thanks a lot for you help. I still has some doubts though. (my board is a 2009)

About the comparator solution, I read the links provided and searched trying to learn how to do it. I've came up with this schematic, is it correct?

About the transistor, is this what you meant?

Sorry for the delay on answering, the problem is that I have to study a lot before posting :slight_smile:

(edit: fixed img links)

I've came up with this schematic, is it correct?

Only if you post it or provide a link can we tell.

Thanks for the fast reply Grumpy_Mike.
I hope to have fixed the links now.

The comparator solution is only better than the transistor solution if you add some positive feedback to give it some hysteresis to improve noise immunity. Also, you may damage the comparator if you drive it directly from the sensor, so you must use at least a series resistor and preferably protection diodes as well (1N4148 or similar). See attached. I’ve omitted the resistor from the comparator output to Vcc on the assumption that you will use the internal pullup in the Arduino, as for the transistor solution. The LM193 or LM393 is a good choice because its common mode input range includes ground.

Better this way

The comparator solution as drawn (both of them) require a split power rail. Otherwise the +ve input is never going to be able to go below the -ve one to switch the comparator.

For a single rail solution:-
It is better if the -ve input is wired to a mid point between +5V and ground provided by a potential divider of two equal resistors, of say 10K.

@Grumpy_Mike
Hum... I think I understand. You say like this?

Yes that's it. :slight_smile:

Grumpy_Mike:
The comparator solution as drawn (both of them) require a split power rail. Otherwise the +ve input is never going to be able to go below the -ve one to switch the comparator.

The LM193 has a common mode input range that includes ground, because the input is a PNP emitter follower. The comparator in my circuit will quite happily switch when the inverting input goes negative by a few millivolts, which will happen when the input goes below -0.25v.

Thanks for the explanation dc42.

About your circuit, I didn't understood the diodes protection very well.
You connected two diodes "inverted" to each other between the comparator inputs?
Isn't it just like wiring the inputs together? How does that work?