Author Topic: Is it possible to divide PWM duty cycle (not frequency!) simple way?  (Read 2690 times)

0 Members and 1 Guest are viewing this topic.

Offline LinuxHataTopic starter

  • Frequent Contributor
  • **
  • Posts: 355
  • Country: us
Hello.
I have a circuit, that manages DC 12V fan via standard 4 pin interface, where PWM signal at 20 khz is delivered via a separate wire.
What I want to do, is to "divide" the duty cycle, while keeping the frequency. So say, duty cycle is 40% at input, and at output it should be 20% and so on.
I built a simple microcontroller circuit and done that in software (capture input high-low durations, calculate frequency and duty cycle, output desired as needed), but I'm curious, whenever there's some other way of doing this, say using logic circuits or something similar? I've googled, but all answers show how to divide pwm frequency, not duty cycle...
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3690
  • Country: nl
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #1 on: August 12, 2022, 07:22:13 am »
What comes to mind is a monostable flip flop, or a timer circuit.

Tuning the pulse on time can then change the pulse width of the original signal. It is not exactly a divide, because it is fixed length based on the setting of the monostable or timer and triggers on the rising edge of the input signal (or falling edge if so designed)

Offline LinuxHataTopic starter

  • Frequent Contributor
  • **
  • Posts: 355
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #2 on: August 12, 2022, 07:38:57 am »
Well that won't work - input duty cycle varies, so should do output too....
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12851
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #3 on: August 12, 2022, 08:20:22 am »
For fixed frequency PWM with one cycle delay between input and output, its conceptually fairly simple, but non-trivial to implement.

The lineup is as follows:
  • Pulsewidth => voltage + a sample and hold so its output is steady across each PWM period.
  • An attenuator to set the input to output pulse width ratio
  • A ramp generator and comparator to output PWM dependent on a control voltage.  The ramp shall be triggered by an edge of the input PWM.

One of the issues that adds complexity is that the input edge that triggers the ramp generator goes away at 0% and 100% duty cycle.

When you start considering the details, the MCU based solution is certainly preferable to the mess of analog ICs required to implement the above.  :horse:
« Last Edit: August 12, 2022, 09:45:05 am by Ian.M »
 

Online mikerj

  • Super Contributor
  • ***
  • Posts: 3237
  • Country: gb
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #4 on: August 12, 2022, 08:42:44 am »
A simple(ish) analog method would be to low pass filter the incoming PWM, scale the resulting DC voltage and use it to set the duty cycle on a PWM generation circuit, either discrete using op-amps etc. or a dedicated IC like the LTC6992.  This assumes the output doesn't need to be phase locked to the input and it wouldn't be a precision division but may be good enough.  You could also LP filter the output and use negative feedback to get a more precise division.

I don't think you'll be able to beat the simplicity of a small micro with suitable timer peripherals though.
« Last Edit: August 12, 2022, 08:44:28 am by mikerj »
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3690
  • Country: nl
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #5 on: August 12, 2022, 08:52:35 am »
One of the issues that adds complexity is that the input edge that triggers the ramp generator goes away at 0% and 100% duty cycle.

The MCU solution will also have problems with that, because it will not receive triggers either. 8)

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3690
  • Country: nl
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #6 on: August 12, 2022, 08:54:10 am »
Well that won't work - input duty cycle varies, so should do output too....

Correct, and that is what I indicated with

... It is not exactly a divide ...

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 8166
  • Country: fi
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #7 on: August 12, 2022, 02:30:08 pm »
One of the issues that adds complexity is that the input edge that triggers the ramp generator goes away at 0% and 100% duty cycle.

The MCU solution will also have problems with that, because it will not receive triggers either. 8)

OTOH, the strength of MCU is, you can work around with software, for example implementing a timeout (somewhat longer than longest expected period) after which the software assumes 0% or 100% duty.

if-elses get really annoying in analog very soon.
 

Offline PeteH

  • Supporter
  • ****
  • Posts: 113
  • Country: ca
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #8 on: August 12, 2022, 02:40:48 pm »
Something like using an LTC2644 with the timerblox chips mentioned above could do this with a simple analog divider ratio, or a simple low-pass.

Not sure why the LTC6992 solution isn't valid given the initial question, maybe glanced over?
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 1991
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #9 on: August 12, 2022, 02:52:28 pm »
But you know, if you devoted an ATTiny85, or some similar MCU, to doing nothing but generate this PWM, it's still going to be the easiest, and probably the cheapest, alternative.  And you could maybe connect a rotary encoder to it to let you adjust the PWM with the finest precision.  One 8-pin MCU and a capacitor on its Vcc.  You don't even need a crystal.
 

Offline LinuxHataTopic starter

  • Frequent Contributor
  • **
  • Posts: 355
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #10 on: August 12, 2022, 08:44:17 pm »
Well I was just curious, whenever it is doable using digital logic, not analogue circuitry.
Btw, these LTC chips have chinese clones for a long time, and with even extended features, like direct 0-10V input :)
 

Offline golden_labels

  • Super Contributor
  • ***
  • Posts: 1207
  • Country: pl
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #11 on: August 12, 2022, 09:14:05 pm »
Doable? Yes. Being simpler or having any important advantages? Consider this:

In a 20kHz 8-bit PWM the shortest pulse may be 196ns, if we ignore jitter. In a microcontroller without dedicated logic, you need at least two operations to detect two edges, which puts the lower limit on clock frequency at 10MHz — much over that in reality. Discrete gates have 5–10ns propagation delay, worse if you want full voltage swing and need to account for stray capacitances and wiring. For a 3 layer NAND circuit that needs to do two transitions per pulse, you are ending in 100ns range. At this point I am completely ignoring the need for counters that can do 10MHz range counting: just the state machine that drives them.
People imagine AI as T1000. What we got so far is glorified T9.
 

Offline KellyGreené

  • Newbie
  • Posts: 5
  • Country: ng
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #12 on: August 13, 2022, 08:48:47 am »
Check out this site, it can help you learn to calculate the duty cycle: https://www.theengineeringprojects.com/2016/02/generate-pwm-8051-microcontroller.html/?amp=1
 

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 493
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #13 on: August 13, 2022, 12:49:26 pm »
If what you really want to do is slow down the fan, then how about reducing the 12V supply?
90% of quoted statistics are fictional
 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3238
  • Country: de
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #14 on: August 13, 2022, 03:27:22 pm »
The easiest way would be:

- low pass filter + scale down (2:1 in your example) the amplitude of the 40% PWM.
- give the low pass filtered analog value (~ 12V * 40% * 0.5 = 2.4V) to the positive input of a comparator.
- feed the negative input by a 0 to 12V triangle wave form generator (integrator + comparator) with 100 kHz.

If linearity is not essential you can also use a NE555 as "triangle" generator (followed by a 3:1 rail to rail amplifier to scale the 4-8V capacitor voltage to 0-12V)

with best regards

Andreas
« Last Edit: August 13, 2022, 03:33:18 pm by Andreas »
 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3238
  • Country: de
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #15 on: August 13, 2022, 07:38:44 pm »
Hello,

further optimization of component count is possible if the duty cycle ratio does not need to be adjusted.
In this case we can directly scale the filtered input voltage suitable to the NE555 triangle voltage (1/3 to 2/3 of VCC).
So only the NE555 + a comparator (e.g. LM393) is needed.
(Hysteresis and pull up resistor not shown in the diagram).

with best regards

Andreas
 

Offline Terry Bites

  • Super Contributor
  • ***
  • Posts: 2385
  • Country: gb
  • Recovering Electrical Engineer
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #16 on: August 15, 2022, 03:56:33 pm »
You could go mad and implement a codec with a DSP system.

You can as mikej says use anlog regeneration- it will add a delay. Mostly the settling time of the LPF.
If you're not in a rush to get the conversion done then this can give an accurate result.
https://www.edn.com/cancel-pwm-dac-ripple-with-analog-subtraction/





« Last Edit: August 24, 2022, 03:44:30 pm by Terry Bites »
 

Offline antenna

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #17 on: August 15, 2022, 04:28:39 pm »
Maybe you could slow the fan down by taking a little off the beginning of the PWM waveform.  I assume the rising edges are all happening at the clock edge so cant you just run the PWM into both inputs of an AND gate and use a delay/phase shift on one of the inputs?  Maybe even something as simple as a capacitor on one of the AND gate inputs to slow the turning on of the gate.  It wouldn't be divide by two, but you could at least slow it down. 

1566463-0
« Last Edit: August 15, 2022, 04:44:02 pm by antenna »
 

Offline KaneTW

  • Frequent Contributor
  • **
  • Posts: 805
  • Country: de
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #18 on: August 15, 2022, 05:05:50 pm »
Tiny FPGA (or discrete logic if you feel like it) with a duty cycle counter, right shift by 1, PWM output. Some consideration for the case pwm_in=always 0 and pwm_in=always 1. Delay should be at most 1/20kHz.
 

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 734
  • Country: us
 

Offline LinuxHataTopic starter

  • Frequent Contributor
  • **
  • Posts: 355
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #20 on: August 23, 2023, 11:35:11 am »
Well, the question was if it is possible to do purely via "logical" way, no analog to digital conversion involved. Because if I wanted to go that way, there's a special chip available for that, GP9301B. It costs 54 cents @ LCSC and can handle the task with ease.
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3458
  • Country: us
Re: Is it possible to divide PWM duty cycle (not frequency!) simple way?
« Reply #21 on: August 23, 2023, 05:48:20 pm »
With pure logic, you can double frequency.  Then AND the original and doubled signals.  Would only work with duty cycles ≤50% .


I have not dabbled with inverting, etc. for duty cycles >50%,
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf