Terry Smith
New Member
TLR Voltmeter Project.
I have only just joined the forum and notice that when writing code to drive an LCD most people seem to use the 18M2 chip. I made this voltmeter to use a 14M2 chip to drive the LCD as an experiment and I share the code and circuit it in case it is useful to other beginners. I have added comments to almost every line to make the code easier to follow. Apologies if the code looks a little unusual, I capitalise PicAxe commands and add an “m.” prefix to variable names as I find it easier to follow the code with this system. (The excellent colour coded PicAxe editor also helps.) Incidentally, I have set my Programming Editor tab setting to 3 characters (View/Options/Editor/Tab Size) – the default is 6 – so your editor needs to be to the same setting for everything to line up.
The voltage is measured using the internal ADC and the resultant four-digit number is displayed on a 2x8 LCD. If an over voltage is detected, the display shows a warning. A switch selected potential divider is used on the input to give two voltage ranges – 0 to 2V and 0 to 20V and a measure of over and reversed voltage protection is offered by adding a zener diode across the ADC input.
The accuracy is dependant on the chip ADC reference and the potential divider resistors and my prototype used 5% ¼ watt resistors and a 300mW zener diode. I trimmed the potential divider ratio (by experiment) by adding a small value resistor (in my case by adding to the 90K resistor(s)) to obtain the same reading on the two ranges when measuring a single 1.5 volt AA cell.
Virtually all the code, apart from reading the ADC, resetting the FVR and converting from the ADC reading to the display reading, (3 lines) is concerned with driving the LCD. While the display is specifically for a voltage reading, the same principles of operation can be adapted to display any four-digit number. The code can be modified or the PicAxe BINTOASCII function could be used to display a full five-digit word value if required.
I have only just joined the forum and notice that when writing code to drive an LCD most people seem to use the 18M2 chip. I made this voltmeter to use a 14M2 chip to drive the LCD as an experiment and I share the code and circuit it in case it is useful to other beginners. I have added comments to almost every line to make the code easier to follow. Apologies if the code looks a little unusual, I capitalise PicAxe commands and add an “m.” prefix to variable names as I find it easier to follow the code with this system. (The excellent colour coded PicAxe editor also helps.) Incidentally, I have set my Programming Editor tab setting to 3 characters (View/Options/Editor/Tab Size) – the default is 6 – so your editor needs to be to the same setting for everything to line up.
The voltage is measured using the internal ADC and the resultant four-digit number is displayed on a 2x8 LCD. If an over voltage is detected, the display shows a warning. A switch selected potential divider is used on the input to give two voltage ranges – 0 to 2V and 0 to 20V and a measure of over and reversed voltage protection is offered by adding a zener diode across the ADC input.
The accuracy is dependant on the chip ADC reference and the potential divider resistors and my prototype used 5% ¼ watt resistors and a 300mW zener diode. I trimmed the potential divider ratio (by experiment) by adding a small value resistor (in my case by adding to the 90K resistor(s)) to obtain the same reading on the two ranges when measuring a single 1.5 volt AA cell.
Virtually all the code, apart from reading the ADC, resetting the FVR and converting from the ADC reading to the display reading, (3 lines) is concerned with driving the LCD. While the display is specifically for a voltage reading, the same principles of operation can be adapted to display any four-digit number. The code can be modified or the PicAxe BINTOASCII function could be used to display a full five-digit word value if required.
Attachments
-
13.3 KB Views: 250
-
11.7 KB Views: 150