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

Multiple duty cycles within one PWM.

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







Multiple duty cycles within one PWM.
PostPosted: Wed Apr 26, 2006 12:02 pm     Reply with quote

Hello all,
I would like to generate a Variable PWM from 1 to 20Hz. When a period (.5-20mS) is selected, i would like to have 3 variable duty cycles inside this period. searching this forum i came up with code below ( i realize that this code only work to 2mS when duty_100=1023). When i turn OFF and ON CCPR1L inside duty cycle i can only see last duty cycle scope. Can i turn off and on CCPR1L of duty cycle?
Thank you,
RC_PWM

Code:


#include <16F877.h>
#device ADC=10
#device *=16
#use delay(clock=8000000)
#FUSES HS, NOWDT, NOPROTECT, BROWNOUT, NOCPD, PUT, NOLVP
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, BRGH1OK) 

char selection;
int16 duty_0=0, duty_12=128, duty_25=256, duty_50=512, duty_62=640,duty_75=786,duty_100=1023;

void main() {
  setup_port_a(ALL_ANALOG);   
  enable_interrupts(GLOBAL);   
  output_low(PIN_C1); // Set CCP2 output low
  output_low(PIN_C2); // Set CCP1 output low
  setup_ccp1(CCP_PWM);
  setup_ccp2(CCP_PWM);
  setup_timer_2(T2_DIV_BY_16, 255, 1);
while(TRUE){
   printf("\r\nFreq:\r\n");
   printf("    1) .5mS\r\n");   
   printf("    2) 1mS\r\n");
   printf("    3) 2mS\r\n");
   do {
    selection=getc();
  } while((selection<'1')||(selection>'3')); 
    switch(selection) {
     case '1' :
                 set_pwm1_duty(duty_25);   // 25% Duty Cycle
// Would like to turn off CCPR1L register
                 set_pwm1_duty(duty_50);
 // Would like to turn off CCPR1L register again
                 set_pwm1_duty(duty_25);          
                 break;         
     case '2' :
                 set_pwm2_duty(duty_62);    // 62% Duty Cycle
                 set_pwm2_duty(duty_75);     // 75% Duty Cycle
                 break;
     case '3' :
                 set_pwm1_duty(duty_50);  // 50% Duty Cycle
                 set_pwm2_duty(duty_50);    // 20% Duty Cycle               
                 break;
   }
   printf("%c\r\n",selection);
 }
}

Code:

     case '1' :
                 set_pwm1_duty(duty_25);   // 25% Duty Cycle
// When turn off CCPR1L register
                 set_pwm1_duty(duty_50);
 // When turn off CCPR1L register again
                 set_pwm1_duty(duty_25);          
                 break;   
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