View previous topic :: View next topic |
Author |
Message |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Timer0 doesn’t seem to count external pulses |
Posted: Mon Jul 27, 2015 2:19 pm |
|
|
Folks,
I’m trying to use the Timer0 as a tachometer to keep track of a fan. I can see the square wave on the RA4/T0CKI pin with the oscilloscope. But the counter doesn’t seem to be incrementing.
Fuses:
Code: | #FUSES INTRC_IO //Internal RC Osc, no CLKOUT |
Timer0 setup
Code: | setup_timer_0(RTCC_EXT_H_TO_L | RTCC_DIV_1); // Fan tachometer
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); // control loop pace
setup_timer_2(T2_DISABLED,0,1); // PWM will be derived from Timer2
setup_oscillator(OSC_8MHZ); |
Timer0 interrogation
Code: | output_high(FAN_ON); // turn on the fan
delay_ms(1000); // give some time for the fan to spin up
set_timer0(0); // zero the counter
delay_ms(1000); // allow time to accumulate counts
output_low(FAN_ON); // turn off the fan
if ( get_timer0() == 0 ) {
return FAN_STUCK; // the code gates here when fan is spinning and tachometer is pulsing (approx 120 - 130 Hz)
} |
No ISR for Timer0 .
Am I missing something?
Cheers,
- Nick
PIC18F4550
4.081 _________________ Read the label, before opening a can of worms. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Mon Jul 27, 2015 2:28 pm |
|
|
Nevermind. It was a hardware problem. Nothing wrong with my timer code.
You, folks, are always an inspiration. _________________ Read the label, before opening a can of worms. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Mon Jul 27, 2015 2:31 pm |
|
|
More to the point, I suspect your 'posting the question', made you look again. This has been mentioned recently. It's surprising how often it works!.
At least for you it did. |
|
|
|