Test Ideas: Program the SPI bus with a DIO module
Function libraries, called at run time, let you change instruments without changing code.
By William Drago, L-3 Communications, Hauppauge, NY -- Test & Measurement World, 4/1/2010 12:00:00 AM
|
At L-3 Communications, we use PLLs (phase-locked loops) in many of our products to generate precise, stable signals. To program these parts, we must load several control registers with digital words that correspond to the desired PLL output parameters. The PLLs, like many programmable devices, use the SPI (Serial Peripheral Interface) bus, which consists of four lines. Because we need only write data to the PLLs, we need just three lines for the SPI; a fourth line, which is not part of the SPI, ties to the PLL's lock detect output to indicate that the PLL is locked.
|
Figure 1 shows an SPI bus timing diagram. Data on the MOSI (master out, slave in) line is clocked into the PLL when the CS (chip select) line is enabled (low). By “bit-banging” the correct sequence on the clock and data lines, while enabling the appropriate CS line, you can emulate the SPI bus.
Just about any DIO (digital I/O) interface lets you emulate the SPI bus. You can generate the bus signals by writing to your PC's serial port or to a parallel port, if you have one. That may be acceptable for lab tests, but in production or in a busy lab environment, a dedicated DIO interface will be more reliable, more versatile, and ultimately, less expensive.
|
In our lab, we shuffle equipment around frequently enough to warrant the use of laptop computers over desktop machines. Because laptops have limited expansion capabilities, we rely on USB devices in place of traditional PCI interface cards. Figure 2 shows the setup we use to program the PLLs using a USB DIO module. We use the Measurement Computing USB-1208 data-acquisition module, but most USB data-acquisition or DIO modules should let you program a device through their SPI bus interface. The USB-1208 provides 16 DIO channels and eight single-ended analog input channels (or four differential-input channels). The analog inputs come in handy when you need to measure analog signals. Nearly every test fixture we build has a USB data-acquisition or DIO module.
Figure 3 shows the software architecture. Each path (A and B) contains the same functions but with different DIO function libraries. View an image showing part of the code, written in Agilent Vee Pro.
![]() Figure 3. External function libraries let you change instrument hardware without recoding your main program. |
At the time I wrote the software, we needed the ability to use DIO modules from either Measurement Computing or National Instruments without changing the code in my main program. Manufacturers provide function libraries that provide an interface between the main program and their instruments. Unfortunately for us test engineers, manufacturer-supplied function libraries work for products from that manufacturer only.
Adding an abstraction layer between my main program and the manufacturer's function libraries eliminates changing the main program's code even when changing module manufacturers. This layer makes all DIO and data-acquisition modules look the same to the main program. By using the abstraction layer, I just needed to write a function library for each device and load the appropriate library at run time.
The libraries in Figure 3 have functions such as Write_Word(), Read_Word(), Write_Bit(), and Read_Bit() that correspond directly to the functions in the .NET library provided with the USB-1208. To build the serial data stream, I wrote the Shift_Out() function, which works by putting the Bit_Out() function in a loop to generate SPI bus clock and data signals.
No related content found.
- 0 rated items found.
Datasheets.com Electronic Parts & Inventory Search
185 million searchable parts
- Part Number
- Description
- Inventory
- Products
- Manufacturers


























