Skip to main content

Posts

Showing posts from May, 2019

Generating Delay Using Timer/Counter of Atmega328

     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