Shop OBEX P1 Docs P2 Docs Learn Events
Please Define PWM — Parallax Forums

Please Define PWM

Kirk FraserKirk Fraser Posts: 364
edited 2011-06-22 17:44 in BASIC Stamp
My project on a BS2 appeared to work briefly before I tried to move it from a solderless prototype board to a circuit board and shorted out the BS2. I noticed the PWM command was unusual in that it generated a signal that itself wasn't variable voltage exactly, it seemed to move around a lot on my o-scope, but it would convert to a voltage when run through a resistor and capacitor. What is the definition of that signal?

I need to know what it is so I can program it on a Propeller. There are several PWM programs available here in documentation, examples, and the object exchange but of the ones I've tried, none appear to do what the BS2 does with that command. Most just vary the on time of the pin. There is also a demo of varying the pin output from 0 to 1 causing an LED to go through a brightening and dimming effect which indicates a variable voltage.

My o-scope isn't precise enough to explain what the BS2 signal is doing. Someone with better equipment, please explain. Thanks.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-06-21 08:03
    PWM is Pulse Width Modulation. You can search the internet for more info. Wikipedia would have info.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-21 08:17
    What the BASIC Stamp manual calls PWM is not really pulse-wdith modulation in the traditional sense (i.e. fixed frequency, variable duty cycle), but rather DUTY modulation. Basically, DUTY modulation rapidly toggles a logic output between high and low such that the ratio of highs to lows is constant within any significant time interval. It is this ratio or, more precisely, the ratio of highs to (highs + lows) that determines the voltage resulting from filtering the output with an RC network.

    -Phil
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-21 09:25
    Gee, I think I gave a pretty good answer in #11 HERE.

    Oh well.

    PE - It's probably because I don't go to a church where you leave your brain at the door and check out a box of crayons.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-21 10:00
    Here's a composite of three scope traces that shows the BS2 "PWM" output for various values of Duty:

    attachment.php?attachmentid=82376&d=1308675608

    -Phil
    639 x 590 - 24K
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-21 11:00
    Thanks everyone! This is all more knowledge than I had to work with before. I even got a bit from the first wikipedia picture. Thanks Phil for the clear explanation and scope traces, (which are far better than my low end Tek scope produces).

    Sorry PJ I had given up looking at my older thread after it degenerated into talking about using stranded & soldered wires in a solderless breadboard.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-21 11:29
    Degenerated? Well, you asked.
    I think #22 is too big, #24 (solid) is the best, and stranded is unacceptable. If it was literally a matter of do or die, there's no tomorrow, then stuff a stranded wire in there, I guess. Otherwise, do it right and get solid #24.

    DAC, digital-to-analog converter. Neat devices, beats this PWM/integrator stuff by a country mile, if it really matters.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-21 13:26
    On wire: I'll stick with my CAT5 which I have hundreds of feet of that doesn't work for computer networks because it's easier to strip than the magnet wire I have. I'll take your advice on #24 if I see a garage sale deal like on the CAT5. The only problem with the CAT5 for breadboards is if a hole has been stretched by big pins on a regulator or something it doesn't conduct, but on regular holes it does good enough. Wire topic closed.

    On PWM v. DAC: PJ, I've worked on DAC for 5 years to no profit, originally suggested and nurtured on this forum. I think Phil posted PWM is the only thing that will work on coils. So if you have any details which revise that conclusion, let me know. Perhaps you're implying simulating a PWM via DAC pulses?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-21 13:57
    One way or the other, whether the output we're talking about is from microcontroller/pwm/integrator or a DAC, you're going to need an interface between whichever you choose and the "coils" they're supposed to activate/control.

    DAC, microcontroller, and op-amp outputs are, generally speaking, low current affairs.

    I know there are power op-amps (audio), but that's a different subject, or maybe not.
    Electrically, a speaker, a transducer, is a coil (an impedance) - an electromagnet connected to a cone.

    5 years is a long time. I can't think that the fault was the DAC. That power interface, I believe, is the rub, the stumbling block. It'd be nice to have a conversation, but I'm sure that the Optoisolation Cabal will be along shortly.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-21 15:01
    Kirk,

    I just reread this thread and noticed your comment about coils. If you're driving an inductive load, I do not recommend either the BS2's "PWM" or the Propeller's DUTY mode output. A true PWM output will give you much more efficiency, since your output transistors can be driven to 100% saturation. There are several PWM objects in the Propeller OBEX to choose from.

    -Phil
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-21 15:50
    Phil, Thanks for the guidance on what to look for. Some of the software I've tried doesn't do it.

    PJ, Yes in my previous thread on grounding it was learned getting the two grounds separated in
    forums.parallax.com/showthread.php?131815-Grounding-3.3v-amp-24v&p=1002325&viewfull=1#post1002325 distance is one option that I hadn't considered,
    forums.parallax.com/showthread.php?131815-Grounding-3.3v-amp-24v&p=1002681&viewfull=1#post1002681 opto-isolation is another and
    forums.parallax.com/showthread.php?131815-Grounding-3.3v-amp-24v&p=1002969&viewfull=1#post1002969 digital-isolation is also available.

    For now I'm struggling to get back to where I was with the BS2, having a chip that measures RCTime and produces PWM. I hope that I can accomplish that, then proceed to the rest of the circuit. For now I'm testing with the FET on 3.3V so I don't blow anything until it's all ready for the 24V test, hoping option 1 works.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-21 17:05
    Maybe I'll get another fatuous, self-serving stream of menopausal nasty-grams from Ayatollah potatocakes. :thumb:

    A guy sees this PWM-cum-integrator circuit and says to himself, "Hot Dog, that's how I get a variable voltage."
    So, I figure, 'fine', he must know what he wants (some kind of variable voltage.) But I know that that thing isn't going to change quickly.

    There are some fast DACs out there these days, audio DACs for MP3s and CDs, and there are even video DACs, that's fast.

    I remember this "4096" number and someone's being stuck on "20 kHz" and I don't know whence those figures derive.

    A guy can throw components at a thing like this all day long, 24/7/365, for 5 years, 50 years, he can build a house out of optoisolators for that matter, and it won't make a difference.

    I'm not out to give anyone a hard time, but is it a PWM signal that's needed or a variable voltage? I'm not selling anything.

    The root of this debacle is a lack of fundamentals. Don't change the problem, address it - fix the problem.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-21 18:28
    I confess my training in school and out on electronics is insufficient for many things. I thought I was doing well when completing Popular Electronics projects and they worked. Eventually I discovered I was only gaining skill in following schematics, not in designing them. So I have to rely on kindly advice instead of knowing already what will give me what I need. My need is computer control of a proportional hydraulic valve, which means the valve shuttle must locate at a position I set which is a fraction of the total travel. How do I get that? DAC or PWM? I can only look at my failures with DAC and temporary success with PWM to give me an answer that is more real to me than the best advice, which Phil has frequently given.

    I could be blinded by my experiences of failure on DAC that may have been a result of not knowing the proper ground wiring system. But PWM uses far fewer parts than the old DAC/OpAmp I was using, which is good. On the other hand, the Prop is able to generate a steady voltage at a given point making the extra parts unnecessary. Now it's a matter of what algorithm, PWM or DAC, will work best. Background reading on proportional hydraulic valves comes in which says it's best to use a 100Hz dither frequency to reduce frictional stiction and magnetic residue caused sticking of the valve shuttle. That appears to be built in with PWM which looks like an FM signal while DAC would look like an AM signal with a 100Hz harmonic overlay. Which is best for driving the FET to get the coils to hold the valve shuttle at the correct position for the desired degree of valve openness? I don't know but I'm guessing for now that the FET produces better results with FM than AM. Any further knowledge?

    4096 is 2^12 or the number of positions RCTime should indicate while turning a 10K pot under 12 bit A/D measurement (subtract a few for start-end of wiper travel). Based on Obex code it looks like a higher value pot could be measured with greater than 12 bit precision, but the pot design I have learned to use only comes in 10K.

    20KHz was not my figure but supplied by someone calculating how much speed the control loop would operate at. By asking a college professor with experience on a pogo-stick single leg robot, I learned I need at least 200Hz in the control loop to balance in the presence of gravity. 20KHz is overkill by 100 times which gives room for running all the robot on a single cog except for the limitation of pins. So I have time to do other things if I decide to in the future, like planning the next move.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-21 19:03
    My need is computer control of a proportional hydraulic valve, which means the valve shuttle must locate at a position I set which is a fraction of the total travel.

    Is that determined by a voltage? For instance, 0-to-5V = 0-to-100% of travel? Or what?

    PE -- Here's a link [ http://forums.parallax.com/showthread.php?83148-Bargraph-Indicator-Tubes-(now-with-youtube-demo) ] to a project that featured a DAC, not the PWM/integrator gimmick. It's running a bargraph tube, not high current. I do stuff to illustrate principles, present building blocks.
    Note the absence of optoisolators.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-21 21:51
    PJ Allen wrote: »
    Is that determined by a voltage? For instance, 0-to-5V = 0-to-100% of travel?

    In your terms, I don't know that principle. It may be voltage or current I suppose. Definitely not sure which comes out of the FET as it looks like what goes in only with more voltage. Judging by Phil's scope shot, it looks like a fixed voltage but as the impulse time spreads thin, the net effect of the applied voltage goes down with it, making less current available to the coil. Perhaps the coil's inductance converts it to voltage like an RC circuit does. I do know that more voltage can make it work better if it's below 24V but perhaps that enables the coils to draw more current. But other experiments with coils tell me voltage does make a difference in the amount of magnetic force that comes out. So I conclude that either voltage or current coming out of the FET should have the desired effect if it's the correct value.

    The dodad on YouTube is nice. I don't see how that relates to a coil. Does it have an internal coil?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-06-21 22:19
    Kirk,

    Typically, if you're driving an inductive load, you can rely on the inductance to smooth out the current. This is a huge advantage for the driving transistor, since it doesn't need to spend any time in its linear region and dissipate a lot of heat and wasted power. But you have to drive that transistor with a frequency low enough that it doesn't spend a lot of its time between states (i.e. in its linear region). That's why DUTY mode outputs are a poor substitute for true PWM: their frequency is just too high. Also, you want your PWM frequency to be above the range of human hearing, if possible; otherwise your coil will make an audible squeal. For these reasons, 20KHz is often the frequency of choice for PWM.

    -Phil
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-21 23:16
    Thanks much Phil, that makes the decision. It's got to be PWM to reduce the linear production of heat.

    So how did you get your excellent understanding of electronics? BTW, what O-Scope do you use / recommend?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-22 05:49
    ???
    I asked a simple question about the operation of your proportional valve.
    From your response to my simple question I can only conclude that you don't know what's required.
    Hoping for some outcome by implementing random, range-of-the-moment "solutions" and indulging concretes out of context will only get you another 5 years with no harvest; there are no figs on that tree, cut it down.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-22 06:12
    So you PJ are directly contradicting Phil's advice on heat production? I being the student should back off and let you professors take the floor of my thread to argue directly.

    I think it is "possible" the DAC could operate as cool as PWM after the recommended dither frequency was applied but it doesn't seem likely when holding the coil at a certain charge to achieve a certain position. Have you PJ tried holding your dodad in a single position, say at $88 indefinitely? How does the heat in your circuit build up compared to varying it between $00 and $FF for the same number of hours?

    One huge advantage of PWM is Phil says there is correct software already written in OBEX while the DAC software would have to be written from scratch to include the dither frequency.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-06-22 08:35
    I can manage that "dodad", sir, and it's a bargraph tube, seven ways to Sunday.
    You betcha!

    I can get a "coil" ripping like nobody else's business, too.
    Aye.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2011-06-22 17:44
    Well I downloaded 3 more OBEX units on PWM and they make little to no sense to me. Especially a demo that causes 2 LED's to dance back and forth at different frequencies. So I'm going to review the BS2 command, Phil's scope traces, and my understanding posted above then write one myself, keeping the earlier advice in mind plus my requirement of one cog per actuator program.
Sign In or Register to comment.