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:
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.
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.
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.
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, Comparator - Wikipedia. Depending on the noise in your signal you can add hysteresis and if you don't know how, read this ap note Mixed-signal and digital signal processing ICs | Analog Devices . If you have any questions after reading the ap notes or your specific implementation, feel free to ask.
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.
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:
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.
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?