[ݳXȲέp


PIC與AD9850使用問題

非8051系列的單晶片軟硬體請在此區討論(CPU介面周邊,或MICRO CHIP等....)

版主: charlesliao

PIC與AD9850使用問題

文章ahao1022 發表於 週一 8月 05, 2019 11:06 pm

各位版大好
小弟最近使用microchip PIC18f26k20搭配AD9850模組使用

使用條件:AD9850使用串行模式 單晶片使用SPI與模組進行協定


下列是我使用MPLAB X IDE MCC 開發介面main檔(若有不清楚清鍵有詳細壓縮檔及電路圖檔)
AD9850-1.zip
(209.27 KB) 被下載 214 次
.png


#include "mcc_generated_files/mcc.h"

/*
Main application
*/

//-----------------------------------------------------------------------------
// AD9850 serial mode rest
//-----------------------------------------------------------------------------
void AD9850_rest_serial(void)
{
SCK_SetLow();//AD9850 WCLK
FQUP_SetLow(); //AD9850 FQUD
//rest single
AD9850_Rest_SetLow();
AD9850_Rest_SetHigh();
AD9850_Rest_SetLow();
//WCLK single
SCK_SetLow();//AD9850 WCLK
SCK_SetHigh();
SCK_SetLow();
//fQUD single
FQUP_SetLow();//AD9850 FQUD
FQUP_SetHigh();
FQUP_SetLow();

}
//-----------------------------------------------------------------------------
// Write commands and data to the AD9850 (serial port)
//-----------------------------------------------------------------------------
void AD9850_wr_serial(unsigned int y)
{
char i,w;
long int a,b,c,x;
//Calculate the HEX value of the frequency
a=4294967296/125000000;//2^32/125M
b=y/1000000;
c=b*a;

//write w4 data 0~7
w=(c>>0);
for(i=0;i<8;i++)
{
x=SPI_Exchange8bit('w');
x>>i&0x01;
SCK_SetHigh();//AD9850 WCLK
SCK_SetLow();//AD9850 WCLK
}
//write w3 data 8~15

w=(c>>8);
for(i=0;i<8;i++)
{
x=SPI_Exchange8bit('w');
x>>i&0x01;
SCK_SetHigh();//AD9850 WCLK
SCK_SetLow();//AD9850 WCLK

}
//write w2 data

w=(c>>16);
for(i=0;i<8;i++)
{
x=SPI_Exchange8bit('w');
x>>i&0x01;
SCK_SetHigh();//AD9850 WCLK
SCK_SetLow();//AD9850 WCLK

}
//write w1 data
w=(c>>24);
for(i=0;i<8;i++)
{
x=SPI_Exchange8bit('w');
x>>i&0x01;
SCK_SetHigh();//AD9850 WCLK
SCK_SetLow();//AD9850 WCLK

}
//write w0 data 注意
w=c;
for(i=0;i<8;i++)
{
x=SPI_Exchange8bit('w');
x>>i&0x01;
SCK_SetHigh();//AD9850 WCLK
SCK_SetLow();//AD9850 WCLK
}
//Move in enable
FQUP_SetHigh();//AD9850 FQUD
FQUP_SetLow();

}


void main(void)
{
// Initialize the device
SYSTEM_Initialize();
AD9850_rest_serial();
AD9850_wr_serial(1000); //Serial write 1000Hz program
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
// Use the following macros to:

// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();

// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();

// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();

// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();

while (1)
{
// Add your application code
}
}
/**
End of File
*/
ahao1022
 
文章: 3
註冊時間: 週五 4月 27, 2018 9:42 pm

回到 其他類單晶片--相關的軟硬體討論區

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 6 位訪客