This tutorial give you the details of synchronous serial communication, which is the basis of data transfer in communication standards like SPI and I2C. The tutorial is aimed for a beginner who has no experience or any idea of serial communication. So intermediate user who already has some idea about serial data transfer can skip this tutorial and jump directly to SPI or I2C tutorials. Data Transfer. Knowledge of data transfer is very important for any embedded system developer. In any embed ed system data is moved between several units like between RAM and CPU. There are many methods and technique for data transfer each having its own pros and cons. So different data transfer technique is used in different situations. Some example of data transfer are Simple parallel transfer. (Used to transfer 8,16,32 … bits of data in the same time) Asynchronous Serial Transfer (USART) – Old but still in use mode of serial communication using only 2 lines (+1 additional line for GND). SPI – Serial Peripheral Interface – Standard Mode of communication between different ICs. Many ICs designed for a Variety of Jobs like Flash Memory, LCD controller, Ethernet Controllers etc uses this standard for communication. So if you want to use any of these functionality you need to have a knowledge of SPI. IIC(or I2C) – […]
In this tutorial we will set up the TIMER0 in fast pwm mode and use it to generate PWM signals of varying duty cycles. In this way we would be generating analog signals of voltages between 0 and 5v. In the example we will connect this output to a LED and see how it varies its brightness. Please see the previous tutorials on PWM and TIMERs before reading this tutorial. PWM Introduction to PWM – Pulse Width Modulation PWM Signal Generation with AVR Timers. Timers Introduction To AVR Timers. Timers In Compare Mode Part I Timers In Compare Mode Part II Setting Up TIMER0 in Fast PWM mode Setting up the TIMER0 in fast pwm mode is very easy and just require one line of code. You only need to deal with one register named TCCR0 (Timer Counter Control Register For Timer 0). You just need to set up various bits in it to get the required setting. The various bits of TCCR0 is given below. TCCR0 This register is used for configuring the TIMER0. See Timer Tutorial for more info. The explanation of various bits of this register is as follows. Bit No 7 6 5 4 3 2 1 0 Name FOC0 WGM00 COM01 COM00 WGM01 CS02 CS01 CS00 Initial Val 0 0 1 0 0 0 0 […]
In the last tutorial you saw how the PWM technique helps us generate analog signals from a microcontroller. In this tutorial we will see how PWM generation is implemented with microcontrollers. Before you begin please see Introduction to PWM Introduction to AVR Timers Generation of PWM signals is such a common need that all modern microcontrollers like AVR has dedicated hardware for that. The dedicated hardware eliminates the load of generation of PWM signal from software (thus frees the CPU ). Its like asking the hardware to generate a PWM signal of a specific duty cycle and the task of CPU is over. The PWM hardware with start delivering the required signal from one of its PINs while the CPU can continue with other tasks. In AVR microcontrolers PWM signals are generated by the TIMER units. (See AVR Timer Tutorials) . In this tutorial I will give you the basic idea of how PWM signals are generated by AVR timers. Their are two methods by which you can generate PWM from AVR TIMER0 (for ATmega16 and ATmega32 MCUs). Fast PWM Phase Correct PWM Don’t worry from their names they will become clear to you as we go on. First we will be considering the Fast PWM mode. PWM Generation Fundas We will use the simplest timer, TIMER0 for PWM generation.(Note […]
A digital device like a microcontroller can easily work with inputs and outputs that has only two state, on and off. So you can easily use it to control a LED’s state i.e. on or off. In the same way you can use it to control any electrical device on/off by using proper drivers (transistor,triac, relays etc). But sometimes you need more than just "on" & "off " control over the device. Like if you wanna control the brightness of a LED (or any lamp) or the speed of DC motor then digital (on/off) signals simply can’t do it. This situation is very smartly handled by a technique called PWM or Pulse Width Modulation. PWM is the technique used to generate analogue signals from a digital device like a MCU. Almost all modern MCUs have dedicated hardware for PWM signal generation. In this tutorial we will learn the basics of PWM technique and later on we will see how to implement PWM generation with AVR microcontrollers. PWM : Pulse Width Modulation A digital device, like a microcontroller can only generate two levels on its output lines, HIGH=5v and LOW=0V. But what if we want to generate 2.5v or 3.1v or any voltage between 0-5 volt output ? For these kinds of requirement, instead of generating a constant DC voltage output […]
Till now we have seen the basics of RS232 communication, the function of level converter and the internal USART of AVR micro. After understanding the USART of AVR we have also written a easy to use function to initialize the USART. That was the first step to use RS232. Now we will see how we can actually send/receive data via rs232. As this tutorial is intended for those who are never used USART we will keep the things simple so as to just concentrate on the "USART" part. Of course after you are comfortable with usart you can make it more usable my using interrupt driven mechanism rather than "polling" the usart. So lets get started! In this section we will make two functions :- USARTReadChar() : To read the data (char) from the USART buffer. USARTWriteChar(): To write a given data (char) to the USART. This two functions will demonstrate the use of USART in the most basic and simplest way. After that you can easily write functions that can write strings to USART. Reading From The USART : USARTReadChar() Function. This function will help you read data from the USART. For example if you use your PC to send data to your micro the data is automatically received by the USART of AVR and put in a buffer […]
Merry Christmas !!!
Welcome to the third part of my RS232 serial communication tutorial. Till now we saw the basics of RS232 communication and made our level converter. Now its time to understand the USART of AVR microcontroller and write the code to initialize the USART and use it to send and receive data. Like many microcontrollers AVR also has a dedicated hardware for serial communication this part is called the USART – Universal Synchronous Asynchronous Receiver Transmitter. This special hardware make your life as programmer easier. You just have to supply the data you need to transmit and it will do the rest. As you saw serial communication occurs at standard speeds of 9600,19200 bps etc and this speeds are slow compared to the AVR CPUs speed. The advantage of hardware USART is that you just need to write the data to one of the registers of USART and your done, you are free to do other things while USART is transmitting the byte. Also the USART automatically senses the start of transmission of RX line and then inputs the whole byte and when it has the byte it informs you(CPU) to read that data from one of its registers. The USART of AVR is very versatile and can be setup for various different mode as required by your application. In this […]
Hello and welcome back. Continuing our discussion on RS232 serial communication in this part we will make a RS232 level converter. In the last tutorial we saw that how RS232 level signals differs from normal logic signals. So to interface RS232 level signals to our MCUs we need a "Level converter". And in this tutorial we will make one. What a level converter will do is to convert RS232 level signals (HIGH=-12V LOW=+12V) from PC to TTL level signal (HIGH=+5V LOW=0V) to be fed to MCU and also the opposite. Fig – Working of RS232 level converter As RS232 is such a common protocol there is a dedicated IC designed for this purpose of "Level Conversion". This IC is MAX232 from Maxim. By using charge pumps it generates high voltages(12V) and negative voltages(-12V). Now lets make it! Things you need S.No Item Value Qty 1 MAX232 IC 1 2 Capacitors 1uF 4 3 10uF 1 4 DB9 Female Connector 1 5 General Purpose PCB 1 6 Some Wires – - Fig – Stuffs required for RS232 level converter. Now having all the stuffs in our working table lets begin. The Schematic Fig – Schematic for RS232 level converter. Assembly Assemble the circuit according to the schematic on a small piece of general […]
RS232 is a asynchronous serial communication protocol widely used in computers and digital systems. It is called asynchronous because there is no separate synchronizing clock signal as there are in other serial protocols like SPI and I2C. The protocol is such that it automatically synchronize itself. We can use RS232 to easily create a data link between our MCU based projects and standard PC. Excellent example is a commercial Serial PC mouse (not popular these days, I had got one with my old PC which I bought in year 2000 in those days these were famous). You can make a data loggers that reads analog value(such as temperatures or light using proper sensors) using the ADC and send them to PC where a special program written by you shows the data using nice graphs and charts etc.. actually your imagination is the limit! Basics of Serial Communication. In serial communication the whole data unit, say a byte is transmitted one bit at a time. While in parallel transmission the whole data unit, say a byte (8bits) are transmitted at once. Obviously serial transmission requires a single wire while parallel transfer requires as many wires as there are in our data unit. So parallel transfer is used to transfer data within short range (e.g. inside the computer between graphic card and […]
Hello Friends, Welcome back. In previous tutorial I introduced my IR remote decoding library. In this tutorial I will continue our discussion and show you how to add IR remote controls support to your AVR projects. Step I Download the library files and unzip them in a folder. Step II In AVR studio create a new AVR-GCC project. Then copy the following files to the project folder. IR remote related. Source Files remote.c Header Files remote.h rckeys.h LCD Related Source Files lcd.c Header Files lcd.h myutils.h Note: Include file from the \lib\ATmega8 if you are using ATmega8 \lib\ATmega16 if you are using ATmega16 or ATmega32 After The files have been copied add them to your project by right clicking project view and selecting “Add Existing Source File(s)…” and then select the “lcd.c”. Similarly add other source files. In the same way add the header files by selecting "Add Existing Header File(s)…" Adding files to projects. If instead of AVR Studio you use Makefiles then add all the source files names in the source section of the makefile along with your main c file (which has same name as your project and has the main function). Step III. In your main C source file include the following files #include "remote.h" in addition to standard files in your main() function initialize […]
Hi Friends, Welcome to my AVR tutorial Series. In this article I will describe my Infrared Remote Control Library. Hope you will enjoy it. I was very much amazed my remote controls since long. The simple circuits described in magazine were just operated like a switch and can only switch on and off an application. That means only single channel. That was of not much use. What I wanted was access to each key on remote control. I wished I could decode the signals generated by common remotes controls found in our homes. This way I could make multi channel remote controls for any project. So I went on and after some web research, coding and debugging I finally succeeded ! Actually I completed that more than one and half year ago (in may 2007). And now I thought I should also make it available to others who are in need of it so that they can use it in their projects. So I went on to make it more "clean" and also to make it more "easily portable" so that it can be used with different devices operating at different frequency. And now the result is here, a very easy to use library that can add remote control feature in any of your AVR project ! Using a IR […]
Here are some Videos that demonstrate the xBoard – a easy to use but powerful development system for Atmel AVR ATmega32 microcontrollers. For complete information about the xBoard™ see http://xBoard.eXtremeElectronics.co.in Video #1 xBoard™ :: AVR Dev-Board – Introduction This video tutorial gives you a quick introduction of the xBoard; easy-to-use and powerful Atmel AVR AtMega32 Microcontroller Development Board. Video #2 xBoard™ :: AVR Dev-Board – Hello World In this tutorial we will introduce you to the basic steps needed set-up and develop programs for the xBoard. We’ll write a LED blinking project which is a Hello World project for microcontroller arena. xBoard – a easy-to-use and powerful Atmel AVR AtMega32 Microcontroller Development Board. Video #3 xBoard™ :: AVR Dev-Board – LCD Interfacing This video tutorial teaches you how you can interface a standard 16×2 LCD Module with the xBoard – easy-to-use and powerful Atmel AVR AtMega32 Microcontroller Development Board. Video #4 xBoard™ :: AVR Dev-Board – IR-Remote This video tutorial shows you how to interface a DVD Player Infrared Remote Control with the xBoard, a easy-to-use and powerful Atmel AVR AtMega32 Microcontroller Development Board.