Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Frequency divider wich maintain the duty cycle

Status
Not open for further replies.

sorell13

New Member
I have a microcontroller and it generates around 1KHz the minmum frequency to 200kHz with variable duty cycle from 0 to 100%. But this frequency is sometimes too high and i want to put at the output a frequency divider (or many frequency dividers) to reach 1Hz the minimum frequency (or around 1Hz). But, is there technique/do you have a scheme of a frequency divider (prescaler) which does this job well? (i mean to maintain the duty cycle of the input frequency). Thank you!
 
Your description was a bit hard to understand so let me restate the question to see if I understand.

You want to generat a PWM output between 1KHz and 200Khz with a duty cycle between 0 to 100 percent.

You talked about input frequency but I am guessing that is in relation to your intended fix. Try this instead.

For each PWM frequency you need to calculate timer settings (using code) that will cause the timer to overflow 100 times the PWM frequencey.

Then use a loop that watches the timer to set the output high and low at the correct time.

The program would:

  1. setup timer at 100x the PWM frequency
  2. if duty cycle is greater then 0 set output high, start counting timer overflows.
  3. When the timer has overflowed the same number of times as the duty cycle percentage set the output low.
  4. Wait till the 100th timer overflow
  5. goto 2

I use this method to generate PWM output that power the two motors for differantial drive robots. You watch for the 2 different duty cycle percentages (Left and Righ) and manage 2 outputs.
 
Last edited:
Thank you!
I will be more clear.
I already build a pwm generator with a microcontroler which outputs a frequency between 1kHz and 200kHz with variable duty cycle from 0 to 100%.

I want to divide this frequency in order to obtain a lower rang of frequencies but i want to have the same duty cycle.
For example: i generate with the microcontroller a frequency of 1kHz with 80% duty cycle. I want to put this frequency at the input of a "frequency divider" and at te output of the frequency divider to have 500Hz with 80% duty cycle (same duty cycle as at the input)
Thank you!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top