[ Function Generator with USB Interface ]

Project Description - Operation Details

Project Description
Source Code
Schematics
Screenshots
Pictures
Presentations and Papers
Home

The operation of the system is relatively straightforward, though some precautions have to be taken due to the quirky nature of the DevaSys USB board.

Hardware Assembly and Description

This is rather simple: first, the PIC and its supporting hardware must be connected to an external power supply that can provide +5V, +10V, and -10V. The positive and negative 10V supplies are necessary for providing a voltage reference and supply to the DAC-08 chip that is used in the function generator, as well as acting as a supply to the 741 op-amp. Once that is done, and the power is turned on, the USB protoboard can then be attached to the computer. For some strange reason, if the protoboard is connected first, then the PC cannot open an instance of the device. Once the hardware is connected, the GUI can be activated.

On the breadboard, there are several annunciator LEDs connected directly to the PIC; one of these indicates when an I2C interrupt has occurred, another for when the PIC is generating a waveform, and the last is free for the PC to flash if need be. A bargraph LED array is also connected to one of the PIC's output ports (PORTD), which is used to display the byte codes that are sent to the DAC to create the output voltages.

The PIC itself is connected to a 10MHz crystal oscillator, which is scaled down internally to 2.5MHz. This oscillator also serves as the reference for the timers that are used to achieve the frequencies of the waveforms.

Low Level Operation of the Function Generator

First off, the low level interface between the PIC and the PC relies on I2C and a command set. Any program implementing this command set and the command protocol can interact with the slave PIC's firmware in such a fashion as our Win32 GUI. Each command sent to the PIC must conform to the following specification:

1. Every command sent must be five bytes in length, otherwise erratic behavior will result.

2. The command must have the following format:
Byte 0 Bytes 1-4
Command Request Command Parameter

Where the Command Request is a command constant that is defined by the table in the next point, and the Command Parameter is four additional bytes, and when it is interpreted as a long or short integer, it is to be treated in big-endian order.

3. The command request must be one of the following:
Command Value Name Summary
CMD_STOP 00h Stop Oscillator Makes the PIC stop generating a waveform. The parameter is ignored.
CMD_START 01h Start Oscillator Makes the PIC perform all internal initialization for generating a wave, then begins waveform generation. The parameter is ignored.
CMD_SET_FREQ 02h Set Frequency Sets the waveform frequency. The parameter is interpreted as an unsigned long. This value varies depending on the wave type.
CMD_SET_AMP 03h Set Amplitude Sets the waveform amplitude. The parameter is interpreted as an unsigned char, and only the first byte of the parameter is used. This value ranges from 1 to 10.
CMD_SET_OFFSET 04h Set DC Offset Sets the DC offset voltage. The parameter is interpreted as a signed char, meaning only the first byte is used, and can range from -2 to 4.
CMD_SET_PHASE 05h Set Phase Shift Sets the phase shift, in degrees. The parameter is interpreted as a signed short integer, therefore the first two bytes are used. This value can range from -180 to 180, and only applies to sine waves.
CMD_SET_WAVE 06h Set Wave Type Sets the wave type, that is, whether it is sine, square, triangle, or sawtooth. The parameter is interpreted as a signed char, and may take on the following values: 0 = Sine, 1 = Square, 2 = Triangle, 3 = Sawtooth. The first byte in the parameter is used.
CMD_FLASH 07h Flash LED Toggles the state of an LED connected to the PIC for debugging purposes or anything else that may be desired.

All of the necessary constants are defined in piccmd.h, which is provided with the source code.

GUI Operation of the Function Generator

Here's a screenshot of the Windows GUI:

It was kept as simple as possible to make entering a new waveform, well, simple. The wave type is set by checking off the proper option button. The scrollbars on the far side of the window are for entering the wave parameters; the blue wave in the display changes as these parameters change, as does the formula on the left side. The red wave, if "Show Constant Wave" is checked, only changes in frequency and amplitude; this allows you to compare the phase shift and DC offset against it. Phase shift is only used for sine waves, however -- if you have selected any of the other wave types, that scrollbar is disabled.

Once the desired waveform and waveform parameters are set, you can click Generate to send the correct commands to the PIC and start generating the wave; the button is grayed out if the USB board is not connected (if this happens, and you get the warning at startup about the board not being found, just connect the board and go to File -> Reconnect USB). The Generate button becomes a Stop button once generation begins, and generation can be stopped by clicking it again. The Play button will allow you to play the waveform back as a one-second tone over the speakers; you can also print it out just as you see it on the screen by going to File -> Print. Finally, you can output a text file by using File -> Save which contains all of the amplitudes necessary to reconstruct the waveform. This file can then be loaded into a program like MATLAB and worked with.

Finally, using the Options dialog box, which is under the Tools menu, you can choose to switch from the slave I2C PIC to a I2C DAC. The recommended DAC to use is the Maxim MAX517 DAC, since the control bytes that are sent out to the DAC before the code correspond to those assigned to this DAC, and the amplitude selection changes to a range corresponding to the output range of that DAC (which has a TTL voltage range). Due to the signal delay on the USB bus, coupled with the additional need to go out to the I2C chip, you will not get an accurate representation of the waveform, however.

 

 

Created by Rick Coogle.