#include<avr/io.h>
#include<avr/interrupt.h>
volatile unsigned char count=0;
volatile unsigned char timer_flag=0;
volatile unsigned char job=0;
volatile unsigned char job1=0;
volatile unsigned long High_table[18]={1389,1599,1799,1999,2199,2400,2599,2796,3002,3199,3401,3596,3802,3999,4201,4394,4596};
volatile unsigned long Low_table[18]={38599,38399,37999,37799,37599,37399,37199,36999,36799,36599,36399,36199,35999,35799,355599,35399};
volatile unsigned char temp=0;
volatile unsigned char temp2=0;
volatile unsigned char val=0;
void init_timer1()
{
TCCR1B=0x0A;
OCR1A=39999;
TIMSK |= (1<<OCIE1A);
}
void init_timer2()
{
TCCR3B=0x0A;
OCR3A=39999;
ETIMSK |= (1 << OCIE3A);
}
int main(void)
{
cli();
DDRG=0xff;
DDRA=0xff;
DDRE = 0xFE;
ADMUX = (0<<REFS1) | (1<<REFS0) | (1<<ADLAR);
ADCSRA = (1<<ADEN) | (1<<ADPS2) ;
init_timer1();
init_timer2();
sei();
while(1)
{
ADCSRA |= 0x40;
while((ADCSRA & 0x10) == 0);
temp=ADCL;
temp=ADCH;
}
return 0;
}
ISR(TIMER1_COMPA_vect)
{
OCR1A=39999;
ADMUX= (ADMUX & 0xF8) + 0x00;
if(temp==255)
{
if(job)
{
job=0;
OCR1A=High_table[0];
PORTG=0xff;
}
else
{
job=1;
OCR1A=Low_table[0];
PORTG=0x00;
}
}
}
ISR(TIMER3_COMPA_vect)
{
OCR1B=39999;
ADMUX= (ADMUX & 0xF8) + 0x01;
if(temp==0)
{
if(job1)
{
job1=0;
OCR3A=High_table[1];
PORTA=0xff;
}
else
{
job1=1;
OCR3A=Low_table[1];
PORTA=0x00;
}
}
}
제가 짠 프로그램인데 조이스틱을 이용해서 들어오는 adc 값 가지고 펄스를 내보내려고 합니다.
근데 ISR(TIMER1_COMPA_vect) 하나만 인터럽트 할때는 정상적으로 되는데 ISR(TIMER3_COMPA_vect)
까지 같이 하려니까 인터럽트는 걸리는데 나오는 펄스가 제대로 되질 않네여;; 조언 부탁드립니다