Рет қаралды 188
Using the analog-to-digital converter in an ATmega328 to read the voltage level at an analog input pin and to display the result on a 4-digit 7-segment display. This follows the previous lab exercise from • 1TE663/723 HT2021 - La...
00:00 choosing the analog input pin
01:30 connecting a potentiometer for a variable voltage
03:30 the hardware control register of the ADC
05:00 the basic code template
06:30 the init()-function
07:30 writing cleaner code to display a numeric value on the display
13:30 setting up the ADMUX and ADCSRA register
17:30 reference voltage selection
18:30 right- or left-alignment of the 10-bit result in the result register
20:50 analog multiplexer and selecting the input
22:20 the control bits ADEN och ADSC
24:20 setting up the clock prescaler
25:30 reading the ADC conversion result
26:30 starting a new conversion and waiting for the result
28:50 use of the &-operator to check a single bit
30:30 compiling and uploading the code
The code template can be found here: pastebin.com/6dWHQV5x