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

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

[avr-gcc-list] Trouble with division


From: Ulrich Schweitzer
Subject: [avr-gcc-list] Trouble with division
Date: Sat, 14 Jun 2003 15:06:28 +0200
User-agent: KMail/1.4.1

Hello Everybody!

I've just started playing around with AVR microcontrollers, so I'm a 
complete newbie. Now I've run into a problem that I don't understand:

Please take a look at the following code:

volatile uint16_t full_count;

int main(void)
{
   init();
   sei();   
   
   for ( ;; );      
      
   return(0);
}

INTERRUPT(SIG_OVERFLOW0)
{
   uint16_t grain;
   
   full_count= 12345;
   grain= full_count / 33;
//   grain= 123;
   
   PORTD= (uint8_t)grain;

   pos_count++;
}

I tried this on an ATMega8, Counter0 is running, the interrupt is enabled 
(I just left out the init() function to prevent the mail from getting to 
long) and there are LEDs on PORTD.
The problem is: The divsion seems to ge wrong when I divide by any number 
that is not a power of 2 (as in the above example). If I change the 33 to 
32 or any other power of 2, the result is just like expected.
Not only does the division go wrong when the divisor isn't a power of 2, 
but the whole interrupt routine seems to break off. I know this because 
even with the line 'grain= 123;' commented in, none of the LEDs light up. 
The MCU doesn't crash however. Any code in the for-loop in main is 
executed even if the interrupt doesn't work.

AVR MCUs are able to divide INTs, aren't they?

Ulrich
-- 
PGP key ID: 0xDF6FC4FA



reply via email to

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