Digital Voltmeter (DVM) using PIC16F688

Summary of Digital Voltmeter (DVM) using PIC16F688


This article details the construction of a 0-20V digital voltmeter (DVM) using a PIC16F688 microcontroller. The system scales input voltage via a resistor divider to a safe range for the internal ADC, converts it to a digital count, and displays the result on an HD44780 LCD.

Parts used in Digital Voltmeter (DVM) using PIC16F688:

  • PIC16F688 microcontroller
  • Resistor R1
  • Resistor R2
  • 5.1V Zener diode
  • HD44780-based character LCD
  • 5K potentiometer
  • In-circuit serial programming (ICSP) header
  • LM7805 linear regulator IC
  • Breadboard
  • Regulated +5V power supply

Introduction

This project will describe how to make a simple digital voltmeter (DVM) using a PIC16F688 microcontroller. The range of this DVM is 0-20V, but you can easily increase or decrease the range of input voltage as your requirements after you understand the voltage scaling method described in this project. The PIC micro reads the input voltage through one of the 8 analog channels and convert it to a 10-bit digital number using the internal ADC. Doing some math with ADC conversion (you will see later), this number can be converted to the actual measured voltage. The voltage is displayed in an HD44780-based character LCD.

Digital Voltmeter

Circuit Diagram and Description

You cannot feed a 20V signal directly to a PIC microcontroller’s input channel. It is too higher than its operating voltage, and the microcontroller could be damaged. So, first we need a voltage scaler that will scale down the input voltage to the safe operating voltage range of PIC16F688. It can be achieved by a simple resistor divider network shown below.

resistors, R1 and R2, the input voltage ranging from 0-20V can be down converted to 0-5V. For the chosen values of R1 and R2, you can see that the output (Va) from the resistor divider network is 1/4th of the input voltage. If the input voltage goes beyond 20V, Va will exceed 5V, and this could be harmful for the PIC microcontroller. If you connect a 5.1V Zener diode across the R1 resistor, the output voltage Va will never exceed 5.1V. This will protect the microcontroller from any possible damage due to high voltage input. The voltage Va will go to AN2 (pin 11) channel of the PIC16F688 microcontroller. The rest of the circuit is shown below.

The LCD display is connected in 4-bit mode. If you have just 14 pins in your LCD module, then you may not have a back-light facility and you can ignore the pins 15 and 16. The contrast adjustment is done through a 5K potentiometer connected between +5V and Gnd. An in-circuit serial programming (ICSP) header is provided so that you can easily upgrade the firmware inside the PIC microcontroller in future if you make any changes. An external reset is helpful to bring the entire system to a known initial condition, when the microcontroller stops executing the program for some reason.

The complete circuit built on a breadboard is shown here. You need a regulated +5V power supply for this project (Why regulated? You will find the answer in the Software section below). You can use a LM7805 linear regulator IC for this purpose (read my article Regulated Power Supply for your Breadboard).

Software

Before writing the code for this project, you need to do some math related to AD conversion. You know that any application that uses analog-to-digital converters (ADCs), requires a fixed reference voltage to provide accurate digital count for input analog signal. If the reference voltage is not stable, the ADC output is meaningless. In this project, the reference voltage for ADC operation is selected to be Vdd (= +5 V). This is done by clearing the VCFG bit in ADCON0 register. Therefore, the ADC will convert any input voltage between 0-5 V in to a digital count between 0-1023. A major source of error in this project is the accuracy of R1 and R2 resistors. You are recommended not to use the rated values of the resistors. Rather measure their values with a good quality digital multimeter, and use those values for your calculation. What I found is R1 = 1267 Ω and R2 = 3890 Ω. Now,

0 – 5 V Analog I/P is mapped to one of the 1024 levels (0-1023 Digital Count)

 

For more detail: Digital Voltmeter (DVM) using PIC16F688

Quick Solutions to Questions related to Digital Voltmeter (DVM) using PIC16F688:

  • How does the project protect the microcontroller from high voltage?
    A 5.1V Zener diode is connected across the R1 resistor to ensure the output voltage Va never exceeds 5.1V.
  • What reference voltage is selected for ADC operation?
    The reference voltage is Vdd, which equals +5 V, achieved by clearing the VCFG bit in the ADCON0 register.
  • What is the resolution of the analog-to-digital conversion?
    The ADC converts any input voltage between 0-5 V into a digital count ranging from 0 to 1023.
  • Which pin of the PIC16F688 receives the scaled voltage?
    The scaled voltage Va is connected to the AN2 channel, which corresponds to pin 11.
  • Why is a regulated power supply necessary for this project?
    A stable reference voltage is required for accurate digital counts; if the reference is unstable, the ADC output becomes meaningless.
  • How should resistors R1 and R2 be handled for calculation accuracy?
    You should measure their actual values with a good quality digital multimeter rather than using the rated values.
  • Can the voltage range of this DVM be changed?
    Yes, the range can be increased or decreased after understanding the voltage scaling method described.
  • How is the contrast of the LCD display adjusted?
    Contrast adjustment is done through a 5K potentiometer connected between +5V and Gnd.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter