Hi,
I have a 100Hz digital signal to a pin of my atmega168. I want to increment by one a variable when my PIN is high. However, it seems it doesn't works. is it too fast to be detected by my MCU?
This is my interrupt code:
volatile int32_t count; void setup() { PCMSK2 |= (1<<PCINT18); //The PCMSK2 register controls the //PCINT18 (PD2 pin) PCICR |= (1<<PCIE2); //Pin change interrupt 2 enabled PCIFR = (1<<PCIF2); //Pin change interrupt 2, flag enabled. sei(); } //Whenever there is a change in the pin status from low to //high, or vice versa... //Fires an interrupt! ISR(PCINT2_vect) { if(PIND & (1<<PD2)) { // PD2 is high count++; } else { // PD2 is low } }
while loop:
while(1) { if( count>=10) DDRB |= (1<<PB3); //Turns on a LED }