Skip to main content

Posts

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
Recent posts

Interface Push Button To Atmega328 with Input Pullup

     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

Creating The First Project in AS7 and Blinking a LED

     Assuming that you have followed the previous tutorials and set up environment for AVR development using Atmel Studio, let us now see how to create a new project in Atmel Studio 7 (AS7). Please take note that while Installing Atmel Studio it will ask permission for installing packages for 8/32bit AVR micro-controllers as well as ARM series, make sure you select the packages for 8/32bit avr micro-controllers.  Step 1      After starting the AS7, you will see the welcome screen in which you can see lots of tools in toolbar and 'Start Page' in tab section. Under that tab look for 'Start' under which lie the 3 options New Project, Open Project and New Example Project. Click on 'New Project' or you can go in file menu and select project under new sub-menu. Atmel Studio 7 home screen  Step 2      Once you choose to create a new project in Atmel Studio, a dialog box will pop up to ask what programming language you want to choose. Select 'GCC C E

Atmega328/P: Basic Circuit and Configuring Fuse Bits

     Now that you have probably installed the driver for USBasp , it's time that we move on to mount the basic circuit for Atmega328 and get it running on the breadboard. You can get a new Atmega328/P micro-controller or just scavenge one from an Arduino UNO lying around. Before we mount the circuit on breadboard here's the of components that are required. Atmega328/P (28 PIN DIP package) 22pf Ceramic Capacitors Qty 2 nos. 16MHz crystal Qty 1 nos. [have 2-3 in spare just in case the one in use is damaged] Tactile Switch/Push Button Qty 1 nos. Resistor 10K Ohm Qty 1 nos. LED 1 nos. Breadboard Connecting Wires       The schematic below shows how to configure Atmega328/P on breadboard. I have posted a hand drawn schematic as well as an eagle schematic. Before you mount the circuit lets understand functions of pin that we are using to make a basic circuit of Atmega328/P. Configuring Atmega328/P [Click to Open) Pin 1 [PC6(RESET/PCI14)]: Pin 1 of Atmega328/p is

USBasp: Driver Installation

     USBasp is an in-circuit programmer for Atmel micro-controllers. It is a nice option if you're just starting with micro-controllers, especially those from Atmel and aren't willing to spend much on a programmer. USBasp uses in-circuit programming interface for uploading your compiled code to the micro-controller.      Before we can use the USBasp we need to make sure that we install the drivers correctly. If you are a Linux or Mac OS user, there's no need to install any driver as your machine will automatically detect the USBasp. So driver installation comes for Windows user like me. It is easy to install the drivers for USBasp, all you need to do are just carry out few steps that I will be telling. Step 1      Download the Zadig application from here . Zadig is an application that has a set of some generic usb drivers and one of them is for USBasp. Now plug in USBasp before running the application. Step 2      Once you have started the Zadig application, che