Advanced Search
Search Results
341 total results found
5. The Stack
The Stack is a memory section of the SRAM that follows First-In-First-Out (FIFO) principles. It is generally used to store temporary data for quick and easy access. The top of the stack is tracked by the 16 bit (adjusting to memory addressing) Stack Pointer th...
6. Printing Bytes as Hexadecimal Values
To easily debug and view numbers, we can create a subroutine that outputs numbers into serial. Since our architecture uses 8 bits, it is easier to print bytes as two hexadecimal values 0x00 - 0xFF by splitting the upper and lower nibbles. In this page, we will...
7. 𝔗𝔥𝔢 ℭ𝔬𝔡𝔢
#define __SFR_OFFSET 0x00 #include "avr/io.h" .global main main: RCALL SER_init LDI ZH, hi8(opening_msg) LDI ZL, lo8(opening_msg) RCALL SER_print ; 16 Bit Addition LDI ZH, hi8(addition_msg) LDI ZL, lo8(addition_msg) RCALL SER_print ...
8. References
“AVR ® Instruction Set Manual AVR ® Instruction Set Manual.” Available: https://ww1.microchip.com/downloads/en/DeviceDoc/AVR-InstructionSet-Manual-DS40002198.pdf “Lecture 02 – AVR Architecture,” Umbc.edu, 2025. https://eclipse.umbc.edu/robucci/cmpe311/Lectures...
New Page
Module 5 - Timer
1. Introduction to AVR Timers
1.1. Overview The ATmega328P is a widely popular 8-bit microcontroller, serving as the "brain" for many embedded systems, most notably the Arduino Uno. Among its most critical peripherals are the Timers. These components allow the microcontroller to perform ti...
2. Operating Modes
2.1. Normal Mode In Normal Mode, the timer acts as a simple up-counter. It starts from 0 and increments with every clock pulse (after passing through the prescaler) until it reaches its maximum value (0xFF for 8-bit, 0xFFFF for 16-bit. Once it hits the maximu...
3. Timer0
3.1. TCNT0 (Timer/Counter 0 Register) The TCNT0 register is the core component of the 8-bit TIMER0 module. It acts as the actual counter that holds the current timer value. The value of TCNT0 increments (or decrements in certain PWM modes) based on the select...
4. Timer1
4.1. TCNT1 (Timer/Counter Register) TCNT1 is functionally the same as TCNT0, serving as the core counter for its respective module, with several significant additions and architectural differences. TCNT1 is a 16-bit register divided into two 8-bit register, T...
5. Delay Using Timers
5.1. Delay Calculation in Normal Mode In Normal Mode, the timer always counts up to its maximum value and then overflows. To get a specific delay, you preload the TCNTn register with a starting value so it only has to count a specific number of steps before ov...
6. Der Code
6.1. Code Example 1 (Timer0) This code toggles PD5 every 0.5s. The delay_timer0 subroutine uses Timer0 in CTC Mode with a 1024 prescaler and a compare value of 156, creating a 10ms hardware delay per call. This subroutine is called 50 times using software loo...
Module 6 - Interrupt
1. Introduction to Interrupt
An interrupt is a mechanism used in microcontroller programming to pause the execution of the current program and call a specific routine or function when a particular event occurs. These events, defined by the programmer, can range from a specific condition o...
2. Interrupt Handler
On the ATMega328P microcontroller, there are three essential requirements that must met to enable an interrupt: Global Interrupt Enabled: Interrupts must be allowed to occur globally across any part of the program. While the Arduino environment typically enab...
3. External Interrupt Registers
For detailed information about the registers, please refer to the Atmega32p datasheet. here From the previous section, we have set up the interrupt handler for external interrupt 0. Now, we will set up the registers to setup/initialize this interrupt. Let's ...
4. Internal/Timer Interrupts
Internal Interrupts Now Internal interrupts or Timer interrupts is somewhat more complex then external interrupts. Before going for implementation let's understand on what use case we can use timer interrupts: Replacing Delay Loops: Instead of using blocking ...