Author Topic: PWM frequency doubler/multiplier?  (Read 8162 times)

0 Members and 1 Guest are viewing this topic.

Offline fubar.grTopic starter

  • Supporter
  • ****
  • Posts: 366
  • Country: gr
    • Fubar.gr
PWM frequency doubler/multiplier?
« on: March 05, 2017, 12:52:30 pm »
Suppose I have a PWM source at a frequency of around 200Hz.  What is the simplest method to double that frequency, while maintaining the original duty cycle?

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7733
  • Country: ca
Re: PWM frequency doubler/multiplier?
« Reply #1 on: March 05, 2017, 01:32:12 pm »
What type of accuracy/resolution do you need for the pwm widths.  The simplest would most likely be a small 65cent 8 pin PIC MCU with a cheap small program.  All you need is VCC, GND, in and out, 1 decoupling cap, 1 pull up resistor + the programming connector for development.

PLL clock multiplication will double your frequency, but, you will loose the PWM width size.  It will also take quite a few more components than the PIC MCU.
 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3246
  • Country: de
Re: PWM frequency doubler/multiplier?
« Reply #2 on: March 05, 2017, 08:22:05 pm »
Hello,

The fully analog way would be using a low pass filter to get a DC voltage.
Then a triangle waveform generator with the new frequency.
A comparator between triangle and filtered DC voltage gives the duty cycle.

with best regards

Andreas
 


Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7733
  • Country: ca
Re: PWM frequency doubler/multiplier?
« Reply #4 on: March 06, 2017, 03:44:39 am »
http://eprints.eemcs.utwente.nl/23243/01/Ma.S.MSc2013Feasibility_study_of_frequency_doubling_using_an_an_xor-gate_method.pdf

https://www.maximintegrated.com/en/app-notes/index.mvp/id/3327

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=12&cad=rja&uact=8&ved=0ahUKEwiOkPGT3sDSAhUq6IMKHaBRAzkQtwIIajAL&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMBiYd5H5w3Q&usg=AFQjCNFMVZz5_w9a2w0WGpkQR2MTk2WPcA&sig2=fIA2w8SdtZi8ncB0_oKx0g


Regards, Dana.

The XOR gate trick wont preserve the %pwm ratio from High to Low.  Say the source starts with a 200hz 2%on going through the XOR gate, will the output 400hz have the 2%on, 98% off.  Then when the source has a 75%on/25%off.  I've successfully used XOR frequency doubling in the few MHZ range, and changing the pwm width at the source created a weird output waveform whenever the duty cycle was more than +/-5% off of the optimum 50%.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: PWM frequency doubler/multiplier?
« Reply #5 on: March 06, 2017, 06:36:45 am »
At 200 Hz, I would use a microcontroller - even an Arduino.

Sample a digital input to get high/low values.  These will give you frequency and duty cycle.  Play them back at double the rate.  Propagation delay will be one input cycle.
 

Offline kosine

  • Regular Contributor
  • *
  • Posts: 158
  • Country: gb
Re: PWM frequency doubler/multiplier?
« Reply #6 on: March 06, 2017, 01:10:50 pm »
It might be a little trickier that it seems, but the Arduino does support a pin_change interrupt: http://playground.arduino.cc/Main/PinChangeIntExample

If you need an exact doubling of frequency whilst retaining the duty cycle, then I think this approach might work...

Firstly, you need to keep the code as lean as possible. If the PWM input is 8-bit (256 levels), then you need to be sampling it above 50kHz. A 16MHz microcontroller gives you about 300 clock cycles per sample, though you're looking at just 150 for the doubled output. That should be enough if you use some lower level code. (E.g., use PORTB=xx rather digitalWrite, and use integer variables instead of floats. Maybe even use some assembly code if you can. )

Step 1: Use two variables inside the pin_change interrupt function to count between incoming PWM changes in microseconds. This maps out a complete on-off duty cycle.

Step 2: Once you have the cycle durations, duplicate these values using a binary bit-shift-right to divide them by 2 (i.e, c = a >> 1; d = b >> 1;). You now have four variables: a=on time duration, b=off time duration, c=on/2, d=off/2.

Step 3: Use these values to create four new ones by adding them to the current system micros() value. These will be r=c+micros(), s=a+micros(), t=a+c+micros(), u=a+b+micros(). You now have four times in the (very near!) future at which you need to toggle your output pin.

Step 4: Create a timer_interrupt routine with "attachInterrupt(function, period)" (http://playground.arduino.cc/Code/Timer1) A period of 100 might be OK, but you may need to play around with this. It needs to be as low as possible without locking up. Inside that interrupt function just compare your four time values (rstu) with micros() and toggle the output pin as each is reached.

You may have to set "period" to a much higher value to give the function time to execute, but it should still work, just not at 8-bit resolution. Also, at 200Hz input you'll get a 5ms delay in the output signal, but that's inevitable and might not be a problem.

If throwing a full-blown Arduino at it is overkill, the 8-pin ATTiny chips also support the pin_change interrupt. However, the internal clocks of stand-alone microcontrollers are not that great (+/- a few percent typically). An external crystal is always better for anything time-critical.

If you've got an Arduino and an oscilloscope it shouldn't take very long to try this out. If you don't have a scope, at these frequencies you could probably feed the signal into a PC's soundcard and capture the waveform. (You'd need to check, but I think the mic input expects a few mV, the line input about 0.5V, so you'd need to divide down the PWM output to a suitable level.)

Interesting problem! Let us know if you can get it working.
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7733
  • Country: ca
Re: PWM frequency doubler/multiplier?
« Reply #7 on: March 06, 2017, 01:40:11 pm »
That's a little too overkill for this project.

Remember, the cheap PIC has both a PWM out and a 16 bit capture timer & compare function input.  Just run 1 input to the 16 bit capture timer & store the low time and high time.

Feed the high period counter number divided by 2 to the PWM module & the sum of the high and low period timer divided by 2 into the period length of the PWM module.  Your output waveform will be a 2x speed version of the input.  Running the PIC at 1 MHz should be overkill for this 200hz clock doubling app.  Ok, run it at 4 MHz just to be safe and have a few additional features squeezed in...
« Last Edit: March 06, 2017, 01:43:33 pm by BrianHG »
 

Offline kosine

  • Regular Contributor
  • *
  • Posts: 158
  • Country: gb
Re: PWM frequency doubler/multiplier?
« Reply #8 on: March 07, 2017, 01:19:05 pm »
1MHz may be cutting it a bit fine: Although the overall cycle is 200Hz (5ms), the duty cycle steps are far more fine-grained.

At 50% duty cycle, you get a transition every 2.5ms. At 5% you're down to a transition after just 250us. 1% is just 50us, and an 8-bit PWM would allow steps of about 0.4%, which is just 20us.

Since you're doubling the frequency, the output transitions need to happen twice that fast, so 10 clock cycles at 1MHz.

Of course, you may not need 8-bit precision or 0.4%-99.6% duty cycles, and 5-10 low-level instructions might be enough in any case. If the PIC's PWM is fully programmable, then just setting some registers should be possible in 10 cycles. Though running on a faster clock would make sense, especially if you wanted to go to higher multipliers.
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7733
  • Country: ca
Re: PWM frequency doubler/multiplier?
« Reply #9 on: March 07, 2017, 02:22:39 pm »
Since you're doubling the frequency, the output transitions need to happen twice that fast, so 10 clock cycles at 1MHz.

Now, just so we are clear, we are not talking about CPU cycles here.

     You only need to read the High counting timer's results 200 times a second, or, once every low to high transition, with the timer's clock set to run at half the cpu clock speed making it count at 500Khz.  That gives you a read resolution of 2500 samples for the source reference, 99.9% high.  This is much better than 8 bit by a land slide.  For the PWM output, you feed that 1 same count number in to the PWM output, only doing this once, every 1/200th of a second, with the PWM module configured to run at 1 Mhz making the high pulse half the size of the source, no divide by 2 needed.  The output PWM period should be set to 400hz so you get 2 sets of the half sized pulses for each input.

     You can literally make this project work this good, 0.04% per step, running the PIC cpu at 32Khz, timer #1 running at 500Khz, and the PWM's clock at 1Mhz.
« Last Edit: March 07, 2017, 02:25:49 pm by BrianHG »
 

Offline orolo

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: es
Re: PWM frequency doubler/multiplier?
« Reply #10 on: March 07, 2017, 04:40:21 pm »
Just for the fun, you can go full analog. The basic intuition is that a 400Hz wave with the same duty cycle that your 200Hz must have the same DC component (integral over one 200Hz cycle). So if you aggressively low-pass filter the 200Hz and 400Hz pwm square waves, the DC component will be the same if, and only if, the duty cycles are equal. You can arrange a feedback system with error signal equal the difference between the LPF waves, and feed it back to a PWM generator.

The circuit below tries to do that. Start with a 400Hz triangle wave, and get a PWM wave using a comparator. In one of the comparator terminals goes the triangle wave, in the other the integral of the error. The error is derived from low pass filtering (Sallen-Key Chebishev, 10Hz, two poles) the input PWM 200Hz signal, and the 400 variable PWM signal, passing them to a differential amplifier to substract the DC components, and finally a RC filter to clean up.

The circuit is a little mess put together in a hurry, but it takes the error to zero when given a 30% duty cycle 200Hz wave. Of course, it should be designed using a serious analysis of stability and convergence.

Anyway, the idea that you can get an error function using a couple of low pass filters is another approach. If you pass the error function to an ADC, you can digitally modulate the duty cycle of the 400Hz wave to minimize the error.

 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 14197
  • Country: de
Re: PWM frequency doubler/multiplier?
« Reply #11 on: March 07, 2017, 06:22:07 pm »
Doubling the frequency and keep the PWM ratio is quite an effort. So the best way would really be create the PWM signal directly at the correct frequency - so a avoid the doubling all together. Using an extra µC do double the frequency would need an µC that is more than capable to generate the correct signal directly.

The analog circuit shown below is only half the solution - it is still missing the part to generate the double frequency triangle wave.
 
The following users thanked this post: orolo

Online joeqsmith

  • Super Contributor
  • ***
  • Posts: 11744
  • Country: us
Re: PWM frequency doubler/multiplier?
« Reply #12 on: March 08, 2017, 03:18:43 am »
Suppose I have a PWM source at a frequency of around 200Hz.  What is the simplest method to double that frequency, while maintaining the original duty cycle?

Interesting question.  Care to add more details about the incoming signal?  PWM resolution?  Need to support 0 - 100%?  Input frequency range?  Is the frequency fixed?  Jitter?  Any idea of the step response?  Any settling time requirements?   

Without knowing much about it, seems like it would be easy enough to do it all in digital.       

Offline orolo

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: es
Re: PWM frequency doubler/multiplier?
« Reply #13 on: March 08, 2017, 07:11:19 pm »
The analog circuit shown below is only half the solution - it is still missing the part to generate the double frequency triangle wave.
I have little to none experience with this kind of circuits, but as a first try I'd push in this direction:

If the 200Hz pwm signal is divided by 2, the variable pulse width is removed. The output of a typical op-amp + comparator VCO is divided by 4. Both signals are xor'ed, and the result is integrated and fed back to the VCO. The triangle wave of the VCO is taken from there. Would this work?

After "convergence" (the error is always positive, so convergence depends on the equilibrium between added error and integrator decay, this could be clearly improved), I get:



The circuit (again, without concern for any fine tuning) and model are attached below.
« Last Edit: March 08, 2017, 07:12:59 pm by orolo »
 

Offline fubar.grTopic starter

  • Supporter
  • ****
  • Posts: 366
  • Country: gr
    • Fubar.gr
Re: PWM frequency doubler/multiplier?
« Reply #14 on: March 08, 2017, 11:54:52 pm »
Suppose I have a PWM source at a frequency of around 200Hz.  What is the simplest method to double that frequency, while maintaining the original duty cycle?

Interesting question.  Care to add more details about the incoming signal?  PWM resolution?  Need to support 0 - 100%?  Input frequency range?  Is the frequency fixed?  Jitter?  Any idea of the step response?  Any settling time requirements?   

Without knowing much about it, seems like it would be easy enough to do it all in digital.     


My computer monitor brightness has dropped significantly, to the point that it is barely useable during the day. There's no problem with the power supply, so I believe the ccfl lamps are nearing their end of life.

I found that they sell on ebay LED strip kits specifically made for converting CCFL monitors to LED backlight. But I read somewhere that the PWM that controls the CCFL brightness has a rather low frequency, between 170 and 250 Hz, and that makes LED strips flicker visibly.

The conversion kits all look like this, and all have the same controller board: http://www.ebay.co.uk/itm/2x-LED-Backlight-Strip-Board-Cable-385mm-Kit-19-Inch-CCFL-LCD-Screen-to-Monitor-/381749215027?hash=item58e206bf33:g:oBsAAOSwIgNXwCZK

Now maybe the controller takes into account the low PWM frequency and automatically multiplies it.

But in any case I think that a circuit that multiplies a PWM signal frequency could have more uses.

I do have a PICit 3 and some small 6 and 8 pin PICs lying around, so I will give it a try!


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf