PWM, not working properly, need advice!

Discussion in 'The Projects Forum' started by bytraper, Apr 4, 2012.

  1. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    Hi People.

    I've got a problem with a PWM circuit that just refuses to work properly. First, let me add the circuit (see below)

    It works perfectly in a simulator, but in reality it doesn't work so well, but I'm pulling my hair out as to why! I'm sure it’s something in the PWM circuit itself, but I don't understand enough about it to work out exactly what. The resistors I am using are all 1%

    The problem with it is that at the very beginning when it changes the duty cycle between about 1-3%, the PWM output goes haywire (see the scope shot). At 0% its ok, at 4% to 96% it works fine and is stable, at 97-100% it goes crazy again.

    I've tried to catch the scope images do you can see.

    Changing the frequency doesn't make any difference, I've tried different filtering with caps and diodes which helped smooth the signal, but didn't fix the problem. The trimpot marked TSS in the schematic is for adjusting the end position of the input pots (because some of the 10k pots I have start and finish in different positions depending on the brand).

    The sawtooth output into the negative of the second comparator (pin 6) of the lm2903 is dead steady. The scope readings were taken from Pin 7 (the second comparator output).

    The PWM square wave output from Pin 1 is stable; however I have noticed that at the problem points in the potentiometer travel (1-3% and 97-100%) it grows the smallest margin wider (time) until you cross past these problem spots.

    The diode D3 on the output helped clean the signal, and so did a capacitor, but again not fixing the problem.

    I've tried external 5v power sources, but it still bugs out. I've tried taking all other circuits out of the design and leaving just the PWM and the 5v reg, but it still bugs out. I can cheat by adjusting the maximum start and end positions, but this is more of a hack and not really fixing the problem.

    I'm just stumped and would appreciate any help I can get!



    The circuit:
    [​IMG]

    0% duty cycle, stable (no picture)


    1-3% Duty Cycle, Crazed, you can’t see it but its shifting horizontally across the screen
    [​IMG]

    ~50% duty cycle, stable
    [​IMG]

    97% Crazed!
    [​IMG]

    99% crazed
    [​IMG]

    The PWM is based on Sarges design.
    [​IMG]

    I'm stuck!
     
    Last edited: Apr 4, 2012
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Looks like you're having noise problems. Metal film resistors will help that.
    Put a 10nF/0.01uF cap from U3 pin5 to GND
    Put a 100pF cap from U3 pin 3 to GND
    Do you have an 0.1uF/100nF cap across u3's power pins?
    I'm going to be mighty busy for the next couple of weeks, attending seminars and travelling. Don't expect any quick replies.
     
  3. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    Since you have an oscope, what does the triangle wave look like?
     
  4. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    Hey Sarge,
    I tried the capacitors you mentioned,
    the 10nf between pin 5 and ground, this made no difference to the output.
    the 100pf between pin 3 to ground, completely shut everything down, no pwm output at all.
    Also, across the VCC/GND I have both a 0.1uf and a 2,2uf pair.

    Bill, here's the sawtooth at Pin 6
    [​IMG]
     
  5. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    The next question is are the voltages at the comparator exceeding the peaks of the triangle wave?

    Something that is important to note, you are not going to get a nice repetitious waveform unless you are dealing with a pure DC, and any AC at all is going to cause jitter.

    Something that has occurred to me, how pure is the 5V? If you are using a SMPS from a phone charger or some such it will feed noise into the system.
     
  6. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    The supply is pretty clean, its a regulated DC lab supply. The line does have noise on it possibly from the regulation stage, but the filters off the 7805 fix this to a degree. The voltage coming in from the pot is 0.556v-4.42V.

    I notice also, that when I touch the dial of the pot, I get a lot more noise on the pin7 output, I've insulated the pot, but the crazy pwm still happens, but could this be part of the problem?

    Sarge initially designed it to work with a Hall Effect Throttle, but it does the same thing (crazy pwm) as the pot.
     
    Last edited: Apr 6, 2012
  7. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    Just free wheeling here (thinking out loud).

    I was a metrology tech for Alcatel for just over a year. I had a problem with noise on a power supply. I fought it for a while, then I noticed the noise matched a transistor radio I was hearing across the lab. Turned out it was RF (the local AM radio station) riding on the DC.

    When you touch anything in a circuit you are an antenna. No way around it. This can go for DVM probes, and maybe even oscope probes.

    There are ways to fight it though. Make sure the power supply is as clean as you can get it. Use a capacitor on the pot wiper. That sort of thing. Look for areas you can quieten without affecting what you are working on.
     
  8. shortbus

    AAC Fanatic!

    Sep 30, 2009
    4,004
    1,524
    According to what I've read in various places including data sheets for PWM chips, its hard to get a PWM that works over the complete range. Most of them only work effectively from ~ 10% to 90% of the 0-100% range.
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
  10. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    The OPs circuit should be able to. It was loosely based off one I published in my LEDs, 555s, Flashers, and Light Chasers, though Wookie may have had this out before then. I seem to remember he published it as a way to get it down to one chip instead of two. When he frees up he can answer that question.

    The schematic in question looks like this....


    [​IMG]
    .................................................. ........................Figure 5.3


    If you look close you will find the hysteretic oscillator has the same 1/3 Vcc and 2/3 Vcc set points as mine, though mine was based of the 555 characteristics. I was quite disconcerted when I found this to be the case.

    I notice there is a pot in his design, so it may not be the case as it was in the other design of Wookie's I saw.

    It is easy to calculate, maybe the OP can pin down the value of VR1 in his design. R1 in my design is frequency of the PWM, which should be stable.

    The 200KΩ trim pot should be 100KΩ, this is pretty critical for the set points I mentioned. It sets the max and min voltages of the triangle wave, which is core to where 0% and 100% to DC voltage in is on the design.
     
    Last edited: Apr 7, 2012
    shortbus likes this.
  11. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    Bill,
    I Put the 200k trimpot there to adjust the triangle wave, because I also use this for hall effect throttles and pots that have different endpoints. Trimpot VR1 lets me adjust the endpoint so the pwm can still reach 100% duty cycle.

    Like sarge said, its a noise issue, I don't think its the PWM, I think there may be noise coming from the main 5V or 12V rail, but I cant seem to get rid of it.

    I can see it, but nothing I do seems to isolate it
     
  12. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    The problem is, that will move your endpoints, but not in a controlled manner. What are they now? (assuming you have measured them).

    [​IMG]

    Side comment, please use the local albums on AAC or attach your documents locally, it creates problems for other people otherwise.

    It is the ratio of R1||R2 and R3 that adjusts the endpoints, if you look at Wookie's schematic he has labeled it as such.

    Let me know what the current value of R2 and I'll calculate your end points. I suspect you will see your problem there.
     
    Last edited: Apr 9, 2012
  13. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    Bill let me test it with a 100k resistor, that'll show if its the PWM module right?
     
  14. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    Probably. Worth doing. What are the setpoint you are aiming for anyhow?
     
  15. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    What do you mean by setpoint ? the voltage range on the input device?

    I tried the 100k, in theory, this should have fixed the problem as the circuit is now identical to the one sarge posted, but the issues are still the same. I don't think the problem is with the PWM... I'm now sure its a noise issue, but I'm damned if I can find the source of the noise, but it's making both the 12v and 5v regulators quite hot.
     
  16. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    Ok... this sucks, now we are back to the PWM.. I had a friend look it over and said the problem isn't the power, its the pwm. He isolated the PWM circuit, took a signal generator and voila, the rest of the circuit worked perfectly.
     
  17. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    Have you taken the time to bread board the PWM circuit separately? I've never used that make of comparators. I've only used the LM339 (and the LM393).

    For U1a I used a 555 as I showed, but you want to make adjustable set points.

    What are you wanting these trigger points to be anyhow? I asked this earlier. I know you are using a hall effect sensor to feed this somehow.

    I'll look up the datasheet of the LM2903, since I am not directly familiar with them.
     
  18. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    OK, this is a direct equivalent to a LM393.

    http://www.fairchildsemi.com/ds/LM/LM2903.pdf

    I'm looking over your schematic, what is the value of C5. I want to calculate the range of your variable frequency generator.

    [​IMG]

    I'm thinking seriously of breadboarding it myself.
     
  19. bytraper

    Thread Starter Active Member

    Sep 28, 2010
    126
    4
    It's pretty frustrating, I've been pulling my hair out.
    C5 is a 1nf. Its only at the top and bottom 3% of the PWM, the rest of the time its stable. And what you said about the voltage input exceeding the triangle wave makes perfect sense, but no matter what I do, I can't change it or get rid of the effect.

    I don't understand what you mean by trigger points? Can you tell me what you mean ? Are you referring to the voltage input from the hall effect? The hall effect takes 5V, it outputs a range from 0.9V to 4.2V

    If you want me to send you the complete boarded unit I'll be happy to.
     
  20. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
    No unit needed. I have a pretty complete workshop, though it comes out on the kitchen table.

    I'm wondering is some kind of loading is going on the rest of the circuit?

    You have to understand, this circuit is based off the hysteretic oscillator, the set points of the Schmitt Trigger also set where the peaks of the triangle wave are, which in turn sets the max and minimum voltages for the PWM (the 1% and 99% points).

    Thing is, if you have a 2 channel scope (which I think you do) overlay the triangle wave with the digital pulses. They should be very consistent.
     
Loading...