Skip to content

Commit

Permalink
MPAE-18888: Updated code for new versions of MPLAB, XC8, changed from…
Browse files Browse the repository at this point in the history
… START to MCC Melody. Updated Readme and meta data
  • Loading branch information
Sindre Midjaas authored and Sindre Midjaas committed Nov 21, 2024
1 parent 9041f2b commit 4f7cfd2
Show file tree
Hide file tree
Showing 171 changed files with 3,904 additions and 178,267 deletions.
17 changes: 9 additions & 8 deletions .main-meta/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
"content": {
"metaDataVersion": "1.3.0",
"name": "com.microchip.mcu8.mplabx.project.attiny817-adc-basics-mplab",
"version": "1.0.1",
"version": "2.0.0",
"displayName": "ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series",
"projectName": "attiny817-adc-basics-mplab",
"shortDescription": "Example describing the basic functionality of the ADC in tinyAVR 1-series.",
"ide": {
"name": "MPLAB X",
"semverRange": ">=5.40.0"
"semverRange": ">=6.20.0"
},
"compiler": [
{
"name": "XC8",
"semverRange": "^2.29.0"
"semverRange": "^2.50.0"
}
],
"dfp": {
"name": "ATtiny_DFP",
"semverRange": "^2.2.89"
"semverRange": "^3.1.260"
},
"configurator": {
"name": "START",
"semverRange": ">=1.7.360"
"name": "MCC",
"semverRange": ">=5.5.1"
},
"device": {
"metaDataVersion": "1.0.0",
Expand All @@ -38,7 +38,8 @@
},
"author": "Microchip",
"peripherals": [
"ADC"
"ADC",
"USART"
],
"keywords": [
"Window Compare",
Expand All @@ -47,7 +48,7 @@
"SAR ADC",
"10-bit ADC",
"LED",
"START"
"MCC"
],
"additionalData": {
"longDescription": {
Expand Down
63 changes: 52 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,72 @@
<!-- Please do not change this html logo with link -->
<a href="https://www.microchip.com" rel="nofollow"><img src="images/microchip.png" alt="MCHP" width="300"/></a>
<!-- Please do not change this logo with link -->

<a target="_blank" href="https://www.microchip.com/" id="top-of-page">
<picture>
<source media="(prefers-color-scheme: light)" srcset="images/mchp_logo_light.png" width="350">
<source media="(prefers-color-scheme: dark)" srcset="images/mchp_logo_dark.png" width="350">
<img alt="Microchip Technology Inc." src="https://www.microchip.com/content/experience-fragments/mchp/en_us/site/header/master/_jcr_content/root/responsivegrid/header/logo.coreimg.100.300.png/1605828081463/microchip.png">
</picture>
</a>

# ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series

Microchip tinyAVR® 0- and 1-series, and megaAVR® 0-series devices feature a 10-bit successive approximation register (SAR) Analog-to-Digital Converter (ADC) and is capable of conversion rates up to 115 ksps. It features a flexible multiplexer, which allows the ADC to measure the voltage at multiple single-ended input pins. Single-ended input channels are referred to ground. The ADC input signal is fed through a sample-and-hold circuit which ensures that the input voltage to the ADC is held at a constant level during sampling. It also features multiple internal ADC reference voltages between 0.55V and VDD.

An ADC conversion can be started by software, or by using the Event System (EVSYS) to route an event from other peripherals. A window compare feature is available for monitoring the input signal and can be configured to trigger an interrupt on user-defined thresholds for under, over, inside, or outside a window, with minimum software intervention required.

This repository describes the basic functionality of the ADC in Microchip tinyAVR® 0- and 1-series, and megaAVR® 0-series devices in Single ended mode. It is explained in detail in the document [*AN2573 - ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series*](https://www.microchip.com/DS00002573) from Microchip. The ATtiny817 Xplained Pro board will be used in these examples.
This repository describes the basic functionality of the ADC in Microchip tinyAVR® 0- and 1-series, and megaAVR® 0-series devices in Single ended mode. It is explained in detail in the document [*AN2573 - ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series*](https://www.microchip.com/DS00002573) from Microchip. The ATtiny817 Xplained Pro board will be used in these examples.

## Related Documentation

- [AN2573 - ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series](https://www.microchip.com/DS00002573)
- [ATtiny817 Device Page](https://www.microchip.com/wwwproducts/en/ATtiny817)

## Software Used

- [MPLAB® X IDE](http://www.microchip.com/mplab/mplab-x-ide) 5.40 or later
- [ATtiny DFP](http://packs.download.atmel.com/) 2.2.89 or later
- [MPLAB® XC8](http://www.microchip.com/mplab/compilers) 2.20 or a later
- [AVR/GNU C Compiler](https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers) 5.4.0 or later
- [MPLAB® X IDE 6.20](https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide) or newer
- [MPLAB® XC8 Compiler 2.50](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers) or newer
- [MPLAB® Code Configurator (MCC) 5.5.1](https://www.microchip.com/en-us/tools-resources/configure/mplab-code-configurator) plug-in 5.7.1 or newer

## Hardware Used

- [ATtiny817 Xplained Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/attiny817-xpro)
- Micro-USB cable (Type-A/Micro-B)

## Setup

**NOTE:** The newest version of the code is generated by MCC instead of START.

### MCC Setup
This section shows how this example is set up in MCC. An overview of the MCC setup is shown in the image below:
<p><img src="images/mcc_overview.jpg" width="600"/></p>

### Device Clock Setup
The CLKCTRL module is located in the System Firmware drop-down menu. This example is configured to run on 3.33 MHz.
<p><img src="images/mcc_clk_settings.jpg" width="600"/></p>

### ADC Setup
In the Clock Settings in the ADC the Clock Pre-Scaler is set to CLK_PER divided by 4. This is to ensure that max resolution is achieved with a ADC clock frequency between 50 kHz and 1.5 MHz.
<p><img src="images/mcc_adc_clk_settings.jpg" width="600"/></p>

In the Hardware Settnigs set the Reference Selection to INTREF. The Positive Channel Input Selection sets the adc input pin, but the code overwites it. It can be changed on this code line ```#define ADC_CHANNEL 6``` in the ```main.c``` file.
<p><img src="images/mcc_adc_hardware_settings.jpg" width="600"/></p>

### VREF Setup
The Voltage reference is selected in the V<sub>REF</sub> peripheral. It is set to 2.5 V and matches the code line ```#define MAX_VOL 2.5``` in the ```main.c``` file.
<p><img src="images/mcc_vref_hardware_settings.jpg" width="600"/></p>

### Usart Setup

In the Usart Configuration Settings, enable Redirect Printf to UART. The rest can be left as default.
<p><img src="images/mcc_usart_configuration.jpg" width="600"/></p>

In the USART0_Peripheral the USART Receiver can be disabled, since it is not in use.
<p><img src="images/mcc_usart_peripheral.jpg" width="600"/></p>

### Device Pin Setup
Setting inputs and outputs can be done in the **Pin Grid View** tab. The LED0 pin on the ATtiny817 Xplained Pro is PB4. Set this to be an output, MCC will handle pins used by the USART and ADC peripherals.
<p><img src="images/mcc_pin_grid_view.jpg" width="600"/></p>

Naming and configuring the different pins can be done in the *System>Pins* menu.
<p><img src="images/mcc_pins.jpg" width="600"/></p>

## Operation

Expand All @@ -35,12 +76,12 @@ This repository describes the basic functionality of the ADC in Microchip tinyAV

3. Open the project in MPLAB X IDE.

4. Choose the use case by configuring the value of the macro *EXAMPLE_CODE* in *main.c*. Refer to the document [AN2573 - ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series](https://www.microchip.com/DS00002573) to learn about the different use cases.
4. Choose the use case by configuring the value of the macro ```EXAMPLE_CODE``` in ```main.c```. Refer to the document [AN2573 - ADC Basics with tinyAVR® 0- and 1-series, and megaAVR® 0-series](https://www.microchip.com/DS00002573) to learn about the different use cases.

5. Build the solution and program the device by using the buttons *Build* and *Make and Program Device*.

6. The ADC result is converted to voltage format and printed through the USART to the terminal.

## Conclusion

This project is an illustration of four basic use cases based around the ADC of Microchip tinyAVR® 0- and 1-series, and megaAVR® 0-series devices.
This project is an illustration of four basic use cases based around the ADC of Microchip tinyAVR® 0- and 1-series, and megaAVR® 0-series devices.
20 changes: 0 additions & 20 deletions attiny817-adc-basics-mplab.X/AtmelStart.env_conf

This file was deleted.

109 changes: 0 additions & 109 deletions attiny817-adc-basics-mplab.X/AtmelStart.gpdsc

This file was deleted.

9 changes: 0 additions & 9 deletions attiny817-adc-basics-mplab.X/atmel_start.c

This file was deleted.

19 changes: 0 additions & 19 deletions attiny817-adc-basics-mplab.X/atmel_start.h

This file was deleted.

Loading

0 comments on commit 4f7cfd2

Please sign in to comment.