显示标签为“采样率”的博文。显示所有博文
显示标签为“采样率”的博文。显示所有博文

2008年10月14日星期二

测试金点子:用串行端口控制ADC

编辑笔记:工程师通常需要一个与PC链接的简单测量电路。如果你没有能力去买一个低速的数字化仪,那么你可以自己用两个连接到PC串行端口的IC做一个数字化仪。数字化仪的吞吐率主要取决于操作系统的性能,处理器速度,以及内存。文中作者能在2.4G奔腾处理器,512M内存,WinXP操作系统配置的PC上做到250Sa/s。高速处理器也就意味着高采样率。通过计算一秒钟内转换的二进制数,你就能够计算出你的吞吐率。







Engineers often need simple measurement circuits that connect to a PC. When you don't have the resources to buy a digitizer for low-speed signals, you can build one yourself with just two ICs connected to a PC's serial port. The throughput rate of the digitizer depends mainly on the performance of the PC's operating system, processor speed, and memory. I was able to achieve 250 samples/s with a 2.4-GHz Pentium-based PC with 512 Mbytes RAM running Windows XP. Faster processors will produce higher sample rates. You can calculate your throughput rate by counting the number of conversions for 1 s.
Do you have a test or design idea you'd like to share? Publish it here and receive $150. Send us your ideas.
The circuit in Figure 1 shows that you can use an MCP3201 12-bit successive-approximation ADC (analog-to-digital converter) with a MAX232 RS-232 interface IC. Using an application written in C#, you can get data into a PC that runs Windows XP or Vista. (Click to download the source code.)
Figure 1. A MAX232 IC interfaces an MCP3201 ADC to a PC’s serial port.The MCP3201 uses RTS (ready-to-send), CTS (clear-to-send), and DTR (data-terminal ready) serial-port lines to communicate with a PC. Its standard SPI (serial peripheral interface) port communicates to the MAX232. The analog signal connects to the MCP3201's IN+ pin, and the MAX232 converts RS-232 signal levels to TTL-compatible levels.
The digital output stream from the DOUT pin goes through the MAX232 to the serial point on the IC's CTS line. The RTS line provides clock pulses to the ADC's CLK (clock) pin. Each separate bit appears at the DOUT pin on the falling edge of the CLK signal. Thus, a software application must latch the bit on the rising edge of the clock pulse. Finally, the DTR line produces the CS (chip select) signal that frames the conversion process. The CS bit must be low while the conversion is in progress. Figure 2 shows a timing diagram of the process.
Figure 2. Software latches 15 bits, discarding the first three after reading the data.In Figure 2, the valid data bits (most-significant bit first) appear on the DOUT line after the third CLK pulse goes low. Thus, you must use software to discard the first three bits after reading the data.
The software application is written in free MicrosoftVisual C# 2008 Express Edition. The built-in SerialPort component in C# provides full control over the port. The software is implemented as a simple console application. You don't need a device driver to use a serial port with this code.
You can easily repeat or modify the source code to fit your application. For example, you can send the data from the ADC to another location over the Internet or pass data to Excel or another application for analysis.
You can also improve on the hardware design in Figure 1. For example, placing a low-pass filter in front of the ADC will reduce noise and thus reduce errors caused by aliasing. Always use a bypass capacitor on the MAX232's VCC pin. Place the 1-μF capacitor (recommended value) as close as possible to the device pin.
You can replace the MCP3201 with a similar successive-approximation ADC that also has an SPI-compatible interface. For instance, you may use a Linear Technology LTC1286 or LTC1297. If you plan to use a different ADC, you will need to make some hardware modifications, so check the manufacturer's data sheet for details. Instead of a MAX232 line driver, you can use similar parts such as MAX225 or MAX233. These parts don't require any external components, thus simplifying the design.
If you use other hardware, you may need to modify the application source code, too. As an example, you may need to change the for (int i = 0; i < 15; i++) loop statement in the source code according to the timing diagram of the part you select.