Shop OBEX P1 Docs P2 Docs Learn Events
generate 5v PWM with the propeller? — Parallax Forums

generate 5v PWM with the propeller?

Jason HicknerJason Hickner Posts: 21
edited 2008-02-03 07:46 in Propeller 1
Hello,

I'm working on a project that involves zigbees (3.3v logic) and also requires a PWM signal at 0-5v. I've been debating between using an arduino or a propeller for the controller. Arduinos can generate the 5v PWM, but don't natively interface with the 3.3v zigbee. Props can talk to the zigbee, but I haven't found a way to generate a PWM signal above 3 volts. I was wondering if there's some kind of external PWM IC that would work, or what my other options might be for generating the 5v PWM signal.

Thanks for any suggestions!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Jason
www.pr0jects.com
«1

Comments

  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 10:07
    > or what my other options might be for generating the 5v PWM signal.


    And amplifier?
    If all that is too complicated, an OpAmp?


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-16 10:12
    I thought about an amplifier, but I couldn't see how I'd be able to maintain the capability to generate the entire 0v to 5v range.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 10:47
    > I thought about an amplifier, but I couldn't see how I'd be able to maintain the capability to generate the entire 0v to 5v range.

    There are many "rail-to-rail" opamps available. Obviously, you need 5V. Is that the problem?
    OTOH, as it is PWM, do you really need the 5V?


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-16 10:58
    Nick,

    The 0-5v signal is being sent to the control pin on an LED dimmer. It doesn't necessarily need to be a PWM signal, just a voltage between 0 and 5v. I was just assuming PWM was the way to go. The whole 0-5v range is needed to get the whole range of dimming. I've never worked with an op-amp before. Would it smoothly convert the whole range?

    Thanks for your help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • hippyhippy Posts: 1,981
    edited 2007-12-16 11:01
    Why not simply run the Propeller generated PWM through a suitable logic gate buffer powered from 5V ?

    I'm sure that would give you as much 0V/5V swing as you'd get from an Arduino or any other 5V microcontroller.
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 11:12
    > The 0-5v signal is being sent to the control pin on an LED dimmer. It doesn't necessarily need to be a PWM signal,
    > just a voltage between 0 and 5v. I was just assuming PWM was the way to go.

    So in fact you need a simple DAC with an output range of 0..5V. Not a PWM signal.
    The easiest way to get that is to use a comparator (LM2903, a dual comparator) and filter the output-signal with an R/C.
    You feed the comparator with a PWM and the output is "smoothed" to get a variable output.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-16 11:25
    Hippy, would that work? I wonder if I could use something as simple as a 3904. I'm not sure how fast they switch.

    Nick, thanks for the info! I'll try that out as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • RobofreakRobofreak Posts: 93
    edited 2007-12-16 12:12
    Just a quick comment here on your 3904 idea. Well, if it's not fast enough for you, you can try the 2222 NPN high speed switching transistor out. You can get one at radio shack. They also have a 15-pack of them.

    Just a suggestion...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Austin Bowen,

    Robo-freak.com

    "One must watch out for mechanics. They start out with a sewing machine, and end up with the atomic bomb" - A quote from someone that I saw on Addall.com

    Post Edited (Robofreak) : 12/16/2007 12:17:25 PM GMT
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-12-16 13:38
    Your opamp doesn't need to be fast as all you realy want is the voltage, not the PWM signal. Run an RC network from the prop as you normally would to convert PWM to a voltage but run the 0-3.3V signal into the opamp's non-inverting input and set the gain resistors to 39K in and 20K (10+10) feedback. This gives a gain of 1 (non-inverting) + 0.513 which will convert the 3.3V signal TO +5V. Note however that the opamp has to be powered from a supply higher than +5V if you want to use a common LM358 otherwise you need a rail-to-rail opamp (usually CMOS).

    The other way is simply to have a 74HCxx logic gate powered from +5V and driven from the 3.3V PWM signal to give a 5V PWM signal. Most gates should work fine when driven from 3.3 but there is a rather remote possibility that the 74HCxx maximum input levels may just be outside of 3.3V.

    A transistor circuit is more trouble than it's worth and really requires npn and pnp plus an npn to drive it. A single transistor would have to be used in a grounded emitter configuration with a low value of collector resistance, as long as it was fast enough and the load was very light. The humble opamp is far easier to use.

    *Peter*
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 14:22
    > Run an RC network from the prop as you normally would to convert PWM to a voltage but run the 0-3.3V signal into the opamp's non-inverting

    The problem with this design is, that you don't have that much guarantee about the Prop's output-voltage. But for the required accuracy good enough.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-16 17:30
    If your dimmer will actually take a PWM input, just run your 3.3V PWM signal through any 74HCT-series gate, powered from 5V, and your PWM will be faithfully reproduced at 5V. If what you really need is a 0-5V analog signal, you can filter the 'HCT output with a simple RC filter, assuming the dimmer's input impedance is high enough (e.g. a typical CMOS input). If it isn't, Peter's op amp solution is the best, since it will buffer the output.

    BTW, even if a garden variety comparator were able to switch fast enough to preserve your PWM waveform accurately (which is doubtful), most have open collector outputs, so don't provide the symmetrical switching currents needed for a simple RC filter downstream. The same would apply to any single-transistor output.

    -Phil
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 18:52
    > BTW, even if a garden variety comparator were able to switch fast enough to preserve your PWM waveform accurately
    > (which is doubtful), ...

    300ns should be enough?

    > ... most have open collector outputs, so don't provide the symmetrical switching currents needed for a simple RC filter downstream.

    A pull-up and the R of the following filter by a magnitude bigger.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Dennis FerronDennis Ferron Posts: 480
    edited 2007-12-16 19:05
    Hey guy, just power the op-amp from something higher than 5 volts - say, 7.5, 9 or even 12, and then use a resistor divider between the output, the negative input, and ground to adjust the gain on the op-amp so that the Propeller's normal logic + voltage comes out to exactly 5 volts on the output. The extra supply voltage will give the op-amp head room to swing to 5 volts; no need to worry about rail-to-rail. You might also want a pull up on the output of the op-amp if it is open collector; this pull-up can be connected to more than 5 volts because the op-amp will sense and regulate the output if you use the negative input to sense the output voltage through a voltage divider.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-16 19:42
    Nick Mueller said...
    300ns should be enough?
    Not really. Even with a relaxed PWM frequency of 30KHz, and assuming 8-bit resolution, one bit time is 130ns. Moreover, if you use one of the Propeller's DUTY outputs for the "PWM", the output frequency could be as high as 40MHz at times (80Mhz system clock with a 50% output duty cycle) — a frequency that would challenge even 74HCT-series logic.

    -Phil
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-16 20:20
    Phil Pilgrim (PhiPi) said...
    If your dimmer will actually take a PWM input, just run your 3.3V PWM signal through any 74HCT-series gate, powered from 5V, and your PWM will be faithfully reproduced at 5V.

    Yes, PWM works with the dimmer. I've tested it with an arduino's 0-5v PWM and it worked great. So a logic gate seems like the simplest approach with least components. I tried a 3904 but it didn't seem to be switching fast enough.

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 20:31
    > a frequency that would challenge even 74HCT-series logic.

    Its biggest challenge will be to output 5V.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-12-16 22:13
    Nick, you keep using a big hammer to bash the threads, are you having a bad day mate?

    1. 74HCT is CMOS and as such will give you rail to rail output swings.

    2. "A pull-up and the R of the following filter by a magnitude bigger" means it needs to be buffered with an opamp anyway as the output will be high impedance.

    3. "The problem with this design is, that you don't have that much guarantee about the Prop's output-voltage. But for the required accuracy good enough" assumes that you can't guarantee your regulator voltage?

    We don't try to be right more than we try to be helpful. In these forums we are better off coming up with answers rather than a "should be". That way we all benefit from workable solutions. The forum is a jam session for propheads, let's make some music.

    *Peter*
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-16 23:46
    > Nick, you keep using a big hammer to bash the threads, are you having a bad day mate?

    You can always argument. Here, you failed.


    > 1. 74HCT is CMOS and as such will give you rail to rail output swings.

    I doubt that you have read the data-sheet of any HCT. 0.1V drop at 20µA, 1.1V at 4mA. 'Nuff? Impedance?


    > 2. "A pull-up and the R of the following filter by a magnitude bigger" means it needs to be buffered with an opamp anyway as
    > the output will be high impedance.

    According to my crystal ball, 100k is enough.


    > 3. "The problem with this design is, that you don't have that much guarantee about the Prop's output-voltage. But for the required accuracy good enough" assumes that you can't guarantee your regulator voltage?

    I can guarantee it as much as you can guarantee it for a HCT, for an OpAmp or whatever. But still I can read the prop's data-sheet.


    Have a nive day!

    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-12-17 01:24
    Nick, we are all in this forum together, you, me and everyone reading this, is there a point with your arguments? As for datasheets I do indeed read them and comprehend them (it's my job). Tie in the the answer from 1 where you are acutely aware of the drive impedance and loading to the answer from 2 where you have ignored this and be honest about the conclusion you draw. Let's not draw swords over millivolts please.

    The point I am trying to make is if we do have an argument, then good!. But let us be forthwith with the rationale behind the argument so that others can benefit from your insight in this instance rather than unsupported negative assertions.

    Thank you, I am having a nice day.

    *Peter*
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-17 09:40
    > ... rather than unsupported negative assertions.

    Oh yes!


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • OzStampOzStamp Posts: 377
    edited 2007-12-17 10:41
    Hi

    other possible scenario's can be explored ... all digital... set and forget type solutions...

    Digital pot....
    I2C chip PCF8591 ( has analog in and analog out ) works on the pins 28 and 29..

    cheers Ron Melbourne Australia
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-12-17 14:07
    I was wondering about this alternative scenario, an i2c 12bit DAC: http://ww1.microchip.com/downloads/en/DeviceDoc/21897B.pdf

    Seems like there's lots of ways to skin this cat.
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-17 17:13
    The question is: What do you need at the end of it?
    You can of course add some ICs (DACs, OPAMPs, voltage converters,..) - maybe even include your laptop in the chain smile.gif

    To my opinion (and also to my experience now) the Propeller is well suited to not need all that, except for very special high precision tasks...

    (A) When you need (low) current, a n-bit current DAC consisting of n resistors is fine, when you need voltage a R-2R ladder is commonly used (it is not perfect, 8-bit ICs rather use 256 integrated single valued resistors...).

    Charging a cap from a PWM source through a resistor is the third way how to implement an DAC:
    Be x the "duty cycle" for a given pulse period of t.; V the voltage at the cap.
    Charging: Q = CV = Ic*x*t; Ic = (Vdd-V)/R
    Discharging: Q = CV = Id*(1-x)*t; Id =V/R
    Equiibrium: (Vdd-V)/R*x*t = V/R*(1-x)*t
    Vdd*x -V*x = V - V*x
    V = Vdd*x

    This is the surprisingly simple equation, without any impact from R or C in the perfect situation, or the "mean voltage" in a less perfect situation.... You can compute the "ripple" caused by the finite period of the used frequency yourself.

    This analysis is equivalent to more classical "low pass filter" considerations.

    You can yield very good results when using the "duty cycle mode" of the counters, sending "spikes" of 12.5 ns, which is not strictly PWM...

    But you can never establish a voltage above pin voltage...

    (B) Using PWM on the other hand has nothing to do with voltage altogether. In fact things as PWM (or even FM) have been invented to become independent of any voltage (or "amplitide"). The only information in a PWM signal should be its "duty cycle", or - when a fixed period is required! - the absolute pulse width.

    When someone requests a specific amplitude for a PWM signal, it should be investigated what he needs it for:
    - just to overcome a trigger threshold?
    - to load a cap upto a specific voltage (without internal signal conditioning)?

    (C) It is a very old controversy how to best control an LED
    - by short high current pulses
    - by steady low current

    Looking into data sheets of LEDs you can find highly interesting diagrams about short pulse current....
    Main advantage of PWM control is the finite voltage needed (of 2 to 3.5 V) and the most simple interface
    Steady current needs a current source, a simple transistor is close to perfect for it. Its base current can be generatet by a simple current DAC or a smoothed PWM signal
  • hippyhippy Posts: 1,981
    edited 2007-12-17 19:08
    No idea if this will work ( software engineer alert ! ) and the ripple could be terrible, but what about a simple charge pump ...

    3V3 >---|>|---.----|>|---.------> Vout
                __|__      __|__
                --.--      --.--
            ___   |          |
    PWM >--|___|--'         -^- 0V
    
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-17 19:17
    Relatively early in the Propeller history, Beau (?) posted a design for a boost regulator driven by a Propeller pin using a cog counter. I don't have a link to it, but you could certainly generate a voltage higher than the 3.3V supply with just a few passive components and a transistor or two. I don't remember whether it used an inductor or a charge pump.
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-17 20:45
    Thanks for all the ideas! I have some 74HCTs on order that I'll be trying next.

    I'm trying to come up with a simple solution that doesn't require too many extra components. Lately I've even been thinking about just soldering a Boarduino (www.ladyada.net/make/boarduino/) directly to the propeller proto board. With a serial connection between the prop and the boarduino, I can use the boarduino's PWM and ADC from the prop without too much fuss, and the boarduino can run off of the same 7.5v power supply that the proto board uses. The boarduino costs $17, which isn't too much more than the handful of 74HCTs and ADC chips I'd need to handle it all from the prop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-17 20:51
    Hippy,

    Using standard (non-Schottky) diodes, your circuit should be able to generate up to 5.4 volts with no load. (C1 charged to 3.3 - 0.6 = 2.7V, then 2.7 + 3.3 - 0.6 = 5.4V on C2.) If you went to ultra-fast-recovery diodes, you might even be able to do it with the DUTY mode output, which would help with the ripple and/or allow smaller caps. In theory, you could close the loop by means of a voltage feedback to the Prop and by using software to maintain the desired voltage. This would eliminate the need for any active components, but the total component count does begin to mount...

    -Phil
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-17 21:39
    @hippy: This will not work for multiple reasons.... The idea behind a charge pump is to never discharge a cap to the lower echolon but use its charge to fill the next one. The idea behind PWM based DACs is to have total control (charging AND discharging) from the source...

    The charge pump will at best generate unprecise triangles, depending on the drawn current at it's output...

    But adventurous persons can try this scheme... It has proven useful for some LCD display's segment control..
    414 x 200 - 11K
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-21 21:15
    FYI - just got my 74HCTs today, and they work great! They're able to generate the PWM signal all the way up to 5v, seemingly without issue.

    I used a 2-input OR gate with one of the inputs tied to ground, and the other coming from a prop pin generating a PWM signal.

    I need three of these gates for my project, so I got a 14-pin dip chip from digikey that has 4 gates on chip, so basically my problem is solved with just one component! Very cool.

    Thanks Phil!!

    - Jason

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-21 21:48
    Yes, very cool! Are you aware that these 74XX chips are available for some forty years now, literally unchanged - more or less smile.gif

    BTW: You should connect both unused input gates to ground as well.

    Post Edited (deSilva) : 2/2/2008 11:46:45 PM GMT
Sign In or Register to comment.