Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Is the datasheet of the AVR ATmega32 wrong?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR
View previous topic :: View next topic  
Author Message
yumi

Bascom Member



Joined: 24 Nov 2016
Posts: 2

PostPosted: Fri Jan 20, 2017 9:27 am    Post subject: Is the datasheet of the AVR ATmega32 wrong? Reply with quote

I'm currently using an ATmega32 to keep time, so I carefully read the datasheet and configured the Timer 1 to generate an interrupt each second.

According to the following formula on the datasheet, using a 16 MHz clock, a prescaler of 256, and OCR1A = 31249, I should get a frequency of 1 Hz in CTC mode:

fOCnA=fclk_I/O2⋅N⋅(1+OCRnA)fOCnA=fclk_I/O2⋅N⋅(1+OCRnA)
This formula is available on page 99 of the ATmega32 datasheet.

I've configured Timer 1 as follows:
Code:
TCCR1A = 0;
TCCR1B = (1<<WGM12)|(1<<CS12);
OCR1A = 31249;
TIMSK = (1<<OCIE1A);


Here is the interrupt code
Code:
ISR(TIMER1_COMPA_vect){
    sec++;
}


Then, I use an LCD to continuously print the value of sec, and I get a timing of 0.5 seconds. In other words, for each second that passes, the timer generates two interrupts.

At first I thought maybe I got the fuses wrong, but that doesn't seem to be the case, as delays work just fine. Anyway, here's how I configured the fuses:

Code:
-U lfuse:w:0xff:m -U hfuse:w:0x99:m

I have absolutely no idea of what's going on, I've double checked everything, tried another ATmega32, tried another 16 MHz crystal oscillator, and I still get the same result.

Is the datasheet wrong, or am I missing something here?[/code]
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Jan 20, 2017 12:20 pm    Post subject: Google Reply with quote

Google is your friend.

http://www.avrfreaks.net/forum/overflow-interrupt-1hz
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum