PWM duty cycle as a percentage.

Status
Not open for further replies.

Suraj143

Active Member
In an eight bit register I’m turning ON a bit 100 times & the other 155 balance I’m turning OFF.
So how can I tell this as a percentage I mean the duty cycle?

Thanks
 
It is approximately 39% duty cycle. (It should really be 100 and 156 for a total of 256 states) 100 / (100+156) = 39.06%
 
Oh thank you very much kchriste now I understood.

Is there any frequency in my application?Is it 256?
 
Is there any frequency in my application?
Yes. I assume you are using a PIC (From your other posts). The PWM frequency depends on the PICs clock frequency and the values in the PR2 and T2CON registers. From a datasheet:
PWM period = [(PR2) + 1] * 4 * TOSC * (TMR2 prescale value)
PWM frequency = 1 / PWM period.
 
Oh I see I have to study that a little bit.

But in my application i'm not using any Timers its just a basic software type one.Incrementing a register 100 times while the bit is turned ON & the other balance counting upto 256 while the bit turns OFF.

My XT is 4mhz.In this situation how to tell the frequency?
 
Last edited:
My XT is 4mhz.In this situation how to tell the frequency?

Run the code in MPLAB simulator for one on/off cycle. That will tell you how long it took. Then just use 1/cycle_time for the frequency.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…