delay AVR32

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

How to use delay_ms(); function with 32bit microcontrollers? Is there any difference or is it the same like with 8bit controllers. For example a simple code for LED Blink every second but with UC3C-EK?
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no such thing for AVR32. But really programmers don't use delay_ms() anyway (why would you pay for expensive silicon to have it sat idle for most of the time?). If you want to schedule activities in your code use a timer.

 

If you REALLY need a delay try something like:

void my_delay(uint32_t n) {
    volatile uint32_t m;
    for (m = 0; m < (n * 100000); m++);
}

You will need to call this a few times in a loop and time it with a stop watch. Adjust 100000 until the delay here is some "useful" amount like 1 millisecond, 10 milliseconds, 100 milliseconds or whatever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Basically i need to read and send data from temperature sensor every 1h, so i am not sure if i can do that without delay_s and while()

 

Thank you for the answer

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But if it's once an hour surely you put the CPU to sleep and arrange for an infrequent alarm to wake it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thats a very good idea Sir!

Thanks
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is also a delay API in ASF which makes use of the cycle counter. 

 

http://asf.atmel.com/docs/3.33.0...

 

-------------------------------------------------------------------------------------------

 

But as sugested by clawson, I would not have my MCU sitting idle, it either has to go to sleep or do someting else. I would suggest that you create a state machine along with a timer to monitor tasks.