The circuit in figure 1 is an extension of a previous idea on how to use an analogue input in a microcontroller lacking a built-in ADC, and it takes into account tricks from another idea on how to drive a seven-segment LED display without external switching transistors (reference 1 and reference 2). 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.

EDNAOL 2016JUN06 AN 03Fig1__Figure 1: __By using common-anode and common-cathode, seven-segment LED displays, the I/O ports of a microcontroller can drive the displays without using additional external components.

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.6V. 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 analogue 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 analogue 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 analogue channels. When one analogue- 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.

EDNAOL 2016JUN06 AN 03Fig2Figure 2: You can expand the number of voltages measured in Figure 1 by multiplexing additional transistor circuits.

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 5V 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 –5V with respect to ground of the PC's RS 232 port. Listing 1 gives a practical example with a PIC16F84A-20P. It is not optimised but is fully commented to make it easy to translate to another Microchip midrange device, such as a PIC16F628A, that supports a frequency of 20MHz with more I/O lines.
References

  1. Benabadji, Noureddine, "Microcontroller, JFET form low-cost, two-digit millivoltmeter,"EDN, June 22, 2006, pg 71.
  2. Benabadji, Noureddine, "Ultra low-cost, two-digit counter features few components,"EDN, Aug 17, 2006, pg 69.


This article is a Design Idea selected for re-publication by the editors. It was first published on May 10, 2007 in EDN.com.