Microcontroller Functions as Voltmeter

Microchip PIC16F84A-20P PIC16F628A

PIC microcontroller and FETs enable a four-digit voltmeter.

Noureddine Benabadji, University of Sciences and Technology, Oran, Algeria; Edited by Charles H Small and Fran Granville -- EDN, 5/10/2007
 

Microcontroller functions as voltmeter

The circuit in Figure 1 is an extension of a previous Design Idea on how to use an analog input in a microcontroller lacking a built-in ADC, and it takes into account tricks from another Design Idea on how to drive a seven-segment LED display without external switching transistors. This circuit adds a serial link and needs only a twisted pair to send each measurement to a compatible PC. The serial link was tested using a Microsoft Hyper Terminal configured at 115,200 baud; at 8, N, and 1; and with no flow control.

Briefly, the software drives one seven-segment LED display at a time, through lines RA0 and RB7. Setting the RA0 output high and RB7 as the input activates common-anode display DS3. Setting the RA0 output low and RB7 as the input activates common-cathode display DS2. With RA0 as the input, setting the RB7 output high activates common-anode display DS1, and, with RA0 as the input, setting the RB7 output low activates common-cathode display DS0. While successively activating one display, only one line, RB0 to RB6, is configured as an output to drive one LED segment. This design no longer is limited to a VDDof 3V or lower, because LEDs inversely connect in parallel, so the forward voltage of one diode limits the reverse voltage of the other. Using a red-diode display requires 1.6 V.
 

Figure 2 illustrates the new aspects of this Design Idea

Figure 2 illustrates the new aspects of this Design Idea. Q1, R5, and R6 act as an equivalent variable resistor, RX, which charges capacitor C3. Instead of pulling RX to ground, just connect it to one I/O— RB0, for example— of the microcontroller. If RB0 is an output with a low state, then the first analog channel activates, and the measure subroutine counts pulses of charge as high as 66% of VDD; then, a look-up table converts this time delay to a three-digit millivolt value. To expand the number of analog inputs, you can connect as many as seven variable-resistor circuits in a parallel configuration—that is, each one connects between C3 and one I/O line, RB1 through RB7. Notice that I/O lines connect to the display and also activate or deactivate the analog channels. When one analog- input channel activates through one I/O line with the output in the low state, the other lines are high-impedance inputs, which deactivate all other channels. Meanwhile, the display is off.

The circuit in Figure 1 also adds a simple serial link with no added components. If you connect two I/O lines, RA1 and RA2, configured as outputs, to RXD (Pin 2) and GND (Pin 5) of an RS‑232 connector, you can reproduce, by software, positive and negative voltages with respect to ground of the PC’s RS‑232 port. When RA1 is high and RA2 is low, then RXD has a positive voltage of 5 V with respect to ground of the PC’s RS‑232 port. When RA1 is low and RA2 is high, then RXD has a negative voltage of –5 V with respect to ground of the PC’s RS‑232 port. Listing 1 gives a practical example with a PIC16F84A-20P. It is not optimized but is fully commented to make it easy to translate to another Microchip midrange device, such as a PIC16F628A, that supports a frequency of 20 MHz with more I/O lines.

EDN

You may have to register before you can post comments and get full access to forum.
Fragments of discussion:Full version of discussion »
  • hex file, please? thank you hex dosyasını verebilirmisiniz? Teşekkьr ederim
  • thank you where is the hex file
  • Hi, This is a very interesting low parts count way of driving 7 Seg displays, however "Listing 1" does not appear to exist. Is it available or is it a link error?Regards
  • Hi all. Hex-file was not given in the original article, but the source code is in Listing 1. See the attachment.
  • hi. how can i conver or prodect hex file from attached fil
  • Greetings. You need a C-compiler that supports microcontroller family PIC16F from Microchip. Possibly suitable MPLAB Integrated Development Environment (MPLAB IDE).
Full version of discussion »
EMS supplier