Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pwm calculation error

Status
Not open for further replies.

kichapi

Junior Member level 2
Joined
Dec 6, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,408
hai,
I used pic 16f877a for generate 50hz square wave pwm output. I used crystel 20mhz.but i have some doubt in PR2 -calculation please help me

1)Pwm period = [(PR2+1)] x 4 x 20Mhz x Time prescale value

1/50 =[(PR2+1)] x 4 x 20mhz x Time prescale value

2) Pwm duty cycle=(CCPR1L:CCP1CON<5:4>) x Tosc x (Time prescale value)

please help this calculation

Please help these two calculation
 

Pwm period = [(PR2+1)] x 4 x 20Mhz x Time prescale value

You need the period of the oscillator, Should be

Pwm period = [(PR2+1)] x 4 x 1/20Mhz x Timer prescale value.

You wont be able to go down to 50Hz using a 20MHz clock!
Even with the prescale at max, you could only go down to ~1K2.

50Hz is quite slow, you could implement your square wave using a timer interrupt.
Or use a sub 1MHz xtal.
 

hai,
Thank you for your valid replay. how do this 50hz pwm please help the program
 

One way to do this is to have two global variables to use as counters, one for period, one for duty cycle.

Set up one of the timers to interrupt every 1mS, you can use mp sim to adjust the timing by setting a breakpoint in the interrupt routine and using the Stop clock.

The period for 50Hz is 20mS, so when the period counter reaches 20, clear the counter and set the output high. When the period counter equals the duty cycle counter, set the output low.

This gives you 1mS resolution for duty cycle. You could increase the interrupt frequency if you need more resolution.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top