View Single Post
Old 01-29-2012, 07:44 PM   #6 (permalink)
MPaulHolmes
PaulH
 
MPaulHolmes's Avatar
 
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832

Michael's Electric Beetle - '71 Volkswagen Superbeetle 500000
Thanks: 1,368
Thanked 1,202 Times in 765 Posts
Code:
#define FOSC 16000000


// timer 1 input capture ISR (1000 hertz)
SIGNAL(SIG_INPUT_CAPTURE1)
{
	counter_1k++;		// 1 KHz counter
}


// Now, somewhere down in main()...

// set up input capture 1 interrupt at 1000Hz
	TCNT1 = 0;		        // load 16 bit counter 1
	ICR1 = (long)F_OSC / 1000;	// timer at 1000 Hz
	TCCR1A = 0;			// no output action on match
	// let counter 1 run at fosc, reset to 0 at ICR1
	TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
	TIMSK1 = (1 << ICIE1);		// enable input capture 1 interrupt
Just change FOSC to whatever frequency you are running at.
__________________
kits and boards

Last edited by MPaulHolmes; 01-29-2012 at 07:49 PM..
  Reply With Quote
The Following User Says Thank You to MPaulHolmes For This Useful Post:
Daox (01-30-2012)