lpf a pwm to an analog voltage

Thread Starter

TillFly

Joined Oct 26, 2016
69
Hello,

I want to create an analog voltage depending on the speed of a wheel.

Its powered from an arduino, goes through a voltage divider for an inductive sensor and then I would like to convert the PWM to an analog voltage with a lpf.
when I read out the pwm before the lpf with the arduino via analogread it shows me steady 509 and when the magnet passes I get a 0.
when I send it through the lpf the signal does not change in relation to the wheel speed.

what is wrong in the circuit?
lpf_circuit.jpg
thanks in advance
 

wayneh

Joined Sep 9, 2010
17,496
I don't understand your strategy. How will the mark space ratio change with RPM? Seems to me it's fixed by the geometry of the wheel.

What's the output of your sensor? I think you may need a diode to rectify your sensor signal. It may generate a negative pulse just as large as the positive pulse.
 

jpanhalt

Joined Jan 18, 2008
11,087
You may have better luck with a frequency to voltage converter. There are several chips available for doing that, such as the LM2907. There are alos DIY examples on the internet.

Or, simply use a timer in theMCU to determine the frequency. Since there is a negative impulse, you will need a diode to protect the Arduino input.

John
 

Thread Starter

TillFly

Joined Oct 26, 2016
69
I don't understand your strategy. How will the mark space ratio change with RPM? Seems to me it's fixed by the geometry of the wheel.

What's the output of your sensor? I think you may need a diode to rectify your sensor signal. It may generate a negative pulse just as large as the positive pulse.
What do you mean with "mark space ratio"?

simplyfied i´m recieving this kind of data before the lpf
I´m printing here
Serial.println(analogRead);

509 (wheel in movement)
509 (wheel in movement)
509 (wheel in movement)
509 (wheel in movement)
0 (magnet is in front of the speedometer sensor)
509 (wheel in movement)
509 (wheel in movement)
509 (wheel in movement)
0 (magnet is in front of the speedometer sensor)
509 (wheel in movement)
509 (wheel in movement)
0 (magnet is in front of the speedometer sensor)
...

so in this example the wheel is accelerating more and more.
at the moment i´m interpreting this as a kind of pwm where the on off ratio is practically something like 95 to 5 %.
is that thinking wrong?

I´m not sure about the voltage range and offset... I have to find that out
 

wayneh

Joined Sep 9, 2010
17,496
PWM is achieved by vary the ratio of on to off, the mark to the space. In your example this would be the time spent at 509 to the time spent at 0. The ratio is not changing with RPM.

What is changing is the length of either on or off, and the frequency at which it switches from one to the other. As noted, you may want a frequency to voltage converter.
 

Sensacell

Joined Jun 19, 2012
3,432
Your wheel pulses change in frequency, (slow-fast) but never change in duty cycle.
Always the same ratio of on to off time.

The Low Pass Filter averages the on/off ratio, this doesn't change, you cannot recover the speed using this technique.
 

wayneh

Joined Sep 9, 2010
17,496
Yup, that's the first circuit I ever built! I got it from the Forrest Mimms handbook that Radio Shack used to sell. I tested it with my guitar tuner and it was nicely linear.
 

Thread Starter

TillFly

Joined Oct 26, 2016
69
Or, simply use a timer in theMCU to determine the frequency. Since there is a negative impulse, you will need a diode to protect the Arduino input.

John
where and why is there a negative pulse? I thought that the range of 0 and 509 is 0 Volts and roughly 2.5V ...

I tried already in the mcu with the timer and it worked, but dont use a diode so far.
please let me know...
 

wayneh

Joined Sep 9, 2010
17,496
An inductive sensor may well produce a negative peak in symmetry with the positive peak. Magnet approaching versus magnet receding. It depends on the sensor, but if it's just a coil watching a magnet go by, you'll get a peak in both polarities. It's why an automotive alternator uses diodes to make DC.
 

jpanhalt

Joined Jan 18, 2008
11,087
where and why is there a negative pulse? I thought that the range of 0 and 509 is 0 Volts and roughly 2.5V ...

I tried already in the mcu with the timer and it worked, but dont use a diode so far.
please let me know...
wayneh beat me to it (post #10).

Inputs on microcontrollers will probably have some protective circuit. Look in the electrical specifications for the controller you are using to find the max + and - input voltages. Most often the tolerance to negative is pretting small. You might get by with a fast Schottky from the pin to ground.

John
 

jpanhalt

Joined Jan 18, 2008
11,087
That's one way to do it. The alternative is a full-way rectifier. For what you are doing, I would just use the half-wave rectifier as you have shown.

John
 
Top