ady689
Newbie level 4
atmega1280 board
Hi, im using an atmega1280 with a 28.224Mhz crystal.
I'm tring to initialize timer/counter 1 to ghet an interupt at 1ms.
I display the counter on a lcd screen and is visible that the counter doesnt incrent at 1ms, and is increment on lower rate maybe 100ms.I dont know what is the problem, can you help me ?thx
What this is basically doing is putting timer 1 in CTC (Clear-on-Terminal-Count) mode, making the clock divisor 64, and telling it to interrupt when it counts up to 441. The MCU clock is 28224000Hz. Divide that by 441 (count 0-440) and i get 1000Hz, or the 1mS interrupt.but dont work.....
void TIMER1_Init(uint16_t y)
{
cli();
TCNT1H=0x00;
TCNT1L=0x00;
uint16_t hiByte, lowByte;
hiByte = y>>8;
lowByte = (uint32_t)y;////y=441;
PRR0 |=(0<<PRTIM1);
TCCR1A |= (0<<WGM10 | 0<<WGM11 | 0<<COM1A1 | 0<<COM1A0);
TCCR1B |= (1<<CS10 | 1<<CS11 | 0<<CS12 | 1<<WGM12 | 0<<WGM13);//prescaler 64
OCR1AL=lowByte;
OCR1AH=hiByte;
TIMSK1 |=(1<<OCIE1A);
TCCR1C |=(1<<FOC1A);
TIFR1 |=(1<<OCF1A);
sei();
}
ISR(TIMER1_COMPA_vect)
{
t.timer++;
itoa(t.timer,ms,10);
LCD_String(ms, FONT8x16,120,150,Red,Blue);
}
I verifi the clock speed, the avr is set on the external crystal, i tri my board with 16mhz, 4 mhz 28mhz cristal and with the 28mhz i get a big refresh rate on my lcd
Hi, im using an atmega1280 with a 28.224Mhz crystal.
I'm tring to initialize timer/counter 1 to ghet an interupt at 1ms.
I display the counter on a lcd screen and is visible that the counter doesnt incrent at 1ms, and is increment on lower rate maybe 100ms.I dont know what is the problem, can you help me ?thx
What this is basically doing is putting timer 1 in CTC (Clear-on-Terminal-Count) mode, making the clock divisor 64, and telling it to interrupt when it counts up to 441. The MCU clock is 28224000Hz. Divide that by 441 (count 0-440) and i get 1000Hz, or the 1mS interrupt.but dont work.....
void TIMER1_Init(uint16_t y)
{
cli();
TCNT1H=0x00;
TCNT1L=0x00;
uint16_t hiByte, lowByte;
hiByte = y>>8;
lowByte = (uint32_t)y;////y=441;
PRR0 |=(0<<PRTIM1);
TCCR1A |= (0<<WGM10 | 0<<WGM11 | 0<<COM1A1 | 0<<COM1A0);
TCCR1B |= (1<<CS10 | 1<<CS11 | 0<<CS12 | 1<<WGM12 | 0<<WGM13);//prescaler 64
OCR1AL=lowByte;
OCR1AH=hiByte;
TIMSK1 |=(1<<OCIE1A);
TCCR1C |=(1<<FOC1A);
TIFR1 |=(1<<OCF1A);
sei();
}
ISR(TIMER1_COMPA_vect)
{
t.timer++;
itoa(t.timer,ms,10);
LCD_String(ms, FONT8x16,120,150,Red,Blue);
}
I verifi the clock speed, the avr is set on the external crystal, i tri my board with 16mhz, 4 mhz 28mhz cristal and with the 28mhz i get a big refresh rate on my lcd