Basic understanding of microcontroller interrupts

This tutorial is based on Atmega328 microcontroller, which is popular in Arduino boards. So you’ll be able to test all code examples on Arduino as it can serve as general purpose AVR test board with no problem. Understanding Interrupts Probably you won’t be able to find a microcontroller without interrupt capability. These are essential attributes of any modern microcontroller or processor. They may seem confusing and tricky at first glance, but during the time, you will find out that regular MCU operation is impossible without interrupts. Interrupts can be compared to real-life events. Look around – all your activities are full of them. For instance, you are reading this tutorial and find it interesting, so you are all in it. But suddenly, your cell phone rings. What do you do? You remember the last stroke you’ve read and answered the phone. One phone conversation is over; you return to your reading as if nothing happened. Well, this is only one example of interrupt to give some visual clue what interrupts are.

Continue reading

A DDS function generator using an ATmega16

I still remember the piece of a rectangular box with many buttons labeled 1kHz, 10kHz, 100kHz, 1MHz, and everything else in between. Oh, it also has a knob connected to a dial dividing a sector into a hundred parts with a series of 7 segments changing dial every time a button is fired– just like old school radio we see at StarTrek. We commonly call it the function generator, and it’s usually used to inject square waves into your circuits – what for? Mostly for clocking. Here’s a new implementation of the AVR DDS function generator 2.0 (scienceprog.com); it has a different board layout and uses only through-hole components for easy construction. It has two outputs, one for a +-5V signal source and the other for a 0-10V signal source; the voltage levels of the two outputs are reconfigurable using two separate potentiometers. Like the original version, it incorporates a 2×16 LCD screen and pushes buttons for control – press a button to start and stop the signal generation. The circuit’s DAC is just a simple R-2R ladder controlled by…

Continue reading

Controlling AVR I/O ports with AVR-GCC

Controlling pins is one of the first things to learn when learning microcontrollers. It seems that each microcontroller type has its port logic. So before using them, it is essential to understand every detail so you can effectively use them in projects. Let’s see how ports are organized in AVR and how to successfully control them. Inside AVR port If you try to look into any AVR datasheet, you will find port drawing which may seem a bit complex at the start. But for a simple start, let’s look at simplified port pin schematic. x designates port (A,B,S,D,…); n designates pin number (0..7) As you can see, each port consists of three registers DDRx PORTx, and PINx (for instance, DDRA, PORTA, and PINA). When looking into this simple logic, we can see several variants of operation. To enable output to the pin, we need to write logic ‘1’ to DDx.n pin. This will enable buffer to let bit through from PORTx register. If the PORTx.n bit is ‘1’, then it can source a pin with VCC voltage and up to…

Continue reading

Setting up AVR development platform

You can be encouraged to use various types of AVR development tools. Most of them cost money to get full functionality and support. All they are great tools out of the box with fast support that you have to pay. Of course, you can give it a try with their limited versions to see capabilities. As we mentioned before, we will use free tools that are great enough compared to commercials. UPDATE! Here are the currently supported software options for AVR microcontroller development: WinAVR or AVR-GCC tools WinAVR is a toolset for C programming the AVR microcontrollers. It is a bunch of small programs that make development as comfortable as possible. The main tools are avr-gcc compiler, avrdude programmer, avr-gdb debugger, and more. These are command-line tools, so you need to integrate them into some integrated development environment (IDE). There can be any IDE supporting external tools like Eclipse and, of course AVRStudio that we will be using. Besides, WinAVR comes with great program writing tool – Programmers Notepad. Actually, with WinAVR, you can write, compile, upload to chip, and…

Continue reading

Choosing AVR programmer

There are many AVR programmers to choose from. The simplest ones are bitbang programmers. These are straightforward programmers that can be built with as few components as few resistors (or no resistors at all). These can be COM, LPT, or USB-to-TTL converter based. DIY Bitband programmers Example of LPT port programmer These are probably the simplest to build, as there is no need to convert any signals from the port. Buffer chip is used only for safety reasons to protect computer port. Even simpler programmer cable can be found here.

Continue reading

Things needed before you learn AVR

There are several things you need to do before learning AVR. First of all, you need an AVR chip. You better choose megaAVR series, so you don’t need to worry about the lack of peripherals when required. Atmega8, Atmega16, or further mega’s will do correctly. Probably chose in DIP package as it will easily fit in breadboard for fast prototyping.  Development boards are great to work with, primarily designed for learning and prototyping.  Any Arduino board can be used with no problem, as it has all the necessary means to serve as a general-purpose dev board. Anyway, I leave this up you for a while. The next thing is the programmer. This is where you can get a headache. Really! In a few words, a programmer is a cable/device used to upload firmware (compiled program) to chip. Programmers can be connected to the computer via various ports, including parallel (LPT), serial (COM), and USB. Or there can be no programmer at all if the chip has a bootloader set up. But this will be discussed later. These were two hardware…

Continue reading