syamin0712
Member level 1
Hi everyone,
I need some help for those who have experience in generating sine waveforms using AD9833 and PIC18F4580.
This is my first experience using SPI to code the sine waveform from PIC18F4580 as a master and AD9833 as the slave.
I set the pin between PIC18F4580 and AD9833 as follows:
RC4/SDI/SDA ---- SDATA
RC3/SCK/SCL ---- SCLK
RA5/SS ---- FSYNC
Does it correct the pin that I set between PIC18F4580 and AD9833?
To generate the 2MHz: By using the formula in AD9833 data sheet page 15, while assuming MCLK is 40MHz. I have set the FREQ register to 13421773 decimal number (110011001100110011001101) in binary.
Also, is it correct the MCLK that I use if im using XTAL 10MHz and enable HSPLL so that it becomes 40MHZ?
Could anybody check what is wrong with my code?Here, Im using CCS C compiler to write my code.
Or is there any additional code that I have to write?
Here is the link for the screen after i compile my code
https://obrazki.elektroda.pl/9098671100_1440397794.png
When I compile these, two errors appear:
The function of #use spi shown an error
"USE parameter value is out of range. Not a number. PIN_C4"
and at void main() it shown "I/O error 131".
What is meant by that statement?
I need some help for those who have experience in generating sine waveforms using AD9833 and PIC18F4580.
This is my first experience using SPI to code the sine waveform from PIC18F4580 as a master and AD9833 as the slave.
I set the pin between PIC18F4580 and AD9833 as follows:
RC4/SDI/SDA ---- SDATA
RC3/SCK/SCL ---- SCLK
RA5/SS ---- FSYNC
Does it correct the pin that I set between PIC18F4580 and AD9833?
To generate the 2MHz: By using the formula in AD9833 data sheet page 15, while assuming MCLK is 40MHz. I have set the FREQ register to 13421773 decimal number (110011001100110011001101) in binary.
Also, is it correct the MCLK that I use if im using XTAL 10MHz and enable HSPLL so that it becomes 40MHZ?
Could anybody check what is wrong with my code?Here, Im using CCS C compiler to write my code.
Or is there any additional code that I have to write?
Code:
#device PIC18F4580
//configure a 10MHz crystal to operate at 40MHz, // System setting - Use 10MHz XTAL with PLL. New Freq: 10MHz x 4 = 40Mhz.
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#define OSC_PLL_ON
#use delay(clock=10000000)
#use spi(DO= PIN_C4 , CLK = PIN_C3, ENABLE = PIN_A5, BITS = 16, MASTER, ENABLE_ACTIVE = 0, MSB_FIRST, IDLE = 1)
//DO=SDATA/SDA pin,
//CLK=SCLK/SCK pin,
//ENABLE=FSYNC/SS pin,
//BITS=16 is max num of bit in one transfer is 16,
//MASTER=PIC is master and AD9833 is slave,
//ENABLE_ACTIVE = 0 is FSYNC pin is active low,
//MSB_FIRST is accept MSB of each transfer first
//IDLE=1 is FSYNC always high when not in use
void main()
{
while(1)
{
// activate control register; both LSB & MSB FREQ write consequtively; enable reset; enable sinewaveform signal
spi_xfer(0b0010000100000000);
//on FREQ0 for generate 2MHz if using MCLK=40MHz ; 13421773 in decimal
spi_xfer(0b100110011001101);
spi_xfer(0b0100001100110011);
//on PHASE0 with zero phase shift
spi_xfer(0b1100000000000000);
//activate control register; both LSB & MSB FREQ write ; disable reset; enable sinewaveform signal
spi_xfer(0b0010000000000000);
}
}
Here is the link for the screen after i compile my code
https://obrazki.elektroda.pl/9098671100_1440397794.png
When I compile these, two errors appear:
The function of #use spi shown an error
"USE parameter value is out of range. Not a number. PIN_C4"
and at void main() it shown "I/O error 131".
What is meant by that statement?
Last edited by a moderator: