| Next revision | Previous revision |
| pt:avr:adc [2015/12/01 11:27] – Criação deste novo documento. artica | pt:avr:adc [2020/07/20 09:00] (current) – external edit 127.0.0.1 |
|---|
| ====== Analog-to-digital Converter ====== | ====== Conversor Analógico-para-Digital ====== |
| |
| Analog-to-digital converter (ADC) transforms an analog voltage value to a digital value. The allowed voltage range on an ADC input of an AVR microcontroller is 0 to 5.5 V. The size of the digital value is 10 bits, but its precision is ±2 units. The error may be even larger, if the microcontroller's supply voltage is not protected from interference. AVR has a separate voltage supply and comparison voltage pin for ADC. The separate supply voltage helps to cut down the interference and it may not differ more than 0.3 V from the main supply voltage. Comparison voltage defines the maximum digital value. For example, if the comparison voltage is 3 V then an input with the same voltage will read as 2<sup>10</sup> - 1 (1023). | Um conversor Analógico-para-Digital (ADC) transforma um valor analógico de voltagem num valor digital. Os limites para a tensão permitida numa entrada ADC do microcontrolador AVR são 0-5,5 V. O número de bits do valor digital é de 10, e a sua precisão é de ± 2 unidades. O erro pode ser ainda maior, se a tensão de alimentação do microcontrolador não estiver protegida de qualquer interferência. O AVR tem um pinos de tensão de alimentação e de tensão de comparação separados para o ADC. A tensão de alimentação separada ajuda a reduzir a interferência e pode não diferir mais de 0,3 V da tensão principal de alimentação. A comparação das tensões define o valor digital máximo. Por exemplo, se a tensão de comparação é de 3 V, então uma entrada com a mesma tensão vai ser lida como 2<sup>10</sup> - 1 (1023). |
| |
| AVR ADC works on the principal of successive approximation. In short, the measured voltage is compared to specific voltage levels and the results are reported as a bit array. This method is relatively slow, as each bit in the final result is calculated separately. AVR spends 13 clock cycles for each measuring, except the first (on start-up), which takes 25 cycles. These cycles are not the controller's duty cycles though, but instead special cycles allocated to the ADC unit by the frequency divider. The ADC frequency should be 50-200 kHz to achieve maximum precision, on higher frequencies the precision fades. In some cases it is more important to get a large number of readings instead of maximum precision, in which case using a larger frequency is totally justified. According to AVR documentation, one measuring takes 13-260 µs. | Um AVR ADC funciona segundo o princípio de aproximação sucessiva. Em suma, a tensão medida é comparada com os níveis específicos de voltagem e os resultados são reportados como uma matriz de bits. Este método é relativamente lento, pois cada bit no resultado final é calculado separadamente. O AVR gasta 13 ciclos de relógio para cada medição, com excepção do primeiro (no start-up), no qual consome 25 ciclos. Esses ciclos não são os ciclos de funcionamento do controlador, porém, mas ciclos especiais atribuídos à unidade ADC pelo divisor de frequência. A freqüência do ADC deve ser 50-200 kHz para permitir a máxima precisão. Em freqüências mais altas a precisão decai. Em alguns casos, é muito mais importante obter um grande número de leituras em vez de uma maior precisão, sendo neste caso o uso de uma frequência maior totalmente justificado. De acordo com a documentação do AVR, uma medição leva 13-260 µs. |
| |
| The measured value can be read as an 8- or 10-bit value. Since AVR itself is an 8-bit device, it has two 8-bit registers for storing the ADC values. It is possible to specify in the settings whether the first two or the last two bits go to a separate register. If the two younger bits, which characterize the result less, are separated, the result can be read as an 8-bit value - a combination like that is called a left-aligned result. The other combination, where both registers are read and the value is in 10-bit format, is called a right-aligned result. | O valor medido pode ser lido como um valor de 8 ou 10-bits. Como o próprio AVR é um dispositivo de 8 bits, tem dois registos de 8 bits para armazenar os valores do ADC. É possível especificar nas configurações se os dois primeiros ou os últimos dois bits vão para um registo separado. Se os dois bits menos significativos, que caracterizam o resultado, são separados, o resultado pode ser lido como um valor de 8 bits - uma combinação como essa é designada de resultado alinhado à esquerda. A outra combinação, em que ambos os registos são lidos e o valor está formatado em 10-bits, é designada de resultado alinhado à direita. |
| |
| A typical AVR has 8 analog voltage input channels, ATtiny series have only a few, some ATmega devices have 16, but there is always only one converter. To make it possible to use different inputs, the device has a built-in multiplexer. The input of the multiplexer is definable using a special register. The ADC unit has a few more properties: using the processor's sleep mode for converting to reduce the interference and the option to use an internal fixed comparison voltage (usually 2.65 V, in some models 1 V). | Um AVR típico tem 8 canais de entrada de tensão analógica. A série ATtiny tem apenas alguns, e alguns dispositivos ATmega têm 16, mas há sempre um único conversor. Para tornar possível a utilização de diferentes entradas, o dispositivo tem um multiplexador embutido. A entrada do multiplexador é definida através de um registo especial. A unidade ADC tem mais algumas propriedades: usando o modo de suspensão do processador para converter para reduzir a interferência e a opção de usar uma tensão de comparação fixa interna (normalmente 2,65 V, em alguns modelos 1 V). |
| |
| ~~PB~~ | <pagebreak> |
| |
| <box 100% round #EEEEEE|Example> | <box 100% round #EEEEEE|Exemplo> |
| |
| Task: measure the voltage in ADC channel 3 of an ATmega128. The voltage is in range of 0-5 V and the result should be at 8-bit precision. | Task: measure the voltage in ADC channel 3 of an ATmega128. The voltage is in range of 0-5 V and the result should be at 8-bit precision. |