CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F690.. trying to code PWM auto shutdown on CCP1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elder



Joined: 16 Mar 2005
Posts: 19

View user's profile Send private message

PIC16F690.. trying to code PWM auto shutdown on CCP1
PostPosted: Tue Nov 27, 2007 8:19 pm     Reply with quote

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);
      }
   }
}
elder



Joined: 16 Mar 2005
Posts: 19

View user's profile Send private message

PostPosted: Tue Nov 27, 2007 9:14 pm     Reply with quote

OK problem solved by doing the register bits myself... heres the change in case anyone comes searching down the track...

I replaced this line from the above code:
Code:

setup_ccp1(CCP_PWM | CCP_SHUTDOWN_ON_COMP1);


with these lines:
Code:

#byte ECCPAS  = 0x1D
#byte PWM1CON = 0x1C
setup_ccp1(CCP_PWM);
ECCPAS = 0x10;       //set PWM to shutdown on CCP1
PWM1CON = 0x80;      //set PWM to autorestart after shutdown condition clears.. equivalent of CCP_SHUTDOWN_RESTART I imagine.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group