This code example shows how to use the ADC on tinyAVR® 2 Family microcontrollers to measure the internal temperature sensor. In Single mode, when the ADC conversion is triggered, the ADC result is available for a single sample. In this mode, ADC resolution can be selected to be 8-bit or 12-bit. In this example, the ADC is used in Single mode to measure the internal temeperature sensor with 12-bit resolution.
Microchip’s free MPLAB X IDE, compiler and MPLAB Code Configurator (MCC) graphical code generator are used throughout the application firmware development to provide easy and hassle-free user experience. Following are the tool versions used for this example:
- MPLAB® X IDE v5.45 or newer
- XC8 Compiler v2.31 or newer
- MPLAB® Code Configurator (MCC) v4.1.0 or newer
- MPLAB® Melody Library 1.37.17 or newer or newer
- MCC Device Libraries 8-bit AVR MCUs 2.7.0 or newer
- Microchip ATtiny1627 Device Support 2.6.122 or newer or newer
- ATtiny1627 Curiosity Nano (DM080104)
- Connect the ATtiny1627 Curiosity Nano to a computer using USB cable
- Download and install all software components as listed under 'Software Used'
- Hello 1
- Hello 2
- Hello 3
![ADC](images/ADC_02.png)
- Hello 4
![ADC](images/ADC_02.png)
- Hello 5 - 1 space
-
Hello 6 - 2 space
-
Hello 7 - 4 space
-
Hello 8 - 10 space
![ADC](images/ADC_02.png)
- Hello 9 - 1 space - Nested
- Download the zip file or clone the example to get the source code
- Open the .X file with the MPLAB® X IDE
- Set the attiny1627-temperature-measure-single-12-bit-adc-mplab-mcc project as Main project by right-clicking on the project title
-
Program the project to the ATtiny1627 Curiosity Nano:
- First clean and build the project by pressing the Clean and Build Main Project button
- Then make and progam the project to the ATtiny1627 by clicking the *Make and Program Device Main Project* button
-
To verify that the code is working:
- Add a Watch to the temperature_in_degC variable found in main.c
- Select the *Watches* tab
- Run code in debugging mode by clicking the *Debug Main Project* button
- Pause the debug session by clicking the *Pause* button
- Now you can read out the latest measurement in the *Watches* tab. Notice that the readout value is in hex format, so remember to convert to decimal value (0x0018 = 24).
This example shows how to use the ADC in single mode to get a 12-bit resolution measurement of the internal temperature sensor on an tinyAVR® 2-series device.