| Author |
Message |
devonsc
Joined: 30 Nov 2004 Posts: 116 Helped: 1
|
30 Nov 2004 20:15 PIC Code - PWM (50% Duty Cycle) |
|
|
|
|
Hi there,
I'm a newbie in using PIC microcontroller and would like to ask something regarding the duty cycle of a PWM coding.
If its not too much trouble, can anyone briefly explain how do I determine the duty cycle of a PWM duty cycle in the coding? Is it true that 255 (decimal) is equivalent to 100% duty cycle while 0 (decimal) is equivalent to 0% duty cycle? If this is right, does it mean that I should write:
movlw d'127'
for a duty cycle of 50%? Advice needed..Please? Thanks in advance..
|
|
| Back to top |
|
 |
nicleo
Joined: 06 Sep 2004 Posts: 717 Helped: 60
|
01 Dec 2004 3:23 PIC Code - PWM (50% Duty Cycle) |
|
|
|
|
Which PIC microcontroller that you're using? Some PIC microcontrollers, e.g. PIC16F877A, has built-in PWM module.
The following article might help:
http://ww1.microchip.com/downloads/en/DeviceDoc/31014a.pdf
Here has many links on using PWM of PIC microcontroller:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1490&filterID=409
|
|
| Back to top |
|
 |
IanP
Joined: 05 Oct 2004 Posts: 6492 Helped: 1542 Location: West Coast
|
01 Dec 2004 3:43 Re: PIC Code - PWM (50% Duty Cycle) |
|
|
|
|
| Your guess is correct: for 50% the number is 127d.
|
|
| Back to top |
|
 |
devonsc
Joined: 30 Nov 2004 Posts: 116 Helped: 1
|
02 Dec 2004 12:45 Re: PIC Code - PWM (50% Duty Cycle) |
|
|
|
|
Thanks a lot.
By the way, I'm using PIC 16F876.
|
|
| Back to top |
|
 |
Google AdSense

|
02 Dec 2004 12:45 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
btbass
Joined: 20 Jul 2001 Posts: 1187 Helped: 113 Location: Oberon
|
04 Dec 2004 0:03 PIC Code - PWM (50% Duty Cycle) |
|
|
|
|
| The PIC16f876 has 2 PWM modules with a resolution of 10bits. So your period could have a count of 1024. The data sheet gives formulas for calculating the duty cycle based on the frequency and resolution.
|
|
| Back to top |
|
 |