Go Down

Topic: how to use rpm sensor where frequency and amplitude of output varies [SOLVED] (Read 3620 times) previous topic - next topic

Henrique Abreu

Oct 06, 2011, 12:12 am Last Edit: Oct 11, 2011, 08:11 pm by Henrique Abreu Reason: 1
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?

dc42

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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Grumpy_Mike

Quote
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.

dc42


Quote
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?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Grumpy_Mike

It says:-
Quote
It is not recommended that the clamping diodes are conducting more than maximum 1 mA


in Application note:- AVR182: Zero Cross Detector

dc42

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Magician

It's in data sheet, paragraph 28 Electrical characteristics:
Quote
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.

dc42

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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Magician

http://www.atmel.com/dyn/products/product_docs.asp?category_id=163&family_id=607&subfamily_id=1723&part_id=4662
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.

ams0178

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

Henrique Abreu

#10
Oct 06, 2011, 03:56 pm Last Edit: Oct 06, 2011, 04:25 pm by Henrique Abreu Reason: 1
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 :)

(edit: fixed img links)

Grumpy_Mike

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

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

Henrique Abreu

#12
Oct 06, 2011, 04:12 pm Last Edit: Oct 06, 2011, 04:26 pm by Henrique Abreu Reason: 1
Thanks for the fast reply Grumpy_Mike.
I hope to have fixed the links now.

dc42

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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Magician


Go Up