“With a code size of 1KB on an ATtiny13A MCU, this tiny module measures voltages up to 22 volts and current up to 5 amps.
There are a lot of so-called “USB doctor” modules which are used for monitoring currents flowing through a USB connection. They are used for cable or charger testing, quick charge detection and load current consumption measurements. They’re cheap of course and someone may ask why should we build one? If you can do it better, then do it. So what’s better about my design?
Self-calibration: You don’t need to know the exact resistor values used for voltage dividers. Just use a proper divider to map your desired voltage range into 0~1.1v range (1.1v is the internal V-ref of ATtiny13. The feature we needed it for). after that all you need to do is to connect the module to a precise 5v supply while holding the onboard button. the device starts up and shows “C” character on the display, calculates the divider values itself and saves them in the internal e2prom. So you just need to do it once.
Various display options: Using the button, you can switch between current display, voltage display and both. It is possible to save the preferred display on e2prom for startup.
A 1KB code challenge: Despite there are better options than using 2 chips (1 micro controller + 1 display driver), I like the discrete designs. I had to implement a display library too. The display driver is universal and you can use it for any other microcontroller that supports an ANSI C compiler! read the libraries provided below.
The design is based on an ATtiny13A microcontroller, a TM1637 LED driver and a 0.033ohms current sense resistor. the 1.1v ADC voltage reference on the ATtiny came quite handy for better precision.
I had to get rid of floating point calculations. despite the voltage divider and the values shown on the display may seem to have radix points, they don’t. The values are calculated as mA and mV and then a point is placed in the display at proper location. so there was no need to calculate float values.”