PDA

View Full Version : PWM configuration



Srigopal007
- 26th October 2004, 23:59
hello everyone,

I am using the 16F77 with a 20Mhz crystal, I have tried the software PWM multiple times and and a bit dissatisfied because I cannot do anything else while I am in the PWM loop. What I want to do is have the PWM going in the background, but I do not want to use the HPWM option I have with PBP. but instead want to just set the appropriate registers myself. I was wondering if someone is willing to help me.

here is what I have so far. I have read the CHIP's manual and here is what it recommend I do.
1)Set the PWM period by wrigint to the PR2 register.
2)Set the PWM duty cycle b writing to the CCPR1L register and CCP1CON <5:4>
3)Make the CCP1 pin an output by clearing the TRISC<2> bit
4) Set the TMR2 prescalar value and enable Timer2 by writing to T2CON
5)Configure the CCP1 module for PWM operation.


Since I wanted to generate a signal around roughly 1khz and have the duty run from 0 to 100% .

I have the following at the top of my code

PR2 = %11111111 'equivalent to 0xFF for 1.22khz at 20Mhz
CCP1CON = %00110000
TRISC = %00000000
T2CON = %00000111 'starts timer and set prescalar to 16


I am not sure if this is all that is required to start the PWM function for this PIC microcontroller. Again I do not want to use the HPWM that is readily available to me by PBP.

Please, Any help with this would be greatly appreciated. Thank you.


srigopal

mister_e
- 27th October 2004, 03:29
this one will help you
http://www.melabs.com/resources/samples/pbp/hardpwm.bas