Skip to content

AVR Programming Playground (Using AVR-GCC & Makefile)

License

Notifications You must be signed in to change notification settings

m3y54m/avr-playground

Repository files navigation

AVR Programming Playground

This is my playground for AVR programming where I rewrite my old AVR programs and practice bare-metal embedded programming skills. It could be beneficial for you as well.

To prepare your build environment first read this tutorial:

All of the programs in this repository are written for Atmega328 on Arduino Uno / Nano but without using Arduino Core and just in bare-metal. I used the Arduino bootloader on Atmega328 and AVRDUDE to write my programs on Atmega328. So there is no need for any external programmer.

Arduino-uno-pinout

Atmega328P Pinout

Note that Atmega328 is an old device and NOT RECOMMENDED FOR NEW DESIGNS. I am using it only to practice programming.

Almost all projects are configured for 16MHz external crystal on Arduino board. You can see each project's configuration in src/my/project_config.h

Blinky is the "Hello World!" of embedded systems :)

Redirect STDIO streams to UART0 input and output so that you can write to serial port using printf() and read using scanf()

Note 1: The implementation of printf() and scanf() is about 5KB in size, which is a problem for memory constrained systems.

Note 2: that if you are using Arduino Uno / Nano board, you do not need any external serial port to communicate with Atmega328, you can use the Arduino USB serial port to test the program. Just connect your board using USB port to your PC.

Implement precise timing functions millis(), micros(), precise_delay_ms(), precise_delay_us()

Test HY-SRF05 ultrasonic sensor using my precise_timing library.

image

image

Test a 20PPR incremental (quadrature) rotary encoder. A quadrature encoder gives 4x resolution using this method. External interrupts (INT0 and INT1) are used for decoding the encoder signals.

image

Emulate a 20PPR incremental (quadrature) rotary encoder using TIMER0 and TIMER2 outputs and decode the generated signals. Decoded speed should be 91 RPM (122 pulses per second).

Use ADC to measure VCC voltage without using any I/O pin or any external component.

Capacitance meter for 470uF to 18pF range with the highest accuracy for small capacitors.

Low power control of an LED using a button. Exits Sleep on button press, turns on an LED and goes back to Sleep. On button release, exits Sleep, turns off the LED and goes back to Sleep.

Testing software reset using watchdog timer. Configured watchdog timer for a timeout of 4 seconds. Reset the watchdog timer 5 times when it reaches 3.9 seconds to avoid triggering a MCU reset. Eventually, triggered the MCU reset by allowing the watchdog timer to reach its timeout.

Determining the reset source (cause) of the MCU during startup.

Resources

About

AVR Programming Playground (Using AVR-GCC & Makefile)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published