This shows you the differences between two versions of the page.
pm:lab:lab0xc0-4 [2020/04/05 15:00] iuliana.brinzoi [ADC in Atmega324] |
pm:lab:lab0xc0-4 [2020/04/07 21:54] (current) iuliana.brinzoi [Tasks] |
||
---|---|---|---|
Line 12: | Line 12: | ||
=== Sampling Rate === | === Sampling Rate === | ||
- | The sampling rate represents the time at which the values of the analog input signal are read. The time is divided into discrete intervals, each sampling a value from the input signal. The Nyquist rate tells us that it is mandatory for the sampling rate to be as twice the frequency of the analog input signal so that the signal can be reconstructed afterwards. | + | The sampling rate represents the time at which the values of the analog input signal are read. The time is divided into discrete intervals, each sampling a value from the input signal. The Nyquist frequency tells us that it is mandatory for the sampling rate to be at least twice the frequency of the analog input signal so that the signal can be reconstructed afterwards. |
- | There appears a problem where frequencies above half the Nyquist rate are sampled because they are incorrectly detected as lower frequencies. This process is called aliasing. | + | There appears a problem where frequencies above half the Nyquist frequency are sampled because they are incorrectly detected as lower frequencies. This process is called aliasing. |
{{ :pm:lab:adc_2.png?600 |}} | {{ :pm:lab:adc_2.png?600 |}} | ||
=== ADC Types === | === ADC Types === | ||
- | == Direct Conversion == | + | == Direct Conversion (Flash ADC) == |
Has a bank of comparators sampling the input signal in parallel, each firing for their decoded voltage range. The comparator bank feeds a logic circuit that generates a code for each voltage range. | Has a bank of comparators sampling the input signal in parallel, each firing for their decoded voltage range. The comparator bank feeds a logic circuit that generates a code for each voltage range. | ||
{{ :pm:lab:adc_3.png?300 |}} | {{ :pm:lab:adc_3.png?300 |}} | ||
Line 39: | Line 39: | ||
For a single ended conversion, the result is ADC = Vin * 1024 / Vref. | For a single ended conversion, the result is ADC = Vin * 1024 / Vref. | ||
- | To check if a ADC conversion is completed, ADIF bit from ADCSRA register can be tested, or a interrupt can be generated by setting bit ADIE in ADCSRA register. | + | To check if a ADC conversion is completed, the ADIF bit from the ADCSRA register can be tested, or an interrupt can be generated by setting the ADIE bit in the ADCSRA register. |
=== Register Description === | === Register Description === | ||
Line 82: | Line 82: | ||
If bit ADATE in ADCSRA register is set, ADC is set to AutoTrigger mode and bits ADPS2:0 control the trigger source. | If bit ADATE in ADCSRA register is set, ADC is set to AutoTrigger mode and bits ADPS2:0 control the trigger source. | ||
- | In **Free Running mode**, write bit ADSC in ADCSRA register to start the first conversion. ADC will then start a new conversion ass soon as the current conversion is done. The result will be overwritten, bit ADSC will not be cleared. | + | In **Free Running mode**, write bit ADSC in ADCSRA register to start the first conversion. ADC will then start a new conversion as soon as the current conversion is done. The result will be overwritten, bit ADSC will not be cleared. |
In **Analog Comparator mode**, ADC can compare two analog signals and trigger an interrupt. For more details, see chaper //22. Analog Comparator// in datasheet. | In **Analog Comparator mode**, ADC can compare two analog signals and trigger an interrupt. For more details, see chaper //22. Analog Comparator// in datasheet. | ||
- | If bits ADTS2:0 are set to **External Interrupt Request**, a rising edge on a input pin can trigger an ADC conversion. | + | If bits ADTS2:0 are set to **External Interrupt Request**, a rising edge on an input pin can trigger an ADC conversion. |
Timers can be used for a precise control of ADC`s sampling rate. Using ADTS2:0 bits, a timer event (compare match, overflow) can be used to start a new conversion. | Timers can be used for a precise control of ADC`s sampling rate. Using ADTS2:0 bits, a timer event (compare match, overflow) can be used to start a new conversion. | ||
Line 92: | Line 92: | ||
{{ :pm:lab:adc_16.png?500 |}} | {{ :pm:lab:adc_16.png?500 |}} | ||
- | When the conversion is done, ADC module can generate a new interrupt that can be used to control the timing of the next timer event. | + | When the conversion is done, the ADC module can generate a new interrupt that can be used to control the timing of the next timer event. |
Line 121: | Line 121: | ||
===== Setup ====== | ===== Setup ====== | ||
- | {{:pm:lab:adc_14.png?900|}} | + | {{:pm:lab:adc_17.png?900|}} |
===== Tasks ====== | ===== Tasks ====== | ||
Sketch is available here: {{:pm:lab:lab3.zip|}} | Sketch is available here: {{:pm:lab:lab3.zip|}} | ||
<hidden> | <hidden> | ||
- | Solution is available here: {{:pm:lab:lab3_sol.zip|}} | + | Solution is available here:{{:pm:lab:lab0xc3_sol_asistenti.zip|}} |
</hidden> | </hidden> | ||
- To the PA1 pin there is connected a voltage divider. Push buttons control the output voltage. Read the value from the pin using polling and print the corresponding voltage to the serial console. | - To the PA1 pin there is connected a voltage divider. Push buttons control the output voltage. Read the value from the pin using polling and print the corresponding voltage to the serial console. | ||
- There is a temperature sensor (LM35) connected to PA0 pin. Configure the ADC to read the value from the sensor using interrupts. Display on the UART console the voltage and the temperature in Celsius degrees associated with it. | - There is a temperature sensor (LM35) connected to PA0 pin. Configure the ADC to read the value from the sensor using interrupts. Display on the UART console the voltage and the temperature in Celsius degrees associated with it. | ||
- | - Configure the ADC to start a conversion every 10 ms using Timer 0 compare match as trigger event and read the value using interrupts. | + | - Configure the ADC to start a conversion every 10 ms using Timer 0 compare match as trigger event and read the value from the potentiometer connected to PA6 using interrupts. |
<note tip> | <note tip> | ||
Hint: Check out ADTS2:0 bits in ADCSRB register | Hint: Check out ADTS2:0 bits in ADCSRB register |