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

16f628a dimmer, simple problem

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



Joined: 15 Apr 2009
Posts: 10

View user's profile Send private message

16f628a dimmer, simple problem
PostPosted: Tue Jul 28, 2009 10:51 am     Reply with quote

Hi there!!

Here is the code:

Code:
#include <16f628a.h>
#fuses INTRC_IO,NOPUT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOMCLR
#use delay (clock=4M)

void main(){

   int inc = 0;
   int counter = 0;

   setup_ccp1(CCP_PWM);  // CCP1 set as PWM
   setup_timer_2(T2_DIV_BY_16,32,1); // timer2 set at 2 kHz
   set_pwm1_duty(inc);
     
   while(TRUE){
   
         if(input(PIN_A0)){
         
            while(input(PIN_A0)){
          }
         
            if(counter<4){
               inc = inc + 8;
               counter++;
            }
           
         }
         
         if(input(PIN_A1)){
           
            while(input(PIN_A1) && inc>0){
         }
         
            if(counter>0){
               inc = inc - 8;
               counter--;
            }
         }
         
         set_pwm1_duty(inc);
   }
         
}


Code does the following:

- When a button that is connected to PIN_A0 is pushed, LED is turned on with a duty cycle of 25%.

- Similarly, when a button that is connected to PIN_A1 is pushed, LED is dimmed with a duty cycle of 25%.

Code works but veeerrrryyyy slow Evil or Very Mad LED responds approximately after 15 seconds each time a button is pushed.

I don't think the root of the problem is hardware.

Thanks in advance...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 28, 2009 10:56 am     Reply with quote

Try using some better button code that has debouncing:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
Grimmjow



Joined: 15 Apr 2009
Posts: 10

View user's profile Send private message

PostPosted: Wed Jul 29, 2009 5:03 am     Reply with quote

Quote:
I don't think the root of the problem is hardware.


I said that however this was not true... Embarassed I had connected the pull-up resistor to the wrong side of the button. So, code was correct and is working now...

Thanks for the quick reply though...
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