4 Demo Operation

In this demo, we use the ATtiny1627 Curiosity Nano and a breadboard circuit to show how to measure circuit currents and monitor a battery using the 12-bit ADC with PGA. To test the circuit, the battery voltage, VBAT, is replaced with VBUS supplied by the micro-USB cable connected to the Curiosity Nano. Furthermore, disconnect the on-board debugger from the on-board target voltage regulator to test this concept using a supply voltage from the micro-USB cable and shorting the VOFF pin on the Curiosity Nano to ground. Then you can supply the Curiosity Nano with target voltage on the VTG pin. The ATtiny1627 Curiosity Nano Hardware User Guide provides a detailed description.

The breadboard circuit consists of two shunt resistors, connections to pins on the Curiosity Nano, and a variable load consisting of three LEDs and resistors. The shunt resistors are used to calculate different currents. Figure 4-1 shows a diagram of the breadboard circuit. In this example, R1 = 1Ω and R2 = 1.5Ω. R3, R4 and R5 are be chosen based on the current flowing through the LEDs and wanted light intensity. If you decide to change the values for R1 or R2, make sure to change the source code correspondingly.

Figure 4-1. Breadboard Circuit Diagram

Shunt resistor R1 is placed in series with the battery voltage and can therefore be used to measure the total current drawn from the battery. Shunt resistor R2 is put in series with VDD and can be used to find the current drawn by the tinyAVR® 2 device. By subtracting the current drawn by the microcontroller from the total current drawn from the battery, the current drawn by the variable load is found.

The equations below show how to calculate the total current drawn from the supply (IBAT), the current drawn by the AVR® device (IDD), the current drawn by the load (ILOAD), and the battery voltage (VBAT).

Equation 4-1. IBAT
I BAT = V R1 R1
Equation 4-2. IDD
I DD = V R2 R2
Equation 4-3. ILOAD
I LOAD = I BAT I DD
Equation 4-4. VBAT
V BAT = V DD + V R1R2

In addition to measuring the current consumption of the different components of the circuit, voltage measurements must monitor the battery. VDD can be calculated by measuring the internal VDD/10 ADC channel and multiplying the result by 10. Then the voltage across both shunt resistors can be measured and added to the VDD result to find VBAT. Recharge the battery if VBAT or VDD is too low for the application to operate correctly.

After performing the necessary measurements, they are converted from ADC results to real-world numbers and sent through USART as floating-point values. MPLAB® Data Visualizer receives these values and graphs them in real time. Three LEDs are connected to the load circuit and controlled by the user by clicking the button on the ATtiny1627 Curiosity Nano board. These are used to observe a change in voltage and current as the load resistance is changed. The LED on the Curiosity Nano board will switch on if all the load circuit LEDs are off and switch off if at least one is on.