A bit different way of generating long delays with AVR

There are many ways of generating delays in AVR or any other microcontroler. One way is to use software counter like delays withing loops. This is not recommended way and should be avoided because this utilizes processor and is hardly predictable due to compiler optimizations. But to get high precision you definitely need to use timer counter. This way you are free from compiler optimizations. Single timer can deal with rather short delays. If you need longer delays generated by hardware only, why not to put another timer to work. ATMEL app note suggests using two timers for generating long delays. The method is pretty obvious from illustration – first timer generates timer1 compare signal on dedicated pin (OC1A), This signal then ticks second timer0. Now imagine if first timer… Continue reading

Using Volatile keyword in embedded code

Volatile is probably the least documented keyword in most tutorials and books. This is the primary cause of most misuses and bugs related to it. If you already are programming microcontrollers, you probably know that volatile is always used on global variables that are accessed from interrupt service routines. Otherwise code won’t work. After few requests I decided to drop few lines about volatile keyword. This keyword is commonly used to tag memory type. We hear “volatile memory”, “non-volatile memory” when talking about computer hardware. As quick reminder – “non-volatile memory” is type of memory that stores its contents even when power is off. Such type of memory is EEPROM, Flash, FRAM. This is easy from hardware perspective. But what volatile keyword means in C or C++ code? This is… Continue reading

Interfacing GPS Module with AVR

GPS modem is a device which receives signals from satellite and provides information about latitude, longitude, altitude, time, etc. The GPS navigator is more famous in mobiles to track the road maps. The GPS modem has an antenna which receives the satellite signals and transfers them to the modem. The modem, in turn, converts the data into useful information and sends the output in serial RS232 logic level format. The information about latitude, longitude, etc. is transmitted continuously and accompanied by an identifier string. The connection of GPS modem with AVR microcontrollers shown in the circuit diagram. The ground pin of max 232 and serial o/p of the GPS modem is made common. Pin2 of MAX232 is connected to pin 3 of GPS modem and pin 3 of max 232 is connected to pin 2 of the modem. This… Continue reading

Software Debouncing of buttons

Connecting a button as an input to a micro-controller is a relatively easy task, but there are some problems. The main problem is that switches bounce, i.e., when you press (or release) a button it will often change level a couple of times before it settles at the new level. So if you, for example, connect the switch to a pin with an external interrupt enabled, you will get several interrupts when you press the button once. This behavior usually is not wanted. Even if the buttons didn’t bounce (with filtering hardware for example) we still want to capture the event of a pushed button and take some action one time for every button press, so we need to keep track of the state of the switch as well. One… Continue reading

Interfacing matrix keyboard with AVR

The keypad is the most widely used input device to provide input from the outside world to the microcontroller. The keypad makes an application more users interactive.  The concept of interfacing a keypad with the ATmega16 is similar to interfacing it with any other microcontroller. Many applications require a large number of keys connected to a computing system which includes a PC keyboard, Cell Phone keypad, and Calculators. If we attach a single key to MCU, we connect it directly to i/o line. But we cannot connect; say 10 or 100 keys directly MCUs because it will eat up precious i/o line and MCU to Keypad interface will contain lots of wires. The rows R0 to R3 are Input to the Microcontroller. They are made an input by setting the proper DDR Register… Continue reading

Sensing Temperature Using AVR

lm35

In this new tutorial, we will be interfacing an LM35 based temperature sensor with ATMEGA32. The three main types are thermometers, resistance temperature detectors, and thermocouples. All three of these sensors measure a physical property (i.e., the volume of a liquid, current through a wire), which changes as a function of temperature. In addition to the three main types of temperature sensors, there are numerous other temperature sensors available for use. However, the LM35 based sensors are precision-integrated temperature sensors, with an output voltage linearly proportional to the Centigrade temperature. The main advantage is these types of sensors don’t require any external calibration. They are internally calibrated and simply generate the output to the temperature they detect. The device is used with single power supplies, or with plus and minus… Continue reading