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 support@ccsinfo.com

Pwm no way CCP for Timer0

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Charles Francês



Joined: 29 Feb 2020
Posts: 7

View user's profile Send private message

Pwm no way CCP for Timer0
PostPosted: Mon Apr 27, 2020 6:07 pm     Reply with quote

Hello!
Ttelmah, I wanted the 3 pwm to read the values ​​of the matrix understood without being automatic in the for loop
God bless you Thank you for your help !


Code:


#include <16F628A.h>
#FUSES NOWDT, HS, NOMCLR
#use delay(clock=4000000)
#int_timer0
void pwm_duty(int pwm0, int pwm1, int pwm2){
   int cont;
   if(cont>15)
      cont=0;
   else
      cont++;
   if(cont>0&&cont<pwm0)
      output_high(PIN_B0);
   else
      output_low(PIN_B0);
   if(cont>0&&cont<pwm1)
      output_high(PIN_B1);
   else
      output_low(PIN_B1);
   if(cont>0&&cont<pwm2)
      output_high(PIN_B2);
   else
      output_low(PIN_B2);
   set_timer0(0);     
}
void main(){
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   set_timer0(0);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   while(true){
      int r, g, b;
      for(b=0;b<16;b++){
         pwm_duty(16,0,b);
         delay_ms(50);
      }
      for(r=16;r>1;r--){
         pwm_duty(r,0,16);
         delay_ms(50);
      }
      for(g=0;g<16;g++){
         pwm_duty(0,g,16);
         delay_ms(50);
      }
      for(b=16;b>1;b--){
         pwm_duty(0,16,b);
         delay_ms(50);
      }     
      for(r=0;r<16;r++){
         pwm_duty(r,16,0);
         delay_ms(50);
      }
      for(g=16;g>1;g--){
         pwm_duty(16,g,0);
         delay_ms(50);
      }
   }
}

}

Ttelmah you are a super saiyan help me to become a super sayiajin too
Cool Very Happy


Last edited by Charles Francês on Tue Apr 28, 2020 11:52 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Apr 27, 2020 11:54 pm     Reply with quote

Where is the rest of the code?.
You have posted an 'excerpt', again with nothing setting up the PWM,
and without anything setting up the chip itself.

There is no command 'pwm_duty'. There is pwm_set_duty, when using a
stream with #use pwm, or set_pwmx_duty when using setup_ccp.

Look at the examples, and read the manual.
EX_PWM.C

The PWM, has to use timer2 on the chip you show (on most of the more
basic PIC's).

That chip also only has one PWM.
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