C# application controls simple ADC
This Design Idea describes a simple and low-cost ADC that you control using the serial port of a PC running Windows XP/Vista. The hardware comprises Microchip’s 12-bit SAR (successive-approximation-register) MCP3201 ADC, which attaches to the serial port of the PC through the RTS, CTS, and DTR lines (Figure 1).
The circuit uses an SPI (serial-peripheral-interface)-compatible interface to communicate with the MCP3201. The MAX232 chip transforms the RS-232 levels into TTL-compatible levels that the MCP3201 converter requires to operate. The analog signal comes through the IN+ pin of the MCP3201. The output digital stream of bytes on the DOUT pin goes through the CTS line to the serial port of the PC. The RTS line of the serial port provides clock pulses that go through the CLK pin of the converter. Each separate bit appears on DOUT on the falling edge of CLK, and the application should latch the bit on the rising edge of the clock pulse.
The DTR line produces the signal that frames the conversion process. The signal must be low while the conversion is in progress (Figure 2).
The meaningful bits, with MSB first, appear on DOUT after the third CLK pulse goes low. It implies that, if you miss the first three data bits, the software would programmatically realize it. The software that controls the device is written in free Microsoft Visual C# 2008 Express Edition. It uses a built-in SerialPort component that allows you to get full control over the serial port of the PC. You implement the software as a simple console application containing Listing 1. The program is uncomplicated, so you can easily modify it. For instance, you could send the data from ADC over the Internet or pass it into Microsoft Excel or Microsoft Access for further processing.
You can improve the simplified circuit in Figure 1 for higher accuracy by placing a lowpass filter in the analog-signal chain. You should also always use a bypass capacitor with the MCP3201. Place a capacitor with a recommended value of 1 µF as close as possible to the device’s pin. You can also replace the MCP3201 with a similar SAR ADC that works with an SPI-compatible interface. For instance, you may use an LTC1286 or an LTC1297 device from Linear Technology. If you plan to use a different ADC, you must make some changes in the hardware and software. The changes necessary to the hardware are obvious, and you may need to change the software source code of the application to correct the for (…) loop statement according to the timing diagram of the selected part.