I'm trying to set up the half-bridge PWM outputs on a 16F684. Not having much luck...
I've read section 11 of the data sheet (41202F) about a million times now. The individual words make sense to me... but I still can't seem to grasp the concept of how to make this thing work.
I *think* I've done the setup according to these instructions in the data sheet, but now I don't know what to do next to make it get up and run.
Here's the setup instructions from Data Sheet:
11.3.7 SETUP FOR PWM OPERATION
The following steps should be taken when configuring
the CCP module for PWM operation:
1. Disable the PWM pin (CCP1) output driver by
setting the associated TRIS bit.
2. Set the PWM period by loading the PR2 register.
3. Configure the CCP module for the PWM mode
by loading the CCP1CON register with the
appropriate values.
4. Set the PWM duty cycle by loading the CCPR1L
register and CCP1 bits of the CCP1CON register.
5. Configure and start Timer2:
• Clear the TMR2IF interrupt flag bit of the
PIR1 register.
• Set the Timer2 prescale value by loading the
T2CKPS bits of the T2CON register.
• Enable Timer2 by setting the TMR2ON bit of
the T2CON register.
6. Enable PWM output after a new PWM cycle has
started:
• Wait until Timer2 overflows (TMR2IF bit of
the PIR1 register is set).
• Enable the CCP1 pin output driver by clearing
the associated TRIS bit.
Here's the little bit of setup code I've got so far. Not sure what to do next.
Could one of you good folks please help point me in the right direction?
Any help would sure be appreciated..Code:</i></font><b>INCLUDE </b><font color="#FF0000">"MODEDEFS.BAS" </font><font color="#000080"><i>'Include Shiftin/out modes </i></font><b>DEFINE </b>OSC 8 <font color="#000080"><i>'8MHz clock </i></font>TRISA= %00000000 <font color="#000080"><i>'Set 'em all to outputs </i></font>TRISC= %00000000 <font color="#000080"><i>'Set 'em all to outputs </i></font>ANSEL = %00000000 <font color="#000080"><i>'Turn off that analog crap </i></font>OSCCON = %01110001 <font color="#000080"><i>'8MHz </i></font>TRISC.5 = 1 <font color="#000080"><i>'disable CCP1 </i></font>PR2 = $65 <font color="#000080"><i>'load a value into PR2 </i></font>CCP1CON= %10001100 <font color="#000080"><i>'half bridge, all PWM outputs active high </i></font>CCPR1L= %11111111 <font color="#000080"><i>'set the PWM duty cycle </i></font>PIR1.1 = 0 <font color="#000080"><i>'clear the TMR2IF interrupt flag </i></font>T2CON.0 = 0 <font color="#000080"><i>'set prescaler to 1... </i></font>T2CON.1 = 0 <font color="#000080"><i>'...set prescaler to 1 </i></font>T2CON.2 = 1 <font color="#000080"><i>'turn timer 2 on </i></font>TRISC.5 = 0 <font color="#000080"><i>'enable CCP1 'Now what? </i></font><b>END </b></code></pre><!--EndFragment--></body> </html>
Thanks!
steve
Bookmarks