Electronic Design

Tiny microcontroller provides 4-channel A/D conversion for a PC serial port

Microchip’s PIC12C671 is a lowcost 8-pin microcontroller that has everything needed to perform a four-channel 8-bit analog-todigital conversion without external components. To create a plug-in four-channel analog-to-digital converter for a PC, the circuit in Figure 1 uses a PC’s serial port to power and communicate with the PIC12C671.

Pin 4 of the PC’s serial port supplies power to the microcontroller through a 5-V reference device. The PIC12C671’s VDD also serves as an A/D conversion reference voltage. The PC sends commands to the microcontroller through pin 7, and the device sends information back to the PC through pin 2. Figure 2 shows the details of the communication protocol.

Once the 12C671 powers up, it will count how many pulses are generated on the serial port’s pin 7 within 16 ms. If there’s one pulse, then channel 0 is selected for the A/D conversion. If the pulse count is 2, 3, or 4, channel 1, 2, or 3 will be selected. After the channel information is received, the microcontroller will start to perform the A/D conversion for the selected channel. Then the 8-bit A/D conversion data will be sent back to PC through the microcontroller's pin 2.

Since the PC may have a different serial port baud rate, it’s necessary to send a training pulse to the PC before starting transmission of A/D conversion data. The PC program contains a loop to accept the training pulse. The number of loop iterations that execute before the training pulse reception is completed determines the baud rate used for reception of the A/D conversion data from the microcontroller.

Listing 1 is the assembly program for PIC12C671 microcontroller and Listing 2 is the C program for the PC. The C program will read four inputs every second and will display the results on the PC screen.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish