Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

AVR timers do more than count time

Probably Timer/Counters are one of the most complex peripherals in microcontrollers, but as fact, they are most common and no matter what complexity program is. Designers of timers have put a lot of thought in them making them very flexible, versatile for all timing dependent tasks like measuring periods, generating PWM signals, generating output signals and timed interrupts. Timers run independently from AVR core. Once set, they do their silent job while AVR can do other tasks or go to sleep. AVR can read timer values, or change operation modes whenever it needs or only can be interrupted with several available interrupts. If you see an application where the frequency is measured, music is generated or motor is driven – there is timer involved. Continue reading

Implementing AVR interrupts

Before we go to the code part lets what is needed to run interrupts successfully. These conditions applies to all AVR interrupts. First of all, we need to enable global interrupts by setting global Interrupts enable bit (I) in the SREG register. This is crucial as this bit enables or disables all interrupts in AVR microcontroller. So each time you are setting up an interrupt be sure this bit is enabled. Next thing is enabling individual interrupt bits on particular peripheral control register. Without setting this bit – wanted interrupt won’t work either. And the last thing is to to be sure that there are required conditions for an interrupt to occur. For instance, if you set timer overflow interrupt, be sure this overflow will occur. Defining AVR interrupts Now… Continue reading

Basic understanding of microcontroller interrupts

Earlier I’ve made a mistake by referring this tutorial to first AVR family microcontrollers like Atmega8/16/32/64/128. But AVR is being continuously changed with various new tweaks and updates like enhanced pin control or different register names. Since now tutorial will be 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 normal MCU operation is impossible without interrupts. Interrupts can be compared to real… 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 own port logic’s. So before using them, it is essential to understand every detail of it so you could effectively use 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… 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. Most common commercial packages are CodeVisionAVR, Imagecraft ICCV, IAR Workbench. All they are great tools out of the box with fast support that you have to pay. Of course, you can give a try with their limited versions to se capabilities as we mentioned before we are going to use free tools that great enough comparing to commercial. 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. Main tools here are avr-gcc compiler, avrdude programmer, avr-gdb debugger and even more. These are command line tools, so you need… Continue reading

Choosing AVR programmer

As we talked earlier, there are many AVR programmers to choose from. The simplest ones are bitbang programmers. These are straight forward programmers that can be built with as little components as few resistors (or no resistors at all). These can be COM, LPT or USB-to-TTL converter based. DIY Bitbang programmers Example of LPT port programmer These are probably simplest to build as there is no need to convert any signals coming 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