The following project shows how to use the Analog-to-Digital Converter (ADC) featured in the tinyAVR® 2 devices to measure current and monitor battery charge, through a discussion of the underlying theory and a demo application. The demo shows an implementation of a simple circuit where various nodes are connected to the ADC for taking certain measurements. Furthermore, by using MPLAB® Data Visualizer the relevant data can be presented live.
This example does not include an actual battery, and the circuit can be changed to match the user’s needs without altering the underlying concepts regarding the overall functionality of the presented case.
- AN4811 - Current Measurement and Battery Monitoring
- ATtiny1627 Device Page
- ATtiny1627 Curiosity Nano Hardware User Guide
- MPLAB® X IDE 6.0.0 or newer
- MPLAB® XC8 2.40.0 or newer
- MPLAB® Code Configurator (MCC) 5.1.17 or newer
- MPLAB® Data Visualizer 1.3.1160 or newer
- MPLAB® Melody Core 2.2.37 or newer
- tinyAVR® 3.0.151 or newer Device Family Pack
- Microchip ATtiny1627 Curiosity Nano Evaluation Kit
- Three LEDs
- Five resistors
- Wires
- Micro-USB cable (Type-A/Micro-B)
- Connect the two shunt resistors, R1 and R2, in series between the voltage source and VTG
- Connect a wire from between the voltage source and R1, to PB5
- Connect a wire from between R1 and R2, to PA6
- Connect a wire from between R2 and VTG, to PA7
- Connecting the load:
- Connect D1 and R3 in series between PC0 and the node between R1 and R2
- Connect D2 and R4 in series between PC1 and the node between R1 and R2
- Connect D3 and R5 in series between PC2 and the node between R1 and R2
- Connect the ATtiny1627 Curiosity Nano to a computer using the USB cable
- Download the zip file or clone the example to get the source code
- Open the .X file with MPLAB® X IDE
- Set the attiny1627-current-measurement-and-battery-monitoring-mplab-mcc project as main project. Right click the project in the Projects tab and click Set as Main Project.
- Program the project to the board: right click the project and click Make and Program Device
- Open MPLAB® Data Visualizer from within MPLAB® X IDE
- Load the .dvws configuration file plot_config
- Start streaming data by clicking the play button
- By pressing the button on the Curiosity Nano, the LEDs light up one by one each time the button is pressed, resetting if pressed when all three are lit. The change in currents and voltages can be observed in the graphs in MPLAB® Data Visualizer.
This example shows how to perform simple current measurement and battery monitoring using the ADC featured in tinyAVR® 2 microcontrollers.