SPI DAC + Audio test
Author: Eric Brombaugh
What it is:
This is a simple sawtooth generator written in Verilog which uses one of the four channels in the LT2624 quad SPI (serial peripheral interface) DAC. It comprises a SPI output interface, a ramp generator and an LED driver. The LED driver is just for gee-whiz diagnostics - a quick check that the design actually loaded and is running.
How it works
The entire system runs synchronously from the 50MHz clock. The SPI interface divides that by 2 to get a 25MHz SPI clock which allows it to work off of both edges without DDR foolishness. A simple state machine controls the loading and shifting of a 24-bit parallel-serial shift register. The DAC needs a 24-bit SPI transfer, plus one additional cycle thrown in so the CS line can pulse. This gives 25 SPI clocks per transfer for a 1MHz overall rate. Every time the SPI interface cycles, an enable is generated to get the next sample of data.
Data comes from a simple 12-bit up counter. When an enable pulse is received from the SPI interface, the counter advances by one. With each enable pulse the value rises from 0 to 4095 and starts over, giving us a clean sawtooth at 244.14Hz.
The 8 LEDs are driven with a binary counter similar to the counter used for the sawtooth generator. The least-significant 20 bits of this 28 bit, counter aren't used because they would be toggling too quickly to see.
How:
To get immediate satifaction, simply do the following :-
- Open 'impact'
- Open the '.ipf' file
- Right click on the xc3s500e device shown
- Select 'program' from the drop down menu
- Click OK, once imPACT has found the programmer
For the full project, do the following :-
- Open the '.ise' file
- You'll see a Design summary
- Double click any of the .v files to see the Verilog code
- Double clicking the .ucf file will open the 'User constraints editor' after it's synthesised the design.
- Then, to 'build, synthesise and program' the code
- Expand the 'Generate programming file process (It's usefull to expand the other Processes so you can watch the flow) as it works
- Right click on 'configure device'
- Select 'run'
- After a while impact will open and repeat as above to 'program' the FPGA
Going further:
This design could easily be extended in several ways:
- Change the logic used to generate the sawtooth: Square waves are easily generated by using the most significant bit of the counter. Triangle waves can be created with logical combinations of the sawtooth data bits.
- Use the on-board switches to dynamically select the pulse width.
- Use the on-board switches to dynamically select one of several different waveforms.
Files:
The project files are all in the .zip file below. The files should extract to a directory called 'spi_test'.
SPI_TEST.ZIP
FPGA Synth