PWM to frequency converter

Discussion in 'Analog & Mixed-Signal Design' started by cmartinez, Sep 29, 2016.

  1. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    A few years ago, I designed a multi-axis step motor controller using one AT89LP4051 MCU as a master pulse generator, and an identical slave MCU for each axis being controlled in the system; using Bresenham's interpolation algorithm. The board is working like a real beauty, but I'd like to improve it by increasing the frequency resolution generated by the master MCU. Currently, the master MCU is generating the pulse train by consulting a small table in its program that allows it to generate 32 different speeds (frequencies).

    My idea is to increase that speed (frequency) resolution to 256 speed levels by using the PWM capability already included in the marvelous AT89LP4051. Never mind for now how I plan to develop the firmware needed for this task. Suffice it to say that I already have a clear picture on how to do that.

    The problem I'd like to solve is how to convert a PWM signal to a frequency one, considering the following restraints:
    • Power source is a single power supply, which is an ordinary 12VDC regulated wall wart.
    • An LM7805 regulator is already present in the circuit, so a 5V supply is already available.
    • Generated square wave must be 0-5VDC, and should be in the range of 0 to 60kHz, in 256 equally divided steps.
    • Duty cycle should be as close to 50% as possible.

    I've already done a little research on this subject, and I've arrived to conclusion that the best way to achieve what I want is to first convert the signal to a proportional voltage, and then convert that voltage to a frequency.

    Converting a 5V PWM signal to a linear voltage seems easy enough. A 2nd order low pass filter should do the trick:

    Capture.JPG



    My itch is with how to properly convert that linear output voltage to a frequency signal as accurately as possible. I've done some googling on the subject and, among many other things, I found these three candidates:

    s200971205630850.jpg

    435_circuit_1.jpg

    234_circuit_1.jpg



    The three circuits are so different from one another that I'm at a loss on how to decide which one would be best for my application.

    Any input on this matter would be thoroughly appreciated.
     
  2. ronv

    AAC Fanatic!

    Nov 12, 2008
    3,282
    1,233
    I kind of like the old IC. Just seems simple.
    http://pdf1.alldatasheet.com/datasheet-pdf/view/87731/FAIRCHILD/RC4151.html
     
    cmartinez likes this.
  3. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    Seems like a very complex and imprecise way of managing stepper motors.

    Some of the newer MCU's have really sophisticated pulse timing and management hardware built it- no analog vagueries to contend with?
     
  4. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,675
    899
    There are/were lots of voltage to frequency and F to V converters. The KA331, NJM4151, RC4152, and LM2907 are some examples. The datasheet for the LM2907 has an interesting application using that device to convert dwell time to voltage.

    Digitally, I would consider using the capture peripheral of a PIC to get the duty cycle and then use a DDS module to get frequency.

    Edit: I was focused on the PWM to frequency question. Last year, I used what was effectively the PWM duty cycle from an AS5048A to drive a stepper in quarter step mode . That was simply based on the ratio between the number of steps per revolution of the stepper motor and the number of counts/PWM percentage of the encoder. The processor was a PIC 16F1829.

    John
     
    Last edited: Sep 29, 2016
    cmartinez likes this.
  5. dannyf

    Well-Known Member

    Sep 13, 2015
    1,771
    358
    + lpf + vco.
     
  6. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    Thanks, but I'm not sure I quite follow. Would you mind elaborating? My goal is to have an easy to control frequency source while the MCU is busy simply counting steps, and requesting the desired frequency according to the desired speed curve.

    Have some mercy, Danny. English is not my mother language, so acronyms are not my strength ... I take it vco means Voltage Controlled Oscillator, but what is lpf?
     
  7. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    Many thanks, John. I'll look those datasheets up and then get back here with my observations.
     
  8. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
  9. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,128
    266
    cmartinez likes this.
  10. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    Thanks, John. I've already gone through the parts you've suggested. Here's what I found:
    • KA331 - Dual power supply
    • NJM4151D - unavailable
    • RC4152 - couldn't find it
    • LM2907 - F to V, not V to F
    Any other options?
     
  11. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    I think I forgot to mention that the entire system is slave to an external encoder. That's why I'm resourcing to an external pulse source.

    Either way, I'm carefully considering your suggestion at this moment, btw. Thanks!
     
  12. ronv

    AAC Fanatic!

    Nov 12, 2008
    3,282
    1,233
    Ahh, I just looked at your diagram. But wait, there's more. A newer version. at Mouser.
    http://www.ti.com/lit/ds/symlink/lm331.pdf
     
    cmartinez likes this.
  13. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,675
    899
    My datasheet for the KA331 shows it to be single supply.

    upload_2016-9-30_0-50-21.png

    I have experience with it and some of its kin for helping posters doing speedometer conversions. Another option is the AD650, which is either V-F or F-V, but it is is quite expensive (Mouser = $25 in single quantity).

    Edit: You can also use the control voltage pin (#5) on a 555 to give a poor man's V-->F converter.

    John
     
    Last edited: Sep 30, 2016
    cmartinez likes this.
  14. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    Incredibly, I have one of those laying around! ... gonna look it up ... thanks!
     
  15. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    Thanks, Ron. Gonna study it carefully, then I'll get back to you.
     
  16. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,555
    2,517
    Would you mind elaborating?
     
  17. OBW0549

    Well-Known Member

    Mar 2, 2015
    1,301
    880
    If you're committed to an all-analog solution, I'd second the nomination of the LM331 V-to-F chip, or you can use the AD650 you have on hand.

    Otherwise, I like the suggestion @jpanhalt made:

    Analog Devices makes a number of Direct Digital Synthesis (DDS) chips, and I think either the AD9833 plus a comparator IC (to generate a logic-level signal from the DDS's sine wave output) or an AD9838 (with built-in comparator) would do the trick.

    But I think there's an even simpler, cheaper solution. Many of the newer PICs contain an NCO (Numerically Controlled Oscillator) peripheral, which is essentially a DDS frequency generator with a pulse or square wave output instead of a sine wave. If you select a PIC with both an NCO and an Input Capture peripheral, you could do the entire job with just one chip: measure the incoming duty cycle with the Input Capture, make whatever mathematical translation is appropriate, and write the result to the NCO's frequency control register.

    My candidate for the job would be the PIC12F1501; in 8-pin DIP, it's $0.77 at Digi-Key.
     
    cmartinez likes this.
  18. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,675
    899
    Here's one version. There is a version published in EDN Design Ideas, but I couldn't find it.
    upload_2016-9-30_5-48-3.png

    KrisBlue (Elecrtronics Point) had some comments about using a 555 as a VCO here: http://www.electronicspoint.com/threads/555-voltage-controlled-oscillator-question.269061/ As I said, it is a "poor man's" VCO.

    About 5 years ago, I did something similar with a low-pass filter plus op-amp buffer to Pin5 of a 555. It was used to change the duty cycle of a signal to the appropriate pulse widths used for a hobby servo, which is probably a more standard use of Pin5.

    @OBW0549 I intentionally left out a DDS recommendation. What I have actually used is one of the very inexpensive AD9850 modules on eBay. Today. I would use an MCU for the whole thing too.

    John
     
    cmartinez likes this.
Loading...