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.

PWM Frequency Problem

Status
Not open for further replies.

Suraj143

Active Member
Guys I have used the PWM module & I have some basic knowledge.

I'm working according to below formulas.

PWM period = [(PR2) + 1] • 4 • TOSC • (TMR2 prescale value)

PWM duty cycle = (DCxB9 : DCxB0 bits value) • Tosc • (TMR2 prescale value)

My question is datasheet says when you go for higher PWM frequency you must decrease the resolution so I cannot use full 10 bits resolution.

Why is that?
 
An easier way to think about the PWM resolution is that the duty cycle can go from zero to (PR2+1)*4 so for the best resolution use as large a value as possible in PR2 and use the prescaler to adjust the frequency.

The reason the resolution decreases is because the duty cycle is compared to timer2 and timer2 resets when it matches PR2 therefore any value greater than PR2 will result in 100% duty cycle.

Mike.
 
An easier way to think about the PWM resolution is that the duty cycle can go from zero to (PR2+1)*4 so for the best resolution use as large a value as possible in PR2 and use the prescaler to adjust the frequency.

The reason the resolution decreases is because the duty cycle is compared to timer2 and timer2 resets when it matches PR2 therefore any value greater than PR2 will result in 100% duty cycle.

Mike.

Very nice easier to understood.

Thanks mike
 
It took me a while to suss out the pwm module, perosnally I found the datasheet very difficult to understand.
Theres a couple of websites that explain its operation well.
Some pics you can define the o/p of the pwm to a choice of pins.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top