Hello Everyone,
I am now using Attiny10 and make following code with "TIM0_CAPT interrupt".
I hope to get variable change from "TIM0_CAPT interrupt" and enter "if(flgStart){}" but variable named "flgStart" might not be changed on interrupt part.
Is there any idea to improve this phenomena ?
I am looking for your reply.
/code/
#include <avr/io.h>
#include <avr/interrupt.h>
int flgTrig=1; //Flag for Capture Edge
int flgStart=1; //Flag from Interrupt
ISR(TIM0_CAPT_vect)
{
PORTB ^= (1<<0);
flgStart=1; //★flag is updated in this part
}
int main(void)
{
//Pin Assignment
//PB0 [O] toggled by TIM0_CAPT
//PB1 external PWM input
- //PB2 [O] toggled by while(1)*
- DDRB = (1<<2)| (0<<1)| (1<<0); //Data Direction (P76)*
- PUEB = (0<<2)| (1<<1)| (0<<0); //Pull-Up Enable Control (P74)*
- //Timer Interrupt*
- TCCR0B |= (0 << ICES0); //The rising edge (P103)*
- TIMSK0 |= (1 << ICIE0) ; //Enable Input Capture (P114)*
- sei(); //Enable Global interrupt*
- flgStart=0; //Init flag*
- while (1)*
- {*
- if(flgStart){ //★But cannot enter if part*
- PORTB ^= (1<<2);*
- flgStart=0; //Reset flag*
- }*
- }*
}