avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Mega32 wierdness


From: Trampas
Subject: RE: [avr-gcc-list] Mega32 wierdness
Date: Sun, 23 Jan 2005 08:56:22 -0500

Jonny,

I can not see anything wrong with your code, why don't you post the listing?


Also you want to be careful when changing variables that are used in
interrupt routines. That is you need to make sure that the changes to the
variables happen in one cycle, which should be the case for your code.
However if you changed the timer_step to a 16bit value, you would need to
disable the interrupt before reading/changing timer_step in your main line
code. 


Regards,
Trampas 
 

-----Original Message-----
From: address@hidden [mailto:address@hidden
On Behalf Of Jonny Dyer
Sent: Sunday, January 23, 2005 4:39 AM
To: address@hidden
Subject: [avr-gcc-list] Mega32 wierdness

I am trying to get started working with GCC for AVR and am having a 
terrible time with a Mega32.  Note that I am experience with AVR 
assembly and the aTinys, but this is my first C AVR project.

As a simple test program, I have Timer0 interrupt enabled and am 
running Timer0 at clk/1024.  On overflow, I am toggling all the pins on 
Port D. If I do just this and nothing else, the program works fine.  
However, I wanted to add a counter to the overflow function so that I 
can divide the timer overflows further and only toggle the LED, say, 
every 5 overflows. If I define my counter variable as volatile (as I 
have read is necessary when working with interrupts several other 
places), increment it in the interrupt function and leave the PORTD 
toggling in that function, it still operates the same (as it should):

SIGNAL(SIG_OVERFLOW0)
{
        timer_step++;
        PORTD ^= 0xff;
}

However, if I do anything to timer_step in the rest of the code (namely 
in main()), it's as if the timer overflow stops being called and the 
pins on PORTD no longer flash.  Note that I am doing nothing at all to 
my interrupt routine:

volatile uint8_t timer_step;

int main (void)
{
        uint8_t save;
        timer_step = 0;
        DDRD = 0xFF;
        PORTD = 0x00;
        
        TIFR  = BV(TOIE0);
        TCCR0  = BV(CS02) | BV(CS00); /* CTC, prescale = 128 */
        TCNT0  = 0;
        TIMSK = BV(TOIE0);    /* enable Timer0 overflow interrupt*/
        sei();
        
        for(;;)
        {
                if(timer_step > 10)
                {
                        timer_step = 0;
                }
        }
}

SIGNAL(SIG_OVERFLOW0)
{
        timer_step++;
        PORTD ^= 0xff;
}

I have disassembled the code and I can see nothing wrong with the code 
GCC is generating either.  It is almost as if somehow messing with 
timer_step (which gcc is saving at r0) outside of the interrupt 
function corrupts TIMSK or TIFR or the interrupt vector.  Any help is 
greatly appreciated.

Thanks
Jonny
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list




reply via email to

[Prev in Thread] Current Thread [Next in Thread]