Delay is required in most of our micro-controller applications, for example to blink a LED for certain duration or just to pause the micro-controller for short time. The avr-gcc compiler in Atmel Studio comes with delay.h library to make things easy for us, but do we know how it work. No, not until we do some digging inside of the library. In this post we will learn to generate short delay without using library, this will give some basic idea for how the _delay_ms() or _delay_us() works. In this tutorial a Logic Analyzer is used to observe the output of Atmega328 on pin PB5. Circuit configuration for Atmega328 is shown in diagram below. Circuit Configuration Atmega328 has three individual timer/counters identified as TC0, TC1, TC2. TC0 is an 8 bit general purpose timer/counter which can also be used for generating PWM waves, TC1 on other hand is 16 bit timer and can be used for generating PWM. Timer/Counter 2 (TC2) is 8 bit timer with support for PWM generat
In previous tutorial we learned how to interface a LED to Atmega328 and then wrote the code in Atmel Studio to make it go 'ON' and 'OFF' after every one second. In short we learned how to use our MCU's port pin as a simple digital output. In this tutorial we will be using a push button as an input to turn LED on for certain duration. Like last tutorial we will be using PORTB for our purpose. We will be using PB5(Pin 19) as output and PB1(Pin 15) as input. In this tutorial we will be using Current Sink method to interface LED with the mcu, whereas internal pullup method for interfacing the pushbutton. The following image shows the circuit we need to assemble. Schematic for Interfacing LED and Button What is Current Sinking? When the current flows from power supply to load and then to the Microcontroller's pin (or any other device) the configuration is called Current Sinking. In our circuit Power Supply is of 5V, LED is the Load and the