Difference between revisions of "Waveform Generation with AD9833, and SPI"
DanJohnson (talk | contribs) |
DanJohnson (talk | contribs) |
||
Line 1: | Line 1: | ||
[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz. It has two frequency registers and two phase registers that can be written to and output from the VOUT pin. This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control. A connection diagram for the AD9833 is given to the right. The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3). |
[[Image:AD9833Connsmall.jpg|right]]The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz. It has two frequency registers and two phase registers that can be written to and output from the VOUT pin. This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control. A connection diagram for the AD9833 is given to the right. The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3). |
||
<br> |
|||
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use. The following code should be included in your program. |
|||
<br><br> |
|||
#use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1) |
|||
<br> |
|||
The first three arguments determine which three pins we will be using: DO is the "SDATA" pin of the AD9833, CLK is the "SCLK" pin, and ENABLE is the "FSYNC" pin. The next argument states that the max number of bits in one transfer is 16. The next argument specifies that the PIC is the master and the AD9833 is the slave. The AD9833's FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first. The SCLK pin is also specified to be kept high when not in use. After this initial setup, the SPI communication is quite straightforward. We simply use the function '''spi_xfer()''' whenever we want to send information via SPI to the AD9833. |
|||
<br> |
|||
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want. Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below. |
Revision as of 10:42, 9 December 2008
The AD9833 is a programmable waveform generator capable of creating sine, triangular, or square wave outputs in a frequency range of 0 to 12.5 MHz. It has two frequency registers and two phase registers that can be written to and output from the VOUT pin. This chip is perfectly suited for use with the PIC 18F4520, as it uses SPI communication for its setup and control. A connection diagram for the AD9833 is given to the right. The MCLK pin is tied directly to the oscillator of the PIC, and the three SPI communication lines are connected to three I/O pins on the PIC (in this case pins A1, A2, and A3).
In order to establish communication between the PIC and the AD9833, we need to set up the SPI for the pins we wish to use. The following code should be included in your program.
#use spi(DO = PIN_A3, CLK = PIN_A2, ENABLE = PIN_A1, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)
The first three arguments determine which three pins we will be using: DO is the "SDATA" pin of the AD9833, CLK is the "SCLK" pin, and ENABLE is the "FSYNC" pin. The next argument states that the max number of bits in one transfer is 16. The next argument specifies that the PIC is the master and the AD9833 is the slave. The AD9833's FSYNC pin is active low, and it accepts the most significant bit (MSB) of each transfer first. The SCLK pin is also specified to be kept high when not in use. After this initial setup, the SPI communication is quite straightforward. We simply use the function spi_xfer() whenever we want to send information via SPI to the AD9833.
Now that we can talk to the waveform generator, we need to know what it needs to be told to produce what we want. Each of the 16 bits transferred has a meaning, and these meanings are described in the Table below.