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

Problem on using TIMER1 on PIC16F877A as counter

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



Joined: 23 Feb 2009
Posts: 4

View user's profile Send private message

Problem on using TIMER1 on PIC16F877A as counter
PostPosted: Tue Feb 24, 2009 10:27 am     Reply with quote

hi all, i am very new in electronics, but i would like to do a very simple counter to count the pulse. I have an opto sensor which produce 5V when blocked and 0V when unblocked, this will create a train of 0-5-0-5-0-5 pulses, i wan to count the pulse using Timer1 (Pin RC0 as TIMER1). The following is my simple program to test if 3 pulses were counted, the LED will light up.. however, it seems like the counter doesnt count my input... anyone can guide me please?

#include<16f877a.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#byte PORTC=7 //Call Port C
#byte PORTD=8 //Call Port D

void main() //Main Block
{
int count=0; //Receives timer count
set_tris_D(0b00000000); //Set Port D as I/O
setup_timer_1(T1_EXTERNAL);// The timer is set up for external input

do{
set_timer1(0); //Reset counter
count=get_timer1(); //Resulting count is read using get_timer()
if (count==3) //if 3 pulse were counted
{output_high(pin_D7);}// LED light up
else
{output_low(pin_D7);}//LED light off

}while(1);


}
Ttelmah
Guest







PostPosted: Tue Feb 24, 2009 11:37 am     Reply with quote

Hint use code buttons....
Code:

   set_timer1(0); //Reset counter
   do{
   count=get_timer1(); //Resulting count is read using get_timer()
   if (count==3) //if 3 pulse were counted
     {output_high(pin_D7);}// LED light up
   else
      {output_low(pin_D7);}//LED light off
  }while(1);


Problem is that you are resetting the counter every time round the loop, so how can it ever reach 3?.....

Best Wishes
leeyung



Joined: 23 Feb 2009
Posts: 4

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 8:01 am     Reply with quote

Ttelmah wrote:
Hint use code buttons....
Code:

   set_timer1(0); //Reset counter
   do{
   count=get_timer1(); //Resulting count is read using get_timer()
   if (count==3) //if 3 pulse were counted
     {output_high(pin_D7);}// LED light up
   else
      {output_low(pin_D7);}//LED light off
  }while(1);


Problem is that you are resetting the counter every time round the loop, so how can it ever reach 3?.....

Best Wishes


opss... got it, sorry for the mistake, thx a lot Smile
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