1
votes

I am trying to make a countdown timer using an ATmega32 clocked at 8 MHz.

I want to use the ATmega timer to start a countdown for 8 minutes when the switch is pressed and the output should turn on for 8 minutes and when the countdown hits zero the output should turn off and the countdown returning back to zero. (All this I want to show on a 16*2 LCD). I know that I have to use a timer for that, but I am really not sure on how to do it. Any suggestions?

Is creating this much long delay from an AVR timer possible or not?

1
ATmega32 - what board is it sitting in? Your own? - Peter Mortensen
This can't be that uncommon. What did you find in your Internet search? There must be something similar out there. For instance, at Instructables. Please add the documentation for the research to your question (by editing your question), not here in comments. - Peter Mortensen
For the length, using a timer alone (software can always be used to count overflows, thus enabling arbitrary length of time), take the clock frequency, and find the highest prescaler and highest-bit timer in the datasheet. For example, ATmega328 at 16 MHz (Arduino Uno, the single 16-bit timer (Timer1) and the highest prescaler 1:256): 1 / 16,000,000 s * 256 * 65536 = 1.04 seconds. A 32-bit timer would extend that to about 19 hours. - Peter Mortensen
This is Stack Overflow, not a forum. It also operates on a time scale of minutes, not hours or days. You are expected to respond promptly. - Peter Mortensen
I am really sorry for that I am still a stranger to the site's way of operation and I am really sorry for that please forgive me this time I will take care next time. - user9728254

1 Answers

0
votes

Please don't be angry with me(I don't want to disrespect you people by answering my own question).I had tried to solve my problem myself and I had achieved this, this code works thanks for your valuable time to answer my questions. I have posted the code so that new people can benefit from it. Thanks for your time.

volatile uint16_t second_count = 0;

void init_timer1(void);

void init_timer1()
{
    TCCR1B |= (1<<WGM12);//CTC mode
    TCNT1 = 0;//initializing timer
    OCR1A = 31249;//preloading timer so that it can count with 1 sec 
    TIMSK |= (1<<OCIE1A);//Timer compare A Match interrupt
    TCCR1B |= (1<<CS12);//Starting timer and clock prescaler(256)
}

ISR(TIMER1_COMPA_vect)
{
    second_count++;
    if(second_count == 180)//turing the output on for 180 seconds on power on
    {
        PORTD |= (1<<PD6);
    }   
    else
    {
        PORTD &= ~(1<<PD6);
        second_count = 0;
    }

}
int main(void)
{
    init_timer1();
    sei();
    DDRD = 0xff;
    PORTD = 0x00;
    DDRB = 0x00;
    PORTB = 0xff;
    while(1)
    {

    }
}