CR4® - The Engineer's Place for News and Discussion®

 Previous in Forum: Need Air Mover Options for a Couple of Projects Next in Forum: Material for Pipe Milk Dairy - Milk Transferring to Silo/Packing Machine
Guru

Join Date: Oct 2006
Location: MSP, MN
Posts: 620

# Precise Duty Cycle of PWM

11/03/2017 1:53 PM

I need my analog brain trust. As P/O a project I need to determine the duty cycle of a PWM signal. This signal will have frequency of 10hz to 100hz and duty cycle of 2% to 40%, both parameters constantly changing. And I need an output that has no ripple and no latency; i.e., it will reflect the duty cycle of the PWM as of the last pulse. I have come up with this insanely complicated circuit:

The PWM signal has it's 1 and 0 times converted to voltages (see pulse width to V).

These are added by op amp to get the period. Then a voltage divider (AD539 or similar) divides the input pulse by the period to yield the duty cycle.

1) Can you find problem(s) with this circuit?

2) Is there an easier way, given the strict output rqmnts? I really want to stay away from microprocessors and software. The last program I wrote was in Fortran..

Pathfinder Tags: analog duty cycle PWM
Interested in this topic? By joining CR4 you can "subscribe" to

Check out these comments that don't yet have enough votes to be "official" good answers and, if you agree with them, rate them!
Guru

Join Date: Dec 2008
Location: Long Island NY
Posts: 12349
#1

### Re: Precise Duty Cycle of PWM

11/03/2017 2:11 PM

Well first off your operational amplifier has only positve feedback. Thus it will be a summing comparator with hysterisis.

__________________
"Don't disturb my circles." translation of Archimedes last words
Guru

Join Date: Mar 2011
Location: Lubbock, Texas
Posts: 14222
#2

### Re: Precise Duty Cycle of PWM

11/03/2017 3:56 PM

This is way complicated. Duty cycle = average voltage / supply voltage.

__________________
If it ain't broke, don't fix it. Just build a better one.
Guru

Join Date: Mar 2007
Location: at the beach in Florida
Posts: 19743
#3

### Re: Precise Duty Cycle of PWM

11/03/2017 4:01 PM

Don't know if this will be any help....but at least it gives some info

https://www.edn.com/design/analog/4330703/DDS-circuit-generates-precise-PWM-waveforms

..."Traditional PWMs use two op amps to generate a sawtooth waveform, a potentiometer to generate a dc reference, and a comparator to generate the PWM output. The advantage of this type of design is that the circuit is practical and inexpensive. Unfortunately, you cannot easily program the frequency without changing component values, and fine-frequency tuning is difficult. Another problem with this method is that accurate control of the duty cycle is difficult. You could use a digital potentiometer in place of the mechanical one, "....

Digital potentiometer

Analog PWM

http://www.ti.com/lit/ug/slau508/slau508.pdf

__________________
Life is like riding a bicycle. To keep your balance you must keep moving. A.E.
Guru

Join Date: Mar 2011
Location: Lubbock, Texas
Posts: 14222
#4

### Re: Precise Duty Cycle of PWM

11/03/2017 4:11 PM

You can generate a controlled frequency using PWM functions in Arduino IDE with \$cheap\$ Arduino UNO, and control the duty factor with delay function.

__________________
If it ain't broke, don't fix it. Just build a better one.
Guru

Join Date: Dec 2008
Location: Long Island NY
Posts: 12349
#5

### Re: Precise Duty Cycle of PWM

11/03/2017 4:13 PM

I also have a very big problem with the stated attribute of no latency. Any analytic circuitry or program can only produce a result based on the previous edge, thus latency is a requirement.

__________________
"Don't disturb my circles." translation of Archimedes last words
Guru

Join Date: Apr 2010
Posts: 5906
#6

### Re: Precise Duty Cycle of PWM

11/03/2017 8:15 PM

It looks like it could work...v1 is the high time, v2 the low time + high time, v0 = v1/v2.

Your "pulse width to voltage" blocks would be integrators with a fixed voltage input. Select a voltage so that the integrator does not max out at the lowest frequency (longest period). You need 2 integrators, one fed with an inverting signal as shown.

There are a few things to consider. You want it to work continuously, so the output of each integrator needs to be stored until the end of the cycle, and each integrator needs to be reset for the next cycle.

So you need some logic so that when the input is high, it is integrating. When the input drops low, the output is latched and then the integrator is reset. I would drive a capacitor on the output of the integrator. Put a CMOS switch between the integrator and capacitor. Opening this switch will latch the voltage on the output capacitor (sample and hold).

Sample and Hold:

Another CMOS switch in parallel with the feedback capacitor of the integrator can be turned on to reset the integrator. (Delayed slightly after sample and hold)

One integrator is integrating while the other is reset allowing this thing to operate continuously.

To get the voltage ratio, I would use the AD534 which will give you the ratio of two voltages with the right connection:

I hope this helps. I think it will work. Please let us know how it comes out!

Guru

Join Date: Oct 2006
Location: MSP, MN
Posts: 620
#7

### Re: Precise Duty Cycle of PWM

11/03/2017 9:12 PM

Thanks for the considered response, Rixter. I've built a slick PWM generator with variable duty cycle and frequency (see PWM generator) to test my design. AD has a bunch of chips that do voltage division; AD633 is only \$11, but needs an op amp. AD539 is a little cheaper than AD534, but both seem to do the job. If no one finds a problem with my design I'll build the circuit and post results.

Guru

Join Date: Apr 2010
Posts: 5906
#8

### Re: Precise Duty Cycle of PWM

11/03/2017 9:55 PM

It looks good on paper to me. Building a test circuit is the way to go.

One of these days, maybe I'll get back to building circuits. I used to do it all the time, first on a breadboard, and when I got the design working, on a perfboard with wirewrap sockets. There is a lot of satisfaction in dreaming up a design and seeing it work.

Guru

Join Date: Oct 2006
Location: MSP, MN
Posts: 620
#14

### Re: Precise Duty Cycle of PWM

11/04/2017 11:35 AM

Is there anything so satisfying as breadboarding a circuit and seeing it work? Well, yes, but they all involve naughty stuff. Here's my PWM generator:

I bought a couple of these "proto boards" many years ago, and have gotten good use of them.

Guru

Join Date: Apr 2010
Posts: 5906
#16

### Re: Precise Duty Cycle of PWM

11/05/2017 4:01 PM

That's the same breadboard I have. I built +5 V and +/- 12 V power supplies in a metal box and mounted the breadboard on top.

I used to use a slit-n-wrap (184-1) to wirewrap a circuit after I had it perfected, using wirewrap IC sockets and wirewrap pins for the discrete components. You can wire multiple pins together with a continuous wire run with the slit-n-wrap, which reduces the effort of building a circuit.

http://www.mouser.com/catalog/specsheets/574WIRET.pdf

Guru

Join Date: Dec 2008
Location: Long Island NY
Posts: 12349
#9

### Re: Precise Duty Cycle of PWM

11/03/2017 10:15 PM

I've used all three analog ratio chips and there is one inherent problem with them. They become unstable and oscillate when the denominator approaches zero. Be very careful with the circuitry for the denominator to prevent this.

Speaking of the denominator circuitry, if you don't change the input polarity to the op amp that generates V2 then this output will always sit at the positive rail, information will be lost. If you swap polarities then V2=k(Vpwp+Vpwn). {Voltage Pulse Width Positive -> Vpwp, k is the combined transfer function of pulse width to voltage and the feedback resistor}

__________________
"Don't disturb my circles." translation of Archimedes last words
Guru

Join Date: Oct 2006
Location: MSP, MN
Posts: 620
#10

### Re: Precise Duty Cycle of PWM

11/03/2017 11:38 PM

This seems to be a preferred noninverting summer:

op amp summer What do you think?

Guru

Join Date: Dec 2008
Location: Long Island NY
Posts: 12349
#12

### Re: Precise Duty Cycle of PWM

11/04/2017 7:39 AM

Notice in your link that the feedback resistor connects the output to the inverting (-) pin and a fourth resistor is also connected from the inverting pin to ground. Your sketch has the inverting pin directly connected to ground.

__________________
"Don't disturb my circles." translation of Archimedes last words
Power-User

Join Date: Sep 2016
Location: SPAIN
Posts: 192
#11

### Re: Precise Duty Cycle of PWM

11/04/2017 5:41 AM

The only industry, as far as I know, where microprocessors are not used, and this types of circuits need to be optimized, is the aerospace industry. If that is not your case, it will be way more useful for you to learn the basics of programming before continuing with this task, or if you prefer it, get a freelancer to do the programming for you. Upwork has plenty of people willing to do it very cheap.

On the other hand, I remember being stunned by your old post PWM-to-PWM-Converter-But-No-Microprocessor, where you wanted 400Hz bandwidth at the output. Here, the best you are getting is about 100 times less, which is anything other than nice! I wonder how much your goal has changed since then.

__________________
Building the future!
Guru

Join Date: Oct 2006
Location: MSP, MN
Posts: 620
#13

### Re: Precise Duty Cycle of PWM

11/04/2017 11:12 AM

Hi Ivan. This thread is P/O my other thread. I know how to convert the voltage from this circuit into the PWM (fixed freq ∼400hz) to drive the servo; that's the easy part. It's this sensing of the input duty cycle that had me stumped for awhile.

Power-User

Join Date: Sep 2016
Location: SPAIN
Posts: 192
#15

### Re: Precise Duty Cycle of PWM

11/05/2017 9:40 AM

If I had to do it personally, I would use a micro to count on-time cycles, count off time cycles, and divide.

Doing that with OPAMP would be on time integrate, off time integrate... and then what? Scale? I do not even know if that is possible.

The most unusual solution other than a microprocessor I could recommend you would be using 4000 and 5400 series ICs (7400 series if you are in the MIL industry). You will not have to deal with any programming language, but you will have to draw many electronic circuits.

You can also do the digital logic in a FPGA. After all: it would not be cheaper, but it certainly would be smaller and easier to troubleshoot!

__________________
Building the future!
Interested in this topic? By joining CR4 you can "subscribe" to