Sunday, December 31, 2023

"Analog" Microcontrollers

Even the smaller microcontrollers continue to strive.  One direction of expansion is the analog domain.   Analog to digital converters (8 to 12-bit)  have long been integrated into microcontrollers.  Some microcontrollers have gone further in analog functions such as Cypress has an innovative line of PSOC microcontrollers with programmable analog and digital functions and Analog Devices has Precision Microcontrollers with 16-bit ADC, DAC and amplifiers which have perhaps the better spec than others.  The venerable PIC microcontrollers has the PIC16F171xx family with ADC, DAC, voltage reference, comparator and Op-Amp.   In particular, PIC16F17115 comes in a 8-pin package (DIP, SOIC and 4x4mm DFN), which is the size of a normal Op-Amp, but it still has 14KB Flash (8K words), 1KB SRAM, timers, I2C/SPI/UART,  configurable logic cells and internal oscillator up to 32MHz and it costs less than $1 in small quantity.  With essentially 6 pins to work with, it has the flexibility of mapping almost all peripherals to any I/O pins (some analog input pins are fixed).   If in-circuit programming is needed, 3 I/O pins have to be used during the programming, so care has to be taken not to have adverse effect when the programming signals are applied.  In order to use the MCLR pin as a general input pin (it cannot be used as an output pin), the high voltage programming mode (LVP=0) has to be used and the voltage on this pin can go up 9V.  The microcontroller can be put into the sleep mode for less than 1uA current draw; it can be waken up with a IO pin change or the watchdog timer.

It is commonly understood that the integrated analog functions are of poor performance compared to dedicated opamp, ADC ICs.   

Voltage Reference

There are two independent programmable gain amplifiers, with gains of 1, 2, and 4 for reference voltages of 1.024V, 2.048V and 4.096V.  The spec tolerance is +/-4 to 5% over the entire temperature range of -40C to 85C.  The reference voltages do not go to the pins, so we cannot measure them directly.  Indirectly, we use it as the DAC reference and measure the DAC output.    The reference is set to 2.048V and the DAC is set to the middle (0x80); the DAC output is measured 1.023V.

Op-Amp

For the 8-pin device, the output of the opamp is not brought out to a pin.  The input voltage is constrained by the maximum 5.5V supply voltage, which is better than most of the modern microcontroller.   Being a newer device, the datasheet is sketchy all parameters are characterized but not tested for VDD at 3V.  The typical offset is +/-1mV, GBW 2.3MHz, slew rate 9V/us, input noise 28nV/sqrt(Hz) at 10KHz (it is called low-noise) and while the input is rail-to-rail, but the output is within 0.15*VDD.   One of the advantages of being a programmable device is that the offset can be calibrated.  

We can set the opamp in the inverting configuration.  The positive input is set to the DAC output, which we can measure.  We measure the negative input; the difference is the offset voltage, which is measured to be 2.6mV, somewhat worse than expected.  We can also measure the gain set resistor values.   When pulling the negative input to ground, it draws about 15uA, so the resistance is about 68K for 8 resistive elements, or 8.5K each.

ADC

It is common to monitor supply voltage with a resistor divider.  When we operate on a single lithium ion battery cell directly for low power operation, we want to minimize the power draw.  We can use one IO pin to switch off the resistor divider.  There is another way that does not require the extra IO pin: use the supply voltage as the ADC reference, and digitize the fixed internal reference and back calculate the supply voltage.  Because this microcontroller supports differential ADC inputs,  it provides still another way: we can set the battery voltage as the positive input and the internal voltage reference 2.048V as the negative input and use the 2.048V reference as the ADC reference voltage.  We can sense the voltage up to 4.096V.

Sunday, December 24, 2023

110mAh LiPo Battery Test

We want to check the capacity of the an 110mAh LiPo battery for a low drain application.  We'll discharge the battery to a 7.5KOhm resistor for about 5mA load and recharge it at 100mA.  

The battery weighs 3.11g (w/ connector), dimension 1.1 x 0.5 x 0.22", connector JST.



Discharging

Charging 

The kink is caused by switching from constant current (100mA) to constant voltage (4.2V) charging.