Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timer/Counter1 problems on Atmega1280

Status
Not open for further replies.

ady689

Newbie level 4
Joined
Jul 27, 2008
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,327
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
 

using timers in atmega1280

Hi,
Just to clarify, won't the clock divider affect the timing?

Regards,
Laktronics
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top