View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
TMR0 as external pulse counter |
Posted: Fri Dec 17, 2010 9:13 am |
|
|
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: 19546
|
|
Posted: Fri Dec 17, 2010 9:34 am |
|
|
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
|
|
Posted: Fri Dec 17, 2010 9:35 am |
|
|
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 |
|
|
|