Go Down

Topic: Arduino Micro Frequency (Read 188 times) previous topic - next topic

Dude85

Hello community,

i bought a brandnew Arduino micro and i tried to run my own project on it.

In order to run a very time-critical application on it i don't wanna use the arduino libs. Instead, i wanna run my own avr C-program.

My first was to checkout the cpu frequency is correct, which means that the frequency is 16 Mhz.

However, when i run i simple led blink main, which is:

#define LIMIT 500000

uint32_t loopCount;
uint8_t state = 0;

int main() {
   loopCount = 0;

   DDRC |= (1 << DDC7);
   while(1) {
      if(loopCount == LIMIT) {

         loopCount = 0;
         state = (state) ? 0 : 1;
         if(state)
            PORTC |= (1 << PC7);
         else
            PORTC &= ~(1 << PC7);
      }

      loopCount++;
   }
}

my led blinks with a period time of around 1 seconds. This is not what i expected.
It should be "LIMIT 16000000" to get a blink frequency of one second.

johnwasser


my led blinks with a period time of around 1 seconds. This is not what i expected.
It should be "LIMIT 16000000" to get a blink frequency of one second.


How many instruction cycles does your loop take?   If you do half a million loops in one second it is doing about 32 instruction cycles per loop.  For a 32-bit comparison , a 32-bit increment, and a jump that doesn't sound too bad.  If you change your loop counter to 16 million you should end up with a 32-second loop.

If you don't want to use the Arduino IDE or libraries you might be better off at the AVRfreaks forum: www.avrfreaks.net
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up