Input Capture Mode ATmega32
subratasarkar20
c_cpp
a year ago
665 B
13
Indexable
/*
* InputCaptureMode.cpp
*
* Created: 27-09-2024 11:33:52
* Author : subrs
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint16_t pulse_time = 0;
int main ()
{
DDRD &= ~(1 << PD6); // Set the ICP1 pin to input mode
DDRB |= (1<<PINB0); // Set PB0 as output to reflect the input from
TCCR1A = 0;
TCCR1B |= (1 << ICES1) | (1 << CS10); // Rising edge, no prescaler
TIMSK |= (1 << TICIE1); // Enable input capture interrupt
sei();
while (1);
{
}
}
ISR(TIMER1_CAPT_vect)
{
pulse_time = ICR1; // Read the ICR1 value (the time of the captured event)
PORTB ^= (1 << PINB0);
}
Editor is loading...
Leave a Comment