Measuring analogue values Print
Written by Jurij Mikeln   

Those of us who are involved in electronics generally want to measure analogue values such as voltage, current, resistance and other electronics parameters. When microcontrollers firstly appeared, they did not have A/D (analogue to digital) converters built-in, so engineers had to figure out that problem. Today, we are lucky: most AVR microcontrollers contain a 10-bit A/D converter, only a few do not. However they usually have at least a built-in comparator which can also be handy for making an A/D conversion.

In this chapter I will show you some program examples that are widely used and suitable for most of our measurements.

AVR internal registers

If you look at an AVRs datasheet, you’ll see many internal functional blocks. In Figure 1, you can see the internal circuitry of the A/D converter.

There are a couple of things that are important to know when dealing with A/Ds. The first is the number of bits of resolution that we get from the A/D conversion. What does this mean? Well, say we have a voltage of 5 Volts, and we interpret (in electronics, we use the word “sample”) it to 8 bits, then one bit corresponds to 0.0195 Volts ( 5/28= 5/256), say 20 milivolts. If the same voltage is sampled to 10 bits, then the resolution is not 20 mV but 0.00488 Volts (5/210 = 5/1024), say 5 mV, which is 4-times better than the 8-bit A/D conversion. This tells us that the resolution is important: probably the most important factor in A/D conversion. Since the A/D converters contained in AVRs are 10-bit ones, the resolution is fixed. If better resolution is needed, then we can do the following: use an external A/D converter with better resolution or use another reference voltage. You can see in Figure 1 that AVRs have an internal reference voltage of 2.56 Volts. This reference voltage can be used if we measure voltages that do not exceed 2.5 Volts. We can also use AVcc (5V) as the reference voltage. In any case, we must define the reference voltage as a part of the Config Adc statement, in our program, as follows:

Config Adc = Single , Prescaler = Auto ,Reference = Avcc

In the above case, the reference voltage is AVcc. If we want to use the internal 2.56 V reference, then we must write the configuration as follows:

Config Adc = Single , Prescaler = Auto ,_Reference = INTERNAL

Measuring analogue values

2012_AVR_UK_87

Continue reading

Shop area

Last Updated on Wednesday, 01 August 2012 14:39