Voltage and Current LCD Display
I modified a Coutant battery charger to be a variable power supply (PSU). This then needed an output display which this circuit provides. The LCD displays both voltage and current to 2 decimal places.
PLEASE NOTE: THIS DESIGN IS PROVIDED WITHOUT WARRANTY AND FOR PERSONAL NON-COMMERCIAL USE ONLY.
I have used Microchip's 14 pin PIC16F688 chip, an LM358N op amp and Sanyo 16x1 LCD (DM161B). I've compiled the program with the BoostC compiler.
The PSU has an existing 'low side' current sense resistor ('Rsense'). This results in a voltage drop across it proportional to current flowing through it. Eg: with 0.1ohm resistance, 0.1v will be lost with a 1A current through it. The op amp amplies this voltage with a gain of about 5 to help the PIC measure it. This voltage drop therefore reveals the current flow.
Circuits that have a low side current sense resistor have two grounds. 'True ground' is on the input/transformer side of Rsense and the negative terminal of the output is at a higher potential. The PIC in this circuit is tied to true ground so that both current and voltage measurements are positive relative to its ground. This makes it easier to measure current but results in a voltage error which needs to be corrected in the software.
An external load sees voltage relative to the higher ground, ie: the voltage measured by the PIC is greater than available on the outside due to the voltage loss through Rsense. So the program adjusts the measured voltage by this loss. It's easy to do this because the PIC is already measuring that loss to determine current. Comparisons with a Fluke multimeter reveal good accuracy (within 0.03v at 4A, 0.01v at lower currents).
Noise in the circuit and whatever other factors often result in a PIC yielding a range of ADC conversion values for a given voltage (ie: not entirely stable). I have found that by averaging many measurements smooths this effect and yields a reliable result. In this application I have also added a 'jitter' check to stop the result flickering up and down by insignificant amounts, 0.01v in this case. As mentioned above the result is good and accuracy seems to be maintained.
The LCD has an HD44780 compatible controller chip which makes it very easy to configure and display characters (see LCD1 & LCD2 for a good primer on LCDs). I've used the 4 bit mode to reduce the number of pins needed. The only downside of this is that every instruction or character displayed requires two 4 bit communications with the LCD instead of one 8 bit. This requires a few extra PIC instructions which take just a few extra micro-seconds. I've also not bothered reading the display for status and rely on safe timing delays for instructions to be executed. Again this saves one pin (RW) on the PIC and adds mere fractions to the timing. For instance, 500 iterations of measuring current and voltage (16 times each), performing all the calculations to convert ADC values to meaningful results and displaying these takes 12-13secs (ie: an update speed / refresh rate of ~40 a second at 4MHz; plenty quick enough).
Voltage/current values are stored in variables for those. These need to be converted to individual characters for sending to the LCD. I use the BoostC 'Integer to ASCII' conversion function which populates variables in an array with one byte per digit. These are in an ASCII form which means numbers are preceded with 0x30 (0 = 0x30, 1 = 0x31, etc). So deducting 0x30 (in 4 bit mode) yields values of 0 to 9 which then easily positioned on the LCD.
The circuit diagram attempts to show how I blended my circuit into an existing PSU. The PSU has a conventional mains transformer feeding a bridge rectifier. This goes to a large input cap which yields 24v DC without load. My LCD requires at least 8v to drive its back light so I feed a 7812 regulator with the 24v from the main capacitor. The 12v from that regulator (not shown on the circuit diagram) drives the backlight via a 51ohm current limiting resistor (70mA). I also feed a 5v regulator from that 12v. This 5v regulator is shown on the diagram and it feeds the PIC / op amp circuit and LCD logic Vdd. Voltage and current inputs to the PIC can go to any analogue channel but the ones I have used are indicated in the C program. Since the PIC I chose only has 14 pins I use Port C to drive the RS line and 4 data channels, and the 'E' (enable) channel is on PortA. You really need to dedicate a port to RS and Data lines as I have done (it makes it easier to configure). R1/R2 resistor divider values are chosen to reduce the maximum PSU output voltage to less than the 5v PIC reference voltage. R3, 4 and 5 set the gain and adjustability of the op amp. These values and some of the arithmetic in the program came from modelling done in this spreadsheet.
Click on the links below for other pages.
Art of the Possible ¦
Absence of Matter ¦