elder
Joined: 16 Mar 2005 Posts: 19
|
PIC16F690.. trying to code PWM auto shutdown on CCP1 |
Posted: Tue Nov 27, 2007 8:19 pm |
|
|
Hi guys, I'm trying to use the PWM feature on pic16f690 where the comparator module can be configured as feedback to shutdown the PWM.
Here is my test code...
-LED toggles as I change the voltage on pin A1 (ie comparator is working)
-The output on the ccp1 pin is 50khz with 50% duty cyc. (ie PWM working)
Problem is the PWM is always on, it doesn't shutdown with the comparator. Is the setup_ccp1() line I'm using the way your meant to set this up?
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOPROTECT, PUT, NOWDT, NOBROWNOUT
#use delay(clock=8000000)
#use rs232(baud=115200, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
void setup_PWM(){
long dutyVal;
setup_vref (VREF_LOW | 12);
setup_comparator(CP1_A1_VR);
output_low(PIN_C5); // Set CCP1 output low
setup_ccp1(CCP_PWM | CCP_SHUTDOWN_ON_COMP1); // Configure CCP1 as a PWM with shutdown on ccp1
setup_timer_2(T2_DIV_BY_1, 39, 1); // Setup for 50khz
dutyVal = 80;
set_pwm1_duty(dutyVal); // 50% duty cycle
}
//lets try PWM&CCP1 function alone
void main(){
delay_ms(200); //start up delay
output_high(PIN_C0); //'power' LED ON
setup_PWM();
while(1){
if (C1OUT){
output_high(PIN_C1); //toggle LED on comparator change
}else{
output_low(PIN_C1);
}
}
}
|
|
|