Programming AVR ADC module with avr-gcc

Most AVR microcontrollers have Analog to Digital Converter (ADC) integrated into to chip. Such a solution makes embedded designers’ life much easier when creating projects and programming them. With no need for external ADC, PCB takes less space, easier to create programs – it saves time and money. As an example, let’s take the Atmega8 microcontroller, which has up to 8 ADC inputs, most with a 10-bit resolution(excluding ADC4 and ADC5 inputs that are 8-bit). All features of AVR internal ADC can be found on official ATMEL AVR datasheets, but most important to mention are: ±2 LSB accuracy – so measurements aren’t very accurate. If AREF voltage is 5V, then the error may reach ±0.04V, but this is still good results for most of the tasks; Integral nonlinearity ±0.5 LSB; Conversion speeds up to 15kSPS at maximum resolution. This is far not enough for 20kHz audio signal sampling.

Continue reading

Batteries and cell characteristics

Batteries are a cheap, small, and relatively safe way of having a portable energy source. There are many types of batteries with different characteristics and uses. Probably many of you heard the terms battery and cell referring to the same. But from a technical perspective, these are different things – a cell is a single unit that houses a single chemical reaction and produces electricity. At the same time, a battery is a pack of cells. Nominal cell voltage and battery voltage For instance, a single AA battery can be called a cell because this is a single unit where a single chemical reaction generates a voltage of 1.5V. Still, car lead-acid battery has six cells producing 2.0V each while all battery produces 12V. The first important thing to remember is that a single cell can produce a specific nominal cell voltage that depends on a chemical reaction. In contrast, the battery voltage is a combined voltage of multiple cells connected in series (or parallel).

Continue reading

AVR internal oscillator jitter research

If you go to the AVR site and open an AVR application note AVR053, you will notice different RC oscillators installed into AVR chips during history. In the table, you can see tunable oscillator versions and their features. Simply speaking, each new version of the oscillator introduces better features and improvements. But is it true? ChaN has done exciting research on this oscillator version. He tested the output signal with fixed width and measured timing fluctuations of it. And he found out that the RC generator frequency slowly fluctuates during the time. Of course, RC oscillator fluctuations are not a problem as this type of clock source isn’t stable. In time-critical applications, it is better to use crystals. But the most exciting thing is that newer versions of tunable oscillators were generating much more jitter than older ones.

Continue reading