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

TMR0 as external pulse counter

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

TMR0 as external pulse counter
PostPosted: Fri Dec 17, 2010 9:13 am     Reply with quote

Hi, anyone can tell me how I can use the TMR0 to count external pulses ? I am using a pic18f452 to 20Mhz. I need to count the number of pulses every 1 second.
This is part of my code but I do not think it is wrong
Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)

int pulsos;

void main(){

   setup_counters (RTCC_EXT_H_TO_L, RTCC_DIV_1);
         
while (TRUE){

   set_timer0(0);
   delay_ms(1000);
   pulsos = get_timer0();

   }
}


Last edited by pilar on Fri Dec 17, 2010 10:00 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Fri Dec 17, 2010 9:34 am     Reply with quote

Start by thinking what 'AKA', and 'or' means. Look at the include file for your processor.
What does "SETUP_COUNTERS() or SETUP_TIMER_0()," mean?.
What do you think happens, if you set timer0 (AKA the RTCC) to use an external clock, and then a line later, set it to use an internal clock?. Which do you think it'll end up using?.

Remove one line, and you may have a chance.....

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Dec 17, 2010 9:35 am     Reply with quote

read the section on the CCP module. (if that PIC has one. if not, look at the datasheet for one that does.)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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