Mega 4808 sleep modes

In most every project your microcontroller does not run all the time. You also don´t want to waste battery capacity, so you should set your microcontroller into a sleep mode.

In a sleep mode the microcontroller shut down some components to save energy. The Mega 4808 has two interesting sleep modes. One of it is the power down mode. In this mode you can wake up from an external interrupt source via a GPIO.

In the following picture you can see a very simple code which sets the Mega 4808 in power down mode. With this code you Mega 4808 sleeps for ever.

Now we add also an external interrupt on pin PF0. If this pin change its state from high to low or from low to high it goes in the subroutine subr(). In the interrupt routine we change the logic state of the variable state. If state is low we set it in the interrupt routine to high and if state is high we set it to low. This state variable is the logic voltage on pin PA2.

So every time the Mega 4808 wakes up from an pinchange interrupt on PF0 it goes in the subroutine subr() and changes the pinstate of pin PA2.

On the pins you can see the function of the code.

You can also use the standby mode instead of the power down mode. In the standby mode you can also use the internal RTC timer. With the RTC timer you can wake up you controller after a programmable time without a external interrupt. For this i use the RocketScream LowPowerAVRZero and the RocketScream_RTCAVRZero library which is available on github.

In the following picture is a code which wakes up every 5 seconds. If the Mega 4808 wakes up from standby it goes in the subroutine subr() and toggle the pin PA2. After this he goes into standby mode.

On the pin PA2 you can see the function of the code.

Tipps:

  • You can only wake up from an high, low or change interrupt in sleep mode.


Other posts about Mega 4808:

Mega 4808 and Optiboot bootloader

The Mega 4808 can normally programmed over UPDI. The UPDI Interface is great, you need only one data wire and ground, but in some cases you wanna program the microcontroller at your board and you don´…

Mega 4808 sleep modes

In most every project your microcontroller does not run all the time. You also don´t want to waste battery capacity, so you should set your microcontroller into a sleep mode.

Mega 4808 Arduino and Serial (UART)

You wanna use the Arduino serial (UART) with a Mega 4808 board? No, problem. The Mega 4808 has three serial (UART) interfaces. Here you can read on which pins you can use the serial (UART) interface a…

Arduino Mega 4808 minimal board

For testing your code for the Mega 4808 with Arduino you need a board where every pin is accesable.

DIY UPDI Programmer for Mega 4808

You wanna programm the Mega 4808 or an other megaAVR 0-series microcontroler? Then you need a UPDI programmer. You can buy the Atmel ICE for ~100$ or you can make your own UPDI Programmer.

Mega 4808 Arduino pin usage / pinout

You wanna use the Mega 4808 with MegaCoreX and Arduino? Then you need the standard pin usage / pinout for it.

Getting started with Arduino and Mega 4808

You wanna get started with the Mega 4808 in Arduino and you do not now how? Here is your answer.

Leave a Reply

Your email address will not be published. Required fields are marked *