Author Topic: Analog PWM generator  (Read 8568 times)

0 Members and 1 Guest are viewing this topic.

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Analog PWM generator
« on: May 25, 2011, 12:51:13 PM »
I have designed an analog PWM generator and would like to have it checked by someone to confirm that I haven't missed anything.

Original idea was to use DAC port of microcontroller to extend number of PWM ports with the circuit I designed.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline Billy

  • Robot Overlord
  • ****
  • Posts: 132
  • Helpful? 2
Re: Analog PWM generator
« Reply #1 on: May 25, 2011, 09:52:00 PM »
I have designed an analog PWM generator and would like to have it checked by someone to confirm that I haven't missed anything.

I like it! I question the very high value of the resistors though. I'd be concerned that the circuit would be sensitive to noise...but if you're only using it to drive motors, then noise shouldn't affect much.

I'd use a CPLD myself though. You could drive a huge number of PWM channels with a small CPLD.
One master counter and a simple homemade SPI interface and you're in business with many outputs.

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Analog PWM generator
« Reply #2 on: May 26, 2011, 07:15:09 AM »
Well, high resistor values ore there to reduce current leak. Some of the resistor values will have to change when prototyping this circuit.

Could You be more specific about noise in the system. Where would it come from, how would it affect it and etc?

N.I.R.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Analog PWM generator
« Reply #3 on: May 26, 2011, 07:44:21 AM »
Quote
Could You be more specific about noise in the system. Where would it come from, how would it affect it and etc?

Lots of places, the power supply rails can pick up noise from the servos (circuit and motors). Noise can come from any external source such as the AC mains and any other electronic device.

Other source of noise is each component in the circuit. Real world components are NOT IDEAL and have noise. Even the passive resistor has a thermal noise that can significant when the value and temperature is high enough.
An example may be in the voltage divider at the bottom of your schematic. This divider is setting a reference voltage to the op-amp. But the resistor contribute noise and there is noise in the op-amp (look up noise spec in the data sheet). These will produce a noise Vref and could change with temperature making your circuit act strange at times.

You don't show any de-coupling caps. Be sure you puts caps on the power to ground pins of all ICs and may be needed in other places.
« Last Edit: May 26, 2011, 09:21:54 AM by waltr »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Analog PWM generator
« Reply #4 on: May 26, 2011, 09:02:31 PM »
Hi,

I have designed an analog PWM generator and would like to have it checked by someone to confirm that I haven't missed anything.
Well, your schematic reveals that you have reached the state of being dangerous ;D
As I read it, you understand the blocks that you have welded together (at least to some degree), but lack the oversight.
You have used 3 op-amps and two 555's to make a circuit that would perform very similar to a single 555 with a little extra (when values are changed and errors removed) and I guess that stems from jumping into it feet first and just start laying brick on brick. to find out how the finished result will look once it's done.
Just like programming by just typing until the code works and then document it.

The right way of getting things done, whether it's electronics, software, mech or whatever is like this:
- Get idea
- Roughly sketch out idea (i.e. take notes while the idea is fresh - don't rely on your memory)
- Flesh out the sketches (i.e. make block diagrams with the sub-functions of the circuit [or software or...])
- Refine each block independently
- Build each block independently
- Test each block independently
- When all blocks are done,start merging blocks, while assuring everything works before adding more blocks - take notes along the way.
- When all blocks are merged and working, you're done and you only had to juggle a very few balls at a time.
And you have a ton of paper and notes that will help you writing up a pro documentation if needed  :)


Original idea was to use DAC port of microcontroller to extend number of PWM ports with the circuit I designed.
I could give you a solution made with a single op-amp, but you'd learn nothing from that (it's hard to make modular as well), so instead, I'll give you a starting point to help you do a good job AND understand each bit of it (you've demonstrated a great potential to learn, so this should be plain sailing for you).

You want to make a voltage controlled PWM generator.
The input has to be 0..5V (from the D/A-C) and the output has to be a PWM signal that is 0..100% (my assumption).
For this I'd start out with 3 block as follows:

The oscillator needs to be either triangle or sawtooth (either will do - no difference).
As you base this on charging and discharging a cap, you could use constant current for linearity, but by voltage charging and using just the middle third of the voltage range, you get a fairly linear result with less headache, less outlay and you won't be able to tell the difference in the finished result.
The level translator is needed to change the 0..5V from the D/A-C to cover the rangeof 1/3 to 2/3 of VCC (which I assume to be 5V).
Finally, a comparator (an op-amp could be used depending...) to compare the two signals and make the output high at all times when the oscillator output is lower than the the control voltage from the level translator.

A few things to take into consideration...
As you've already heard, keep resistor values as low as you can get away with, without blowing components or budget. You want the output to have short rise- and fall times and this means you need a good strong hold in the transistor I assume you'll want to drive and fast transients means lots of harmonics - a digital circuit cruising at a lowly 10kHz may well generate harmonics in the MHz or even GHz range.
Use caps on any node* that you want to stay silent or hold a rigid voltage, but don't overdo it - few circuits are happy to see a very capacitive load.
When you draw a schematic, whether for others to read or for your own collection, name each component (like R1, R2, IC1A, etc.) as it makes it possible to point out any place in a circuit.
Don't draw wires through components.
Don't litter the schematic with junction "dots", making it look like you assaulted it with a shotgun ;D
Don't fit any component that isn't needed - the more components in a circuit, the larger the chance that it fails.

(* a node is any part of a circuit that connects 2 or more components)


If you concentrate on one sub-circuit at a time (here's two plus a comparator), it should be doable. Perhaps a minor challenge (best way to learn :)), but absolutely doable and if you run into a hurdle - post what you've done and what you have measured etc.


Well, high resistor values ore there to reduce current leak. Some of the resistor values will have to change when prototyping this circuit.
Calculating a circuit prior to prototyping should land you close to the final values and the proto-stage is just for trimming the final bits & bobs, optimizing the real world example of what you have on paper.
Stay clear of resistors above ~100 kOhm (or use extensive screening techniques). Sure I have resistors  up to 10GOhm (10 Giga-Ohm), but they're reserved for very special circuitry and is never my first pick. Any design involving, or working in proximity to; PWM, motors, solenoids, relays, transmitters, any kind of spark gap and similar noisy environments, I try to keep the resistors quite low).

On the other hand, I don't see how you'd see the components thermoelectric noise as a problem in circuits like that, as that is orders of magnitude below the noise sources that you will have to deal with - if we were discussing something like a sensitive mic-preamp, with a gain of 1k, it would indeed be something to take very serious though.


A couple of things to ponder
How much current can you "afford" to use for this circuit?
Eg. 5kOhm on 5V is 1mA and if it will be running a load that takes a thousand times that or more...

What frequency do you want your PWM to run?

What precision do you need*
What repeatability do you need*
(* need, not like - we'd all like a Lambo in the garage, but most of us make do with something a little less but still able to get us down the road and back ;))

These are all design criteria, so should be spec'd out before you touch a single component.


Where would it come from, how would it affect it and etc?
The noise that you have to consider may (will) come from:
- Any motor (via the supply, magnetic induction etc.)
- Any other reactive loads
- Any shifting transients (the higher the voltage and the faster the shift, the more noise is generated)
- Radio signals, like R/C equipment and all the clutter in the ISM bands, where there's lots of "garbage" from WiFi, wireless doorbells, baby alarms and what not
- Cell phones should have a specific mention, as a pulse burst from a cell can tilt most circuits if not designed to the latest EMC specs.
- What we used to call "Radio Moscov", i.e. any broadcast that resonates with any part of your circuit (which is just one of the reasons why proper design and PCB layout is important)
- Klingon tractor beams

As long as you get your signals cleanly into the digital domain, you're some 90% home, as digital signals are way more noise immune. Don't celebrate just yet though, unless you know you have low impedance supply lines, low impedance sensor circuits, low inductance PCB layout, screening where needed (especially with cheap plastic end capped motors and/or large open slots in same), twisted power leads etc.

What is a low impedance, you may ask - well, it depends on the circuit and its intended function - sometimes there's conflicting demands (like only having 1µA to spare, say in a hearing aid), but then there's Metglas and similar stuff to wrap sensitive circuits in  ;D
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Analog PWM generator
« Reply #5 on: May 27, 2011, 02:35:10 PM »
[...] a single 555 with a little extra [...]
OK, here is a simpler version of PWM generator. Is this the one You were talking about?

This circuit should operate at 20kHz, although I am not sure how precise it is.

In my previously posted circuit (as in this one) I could not figure out how to perform voltage level translation, so decided to build custom 555 timer in order to achieve capacitor charge voltage of 4.95V and discharge voltage of 0.05V. Also, I assumed use of non-rail-to-rail Op-Amps, hence all extras to make PWM peak at 5V.

Question number 1: Should I consider voltage drop across transistor?

Question number 2: How voltage level translation is done?
« Last Edit: May 27, 2011, 03:07:37 PM by newInRobotics »
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Analog PWM generator
« Reply #6 on: May 30, 2011, 06:54:30 PM »
Hi,

OK, here is a simpler version of PWM generator. Is this the one You were talking about?
No, what I meant was, that the result of all your components were colse to that of a single 555 with a little extra make the sawtooth and so.

Seems like the block diagram I included wasn't included at all (although it was on the preview), but here it is (I hope ;D)




This circuit should operate at 20kHz, although I am not sure how precise it is.
OK, no need for exotic component values then.


In my previously posted circuit (as in this one) I could not figure out how to perform voltage level translation, so decided to build custom 555 timer in order to achieve capacitor charge voltage of 4.95V and discharge voltage of 0.05V. Also, I assumed use of non-rail-to-rail Op-Amps, hence all extras to make PWM peak at 5V.
Ask yourself...
"Why do I want it to peak at 5V?"
And when you've heard the reason, play the Devils Advocate, asking "Is there any need for it to be like that, or does it matter at all whether it's 0-5V, 0-4V or 1-4V for that matter".

I don't know what you wanna drive with the output, so you're the best one to ask ;)  but in PWM, the duty cycle is far more important than the levels (and if push comes to shove, you can always feed the signal through a digital buffer or an analog comparator).


Question number 1: Should I consider voltage drop across transistor?
Under normal circumstances, you should consider every little detail, if for nothing else than to dismiss it as important.
You're gonna need a transistor to buffer and amplify the PWM signal, so you should aim for making the PWM able to do just that.

I'd make the oscillator from an op-amp, the level converter from another op-amp and use a third op-amp for a comparator, that way you can use a single quad op-amp and still have sub-modules to check independently and an op-amp spare.
I don't know if you have any particular reason for the 20kHz (very small motor perhaps?), but I usually aim for around 3kHz for motor control - If you do that as well, you can get by with an ancient LM324 quad op-amp in a 14 pin PDIP.


Question number 2: How voltage level translation is done?
It's not very different from how you'd do it with numbers on a "four function" pocket calculator (i.e. you can add, subtract, multiply and divide).

To get from your present reference level (0V) and magnitude (5V) to eg. a reference level of 1.67V and a magnitude of 1.67V, you'd first calculate the magnitude difference:
  1.67 / 5.00 = 1/3 (0.333)
So, you need to multiply with 0.333 - which is very unpractical, so it's better to divide with the inverse (3/1).
That takes care of the magnitude, but it still need the offset of 1.67V, which you simply add.
  UOUT = UIN/3+1.67

Onwards to the op-amp (or analog computer if you want).
- Adding takes place on the non-inverting pin (assuming only positive voltages is available)
- Subtraction takes place on the inverting pin (same assumption)
- Multiplying is another word for gain in this context
- Division can be even simpler... A resistive divider

Since you want a positive out for positive in, you need a non-inverting amplifier and hence the gain will be more than 1. It is easy to make a gain of 2, just use identical resistors on the "chain" connected to the inverting input.
That was a multiply of 2, and it should be a division of 3 in the end, so the division need to be 3x2=6.
A 1/6 resistive divider from the A/D-C (if it's output impedance is sufficiently low - see datasheet), can be made by 11k input resistance and 2k2 at the bottom.

Now your input signal is reduced to 0V to 0.833V (before the gain block) and you want to add an offset of 1.67/2=0.833 (still before the x2 gain). This can be made with a trimmer, a cap and 2 resistors to make the trimmer cover only a narrow range around the area of interest.

The input signal as well as the offset voltage should be fed to the op-amps non-inverting input through two resistors of say 47k.

As a minimum, make any output look into an input of at least 10 times as high an impedance.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Analog PWM generator
« Reply #7 on: June 01, 2011, 02:46:44 PM »
I don't know if you have any particular reason for the 20kHz (very small motor perhaps?), but I usually aim for around 3kHz for motor control [...]
1. I thought that anything equal to or below 20kHz is audible, hence I thought that If I use PWM to drive a MOSFET or transistor it will make sound, which I don't want.
2. If I want to use it for servo control, as far as I know servo takes 20kHz.
3. Isn't it true that the higher the frequency the more precise control is achieved?

Are any of these true?  ;D
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Analog PWM generator
« Reply #8 on: June 01, 2011, 09:20:53 PM »
Hi,

1. I thought that anything equal to or below 20kHz is audible, hence I thought that If I use PWM to drive a MOSFET or transistor it will make sound, which I don't want.
Well, you young people may be 20kHz "enabled", but it's rare to find people over 30 years with undampened hearing above 15kHz, but that aside...
It sure is annoying to listen to all the mains hum at 50 (or 60) Hz, right   :P

For a 3kHz signal to be audible, it have to be translated from alternating electrical current into alternating pressure waves. cheap motors with loose windings can make that translation (because two adjacent windings can be 180° out of phase electromagnetically, so will push and pull each other and when most of the windings do so, it will be audible.
But a MOSFET alone won't translate it.
Better quality motors will be wound better and they're usually lacquered  after winding, to bond the vindings so they're locked in place.
Besides, it has to be a real bad motor to be all that annoying, not the least among the mechanical noises from servos and gearboxes.
Besides-besides... One mans noise, another mans music   ;D


2. If I want to use it for servo control, as far as I know servo takes 20kHz.
Nope, an R/C servo use a repetition frequency of 20ms (which is 50Hz and as such quite audible, if translated into pressure waves).

But, if you make a servo system from the ground up, you're in charge of the frequencies involved of course.


3. Isn't it true that the higher the frequency the more precise control is achieved?
For an R/C servo, the frequency should be close to the 50Hz (or your servo may die screaming).
The precision (still talking R/C servos) is in the resolution and repeatability of the pulse (the 1.000ms to 2.000ms if we stick to the standard, which sadly few manufacturers do these days).
If you can set and hold the signal steady with a precision of 1..2µs, you get it as stable as the servos electronics will allow - further precision from your side is wasted.

The precision of a servo is for a large part determined by the repeatability of the position pot, backlash in the gears and how well designed and built the internal control electronics is made.

If you wanna build an R/C-like servo, I'll suggest using a pot made of conductive plastic, as they are very precise and repeatable (and unfortunately pretty costly as well). Alps makes lots of values and physical sizes.
Or, go with a rotary field Hall element with digital outputs and a magnet (the best, long term, but quite expensive though).

Since you won't be bound to the R/C signal protocol, you could either make the input an analog voltage or a digital serial (SPI/IIC) signal.
Whichever way you go, it should provide you ample learning, a.k.a. lots of swearing and hair pulling ahead, but the rush when it finally works will make your hair grow back and your swear box will secure the rest of your education   :D


If the PWM is just for running a servo, why not use a small controller and let the PWM% be determined and controlled by a PID or Fuzzy Logic algorithm. Then you don't need no stinkin' badges analog control at all.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Analog PWM generator
« Reply #9 on: June 02, 2011, 08:36:23 AM »
Well, you young people may be 20kHz "enabled", but it's rare to find people over 30 years with undampened hearing above 15kHz, but that aside...
It sure is annoying to listen to all the mains hum at 50 (or 60) Hz, right  :P
Ha ha, funny You are  ;D I got Your point though.

What I would like to make in the end is a switching voltage regulator. I want to build analog PWM generator for the sake of learning how it works. At the end of the day I might be able to use it for my final project instead of uC.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Analog PWM generator
« Reply #10 on: June 10, 2011, 12:02:40 PM »
Here is PWM generator based on calculations found on Precision Triangular-Wave Generator Uses a Single IC article.

Triangular wave generator is supposed to run at 20kHz.

Any advices before I try to prototype it?
« Last Edit: June 10, 2011, 12:33:30 PM by newInRobotics »
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline newInRoboticsTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Analog PWM generator
« Reply #11 on: June 25, 2011, 08:47:53 AM »
Here is another circuit (better than the previous I believe) and more simple as well.

Explanation:
  • Red - power supply (16V absolute max)
  • Black - 555 timer in astable configuration. Tri connector outputs triangle wave (50% duty cycle) at frequency = 1.44/(R1*C1)
  • Green - presentation of DAC from microcontroller
  • Blue - Op-Amp in Non-Inverting Summing Amplifier configuration used as Voltage Level Translator (as triangular wave from 555 timer is from Vdd/3 volts to 2*Vdd/3 volts)
  • Pink - Op-Amp used as comparator to output PWM

Question:
  • If I used this circuit to control servo, is it critical to have PWM running precisely @ 50Hz, or can it be 49.5Hz or 50.5Hz?
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline Afroman

  • Expert Roboticist
  • Full Member
  • *****
  • Posts: 50
  • Helpful? 4
    • Oscilloscope tutorial video
Re: Analog PWM generator
« Reply #12 on: June 25, 2011, 12:59:19 PM »
Servo signals don't need to be updated at a precise 50Hz; The critical thing is an accurate pulse width. Even if you update at 40Hz it will be fine. Try to not go much higher than 50Hz though.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: Analog PWM generator
« Reply #13 on: June 25, 2011, 02:08:11 PM »
Servo signals don't need to be updated at a precise 50Hz; The critical thing is an accurate pulse width. Even if you update at 40Hz it will be fine. Try to not go much higher than 50Hz though.

I've experimented with slower pulse rates and even 20Hz still worked. Once the pulse rate gets too low the servo may jitter and the holding torque is reduced.
« Last Edit: June 25, 2011, 02:15:20 PM by waltr »

 


Get Your Ad Here