lpf a pwm to an analog voltage

Discussion in 'The Projects Forum' started by TillFly, Dec 6, 2016.

  1. TillFly

    Thread Starter Member

    Oct 26, 2016
    53
    0
    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
     
  2. wayneh

    Expert

    Sep 9, 2010
    16,099
    6,212
    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.
     
  3. jpanhalt

    Expert

    Jan 18, 2008
    7,412
    1,719
    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
     
  4. TillFly

    Thread Starter Member

    Oct 26, 2016
    53
    0
    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
     
  5. wayneh

    Expert

    Sep 9, 2010
    16,099
    6,212
    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.
     
  6. Sensacell

    Moderator

    Jun 19, 2012
    2,362
    761
    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.
     
    TillFly likes this.
  7. DickCappels

    Moderator

    Aug 21, 2008
    5,590
    1,747
    You can achieve duty cycle modulation ((PWM) by placing a one-shot between your pulse source and the low pass filter. An NE555 would probably work wonderfully. The result is a tachometer.

    upload_2016-12-7_17-18-22.png
    http://www.tradeofic.com/Circuit/904-ANALOG_TACHOMETER_CIRCUIT.html

    In the example above the inertia of the meter movement provides the low pass filtering of the pulse.
     
  8. wayneh

    Expert

    Sep 9, 2010
    16,099
    6,212
    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.
     
  9. TillFly

    Thread Starter Member

    Oct 26, 2016
    53
    0
    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...
     
  10. wayneh

    Expert

    Sep 9, 2010
    16,099
    6,212
    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.
     
  11. jpanhalt

    Expert

    Jan 18, 2008
    7,412
    1,719
    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
     
  12. TillFly

    Thread Starter Member

    Oct 26, 2016
    53
    0
  13. jpanhalt

    Expert

    Jan 18, 2008
    7,412
    1,719
    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
     
    TillFly likes this.
Loading...