一、基于單片機的信號發生器設計方案
信(xin)號(hao)(hao)發生器(qi)用于調節射(she)頻匹配電路,可以(yi)自(zi)行設(she)計(ji),一般普通的信(xin)號(hao)(hao)發生器(qi)需要輸(shu)出正弦波、方波、三角波以(yi)及鋸齒波等信(xin)號(hao)(hao),可通過(guo)按鍵(jian)調節信(xin)號(hao)(hao)的頻率以(yi)及信(xin)號(hao)(hao)的幅度,其具體的設(she)計(ji)方案如下(xia):
1、總體方案設計
信(xin)(xin)號(hao)(hao)(hao)發(fa)(fa)(fa)生器發(fa)(fa)(fa)送出(chu)去(qu)的(de)(de)是(shi)模(mo)擬信(xin)(xin)號(hao)(hao)(hao),而單片(pian)機輸(shu)出(chu)的(de)(de)是(shi)數(shu)字信(xin)(xin)號(hao)(hao)(hao),因此在設計信(xin)(xin)號(hao)(hao)(hao)發(fa)(fa)(fa)生器系(xi)統(tong)時,需(xu)要使用(yong)(yong)(yong)(yong)到(dao)數(shu)模(mo)轉(zhuan)換(huan)芯片(pian),可(ke)選擇數(shu)模(mo)轉(zhuan)換(huan)芯片(pian)DAC0832,然后再(zai)利用(yong)(yong)(yong)(yong)運算放(fang)(fang)大器將(jiang)DAC0832輸(shu)出(chu)的(de)(de)電(dian)流信(xin)(xin)號(hao)(hao)(hao)轉(zhuan)換(huan)成(cheng)電(dian)壓(ya)信(xin)(xin)號(hao)(hao)(hao)。這(zhe)樣信(xin)(xin)號(hao)(hao)(hao)發(fa)(fa)(fa)生器便(bian)輸(shu)出(chu)了模(mo)擬電(dian)壓(ya)。系(xi)統(tong)要輸(shu)出(chu)各(ge)種波形信(xin)(xin)號(hao)(hao)(hao),則要求DAC0832在運放(fang)(fang)的(de)(de)作用(yong)(yong)(yong)(yong)下,在不同(tong)時間點輸(shu)出(chu)不同(tong)的(de)(de)電(dian)壓(ya)值(zhi),再(zai)將(jiang)這(zhe)些電(dian)壓(ya)值(zhi)連接起來(lai),便(bian)構(gou)成(cheng)了相應的(de)(de)波形信(xin)(xin)號(hao)(hao)(hao)。而要得到(dao)不同(tong)的(de)(de)電(dian)壓(ya)值(zhi),則單片(pian)機需(xu)要將(jiang)8位(wei)I/O口(kou)接到(dao)DAC0832芯片(pian)的(de)(de)8位(wei)數(shu)據(ju)(ju)信(xin)(xin)號(hao)(hao)(hao)輸(shu)入(ru)端,單片(pian)機通(tong)過(guo)改變(bian)(bian)8位(wei)I/O口(kou)的(de)(de)數(shu)字信(xin)(xin)號(hao)(hao)(hao),便(bian)可(ke)以在DAC0832以及運放(fang)(fang)的(de)(de)作用(yong)(yong)(yong)(yong)下,得到(dao)不同(tong)的(de)(de)電(dian)壓(ya)值(zhi),再(zai)在時間的(de)(de)作用(yong)(yong)(yong)(yong)下形成(cheng)不同(tong)的(de)(de)波形信(xin)(xin)號(hao)(hao)(hao)。波形信(xin)(xin)號(hao)(hao)(hao)頻率(lv)的(de)(de)的(de)(de)變(bian)(bian)化(hua)可(ke)通(tong)過(guo)改變(bian)(bian)單片(pian)機8位(wei)I/O輸(shu)出(chu)口(kou)的(de)(de)數(shu)據(ju)(ju)變(bian)(bian)化(hua)率(lv)來(lai)實現。
波形信(xin)號(hao)的(de)(de)(de)幅度由(you)DAC0832的(de)(de)(de)參考電(dian)(dian)壓(ya)(ya)VREF來決(jue)定,為(wei)了確保VREF的(de)(de)(de)大小可變(bian)(bian)(bian),本系統使用到了芯片PCF8591,將PCF8591芯片的(de)(de)(de)模擬電(dian)(dian)壓(ya)(ya)輸(shu)出端接在DAC0832的(de)(de)(de)VREF上,通(tong)過(guo)(guo)改變(bian)(bian)(bian)PCF8591模擬電(dian)(dian)壓(ya)(ya)輸(shu)出值(zhi)便可改變(bian)(bian)(bian)VREF值(zhi),從(cong)而改變(bian)(bian)(bian)波形信(xin)號(hao)的(de)(de)(de)幅度值(zhi)。而PCF8591的(de)(de)(de)模擬電(dian)(dian)壓(ya)(ya)輸(shu)出值(zhi)則是尤其I2C總行上的(de)(de)(de)數據所決(jue)定,利用單(dan)片機的(de)(de)(de)I/O口模擬I2C與(yu)PCF8591進行通(tong)信(xin),那么單(dan)片機便可通(tong)過(guo)(guo)I/O口控制VREF電(dian)(dian)壓(ya)(ya)的(de)(de)(de)變(bian)(bian)(bian)化,從(cong)而控制波形的(de)(de)(de)幅度變(bian)(bian)(bian)化。
2、系統硬件設計
(1)晶振電路設計
單片機(ji)(ji)穩(wen)定(ding)(ding)工(gong)作則需要穩(wen)定(ding)(ding)的(de)(de)(de)(de)時(shi)鐘信號(hao)(hao),而時(shi)鐘信號(hao)(hao)則是由晶(jing)(jing)(jing)振(zhen)(zhen)電(dian)(dian)(dian)路產(chan)生,因此(ci)晶(jing)(jing)(jing)振(zhen)(zhen)電(dian)(dian)(dian)路設(she)計的(de)(de)(de)(de)好壞直(zhi)接影響(xiang)到(dao)最小系(xi)統的(de)(de)(de)(de)穩(wen)定(ding)(ding)性。單片機(ji)(ji)的(de)(de)(de)(de)18腳和19腳為(wei)晶(jing)(jing)(jing)振(zhen)(zhen)連接輸入腳,將晶(jing)(jing)(jing)振(zhen)(zhen)X1的(de)(de)(de)(de)兩(liang)端連接到(dao)單片機(ji)(ji)18和19腳之(zhi)后便(bian)會產(chan)生時(shi)鐘信號(hao)(hao),此(ci)時(shi)的(de)(de)(de)(de)信號(hao)(hao)會存在(zai)不穩(wen)定(ding)(ding)的(de)(de)(de)(de)問題(ti),需要在(zai)晶(jing)(jing)(jing)振(zhen)(zhen)Y1的(de)(de)(de)(de)兩(liang)端分別外接一個22PF電(dian)(dian)(dian)容(rong)(rong)(rong)C1、C2到(dao)GND,該(gai)電(dian)(dian)(dian)容(rong)(rong)(rong)為(wei)晶(jing)(jing)(jing)振(zhen)(zhen)的(de)(de)(de)(de)匹配電(dian)(dian)(dian)容(rong)(rong)(rong),晶(jing)(jing)(jing)振(zhen)(zhen)匹配了電(dian)(dian)(dian)容(rong)(rong)(rong)之(zhi)后,那么產(chan)生的(de)(de)(de)(de)時(shi)鐘信號(hao)(hao)就比較穩(wen)定(ding)(ding)。出現的(de)(de)(de)(de)頻偏也(ye)是在(zai)20PPM的(de)(de)(de)(de)范圍內。這樣才(cai)能確保系(xi)統時(shi)鐘穩(wen)定(ding)(ding)可靠。
(2)復位電路設計
最(zui)小系(xi)統(tong)除了晶振電(dian)路(lu)之外(wai),還需要(yao)具備復(fu)位(wei)(wei)電(dian)路(lu),單片機上電(dian)后,啟(qi)動的(de)時候(hou),需要(yao)復(fu)位(wei)(wei)電(dian)路(lu)先進行(xing)復(fu)位(wei)(wei),確保(bao)系(xi)統(tong)運(yun)行(xing)的(de)起始(shi)地址(zhi)一(yi)致 ,保(bao)證系(xi)統(tong)工作的(de)穩定(ding)性,復(fu)位(wei)(wei)是利用電(dian)容C3與(yu)R1來實現(xian)的(de)。
(3)波形幅度調節電路設計
為改變系(xi)(xi)統輸(shu)出的(de)(de)波形幅(fu)(fu)度(du)值,本(ben)系(xi)(xi)統使用到了PCF8591芯(xin)(xin)片(pian)(pian)(pian),該芯(xin)(xin)片(pian)(pian)(pian)是(shi)一(yi)個8位CMOS數(shu)據采集器,該芯(xin)(xin)片(pian)(pian)(pian)可(ke)以(yi)(yi)將模(mo)(mo)(mo)擬信(xin)(xin)(xin)號(hao)轉換成數(shu)字信(xin)(xin)(xin)號(hao),再通(tong)(tong)過(guo)I2C數(shu)據總(zong)線將該數(shu)字信(xin)(xin)(xin)號(hao)發送(song)給(gei)單(dan)片(pian)(pian)(pian)機;也可(ke)以(yi)(yi)反過(guo)來,單(dan)片(pian)(pian)(pian)機通(tong)(tong)過(guo)I2C總(zong)線將數(shu)字信(xin)(xin)(xin)號(hao)發送(song)給(gei)PCF8591芯(xin)(xin)片(pian)(pian)(pian),再由該芯(xin)(xin)片(pian)(pian)(pian)進行數(shu)模(mo)(mo)(mo)轉換后(hou),變成模(mo)(mo)(mo)擬電壓再由AOUT腳輸(shu)出。利用這一(yi)原理,本(ben)系(xi)(xi)統為了調節信(xin)(xin)(xin)號(hao)發生器的(de)(de)幅(fu)(fu)度(du)值,將單(dan)片(pian)(pian)(pian)機P2.0和P2.1模(mo)(mo)(mo)擬I2C與PCF8591通(tong)(tong)信(xin)(xin)(xin),這樣(yang)單(dan)片(pian)(pian)(pian)機便可(ke)以(yi)(yi)控制PCF8591的(de)(de)AOUT輸(shu)出端模(mo)(mo)(mo)擬電壓的(de)(de)大小,再將其接入到DAC0832的(de)(de)VREF腳上,便可(ke)以(yi)(yi)控制波形的(de)(de)幅(fu)(fu)度(du)。
(4)數模轉換電路設計
信號發生(sheng)器產(chan)生(sheng)各種波形信號使用(yong)到了DAC0832數(shu)(shu)模轉換(huan)芯(xin)片(pian),該芯(xin)片(pian)內(nei)部集成了一(yi)(yi)個(ge)(ge)8位D/A轉換(huan)器,一(yi)(yi)個(ge)(ge)8為DAC寄(ji)存器,一(yi)(yi)個(ge)(ge)8位輸入(ru)寄(ji)存器以(yi)及一(yi)(yi)個(ge)(ge)控制電路,其(qi)內(nei)部采(cai)用(yong)的(de)(de)是倒(dao)T型R-2R電阻網(wang)絡,將該數(shu)(shu)模轉換(huan)芯(xin)片(pian)與運算放大器LM358一(yi)(yi)起使用(yong),便可以(yi)使運放輸出(chu)(chu)端有28 =256個(ge)(ge)電壓(ya)(ya)值(zhi)輸出(chu)(chu)。在不同時間內(nei)變換(huan)輸出(chu)(chu)不同的(de)(de)電壓(ya)(ya)值(zhi),使其(qi)產(chan)生(sheng)周期性(xing)的(de)(de)變化便能形成相應的(de)(de)波形信號。
(5)按鍵中斷控制電路設計
基于單(dan)(dan)(dan)片(pian)(pian)(pian)機(ji)的信號(hao)發生器要求輸出(chu)方波(bo)(bo)、三角波(bo)(bo)、鋸齒波(bo)(bo)以(yi)及正弦(xian)波(bo)(bo)信號(hao),信號(hao)的幅(fu)度和頻(pin)率(lv)可調,用戶(hu)可通(tong)過系(xi)統按(an)(an)(an)鍵(jian)(jian)來對(dui)(dui)信號(hao)發生器進行設(she)置。在系(xi)統中,設(she)計了8個按(an)(an)(an)鍵(jian)(jian),其功(gong)能(neng)分別為100HZ頻(pin)率(lv)加按(an)(an)(an)鍵(jian)(jian)、1hz頻(pin)率(lv)加按(an)(an)(an)鍵(jian)(jian)、-1hz頻(pin)率(lv)減按(an)(an)(an)鍵(jian)(jian)、1V電壓(ya)幅(fu)度加按(an)(an)(an)鍵(jian)(jian)、0.1V電壓(ya)幅(fu)度加按(an)(an)(an)鍵(jian)(jian)、-0.1V電壓(ya)幅(fu)度減按(an)(an)(an)鍵(jian)(jian)、波(bo)(bo)形切換(huan)按(an)(an)(an)鍵(jian)(jian)、掃頻(pin)開(kai)關按(an)(an)(an)鍵(jian)(jian)。為了方便系(xi)統設(she)計,采用獨立按(an)(an)(an)鍵(jian)(jian)設(she)計方法(fa),利用單(dan)(dan)(dan)片(pian)(pian)(pian)機(ji)P1口(kou)將各(ge)按(an)(an)(an)鍵(jian)(jian)連(lian)接(jie),通(tong)過軟件將P1口(kou)設(she)置成(cheng)上拉狀(zhuang)態。當沒有按(an)(an)(an)鍵(jian)(jian)按(an)(an)(an)下時,單(dan)(dan)(dan)片(pian)(pian)(pian)機(ji)P1口(kou)中的所有I/O口(kou)檢(jian)測的到時高(gao)電平;當有按(an)(an)(an)鍵(jian)(jian)按(an)(an)(an)下時,則該按(an)(an)(an)鍵(jian)(jian)對(dui)(dui)應單(dan)(dan)(dan)片(pian)(pian)(pian)機(ji)的I/O口(kou)會被拉低,變成(cheng)低電平。單(dan)(dan)(dan)片(pian)(pian)(pian)機(ji)便能(neng)檢(jian)測到,從而調用該按(an)(an)(an)鍵(jian)(jian)程序(xu)執行相(xiang)應的功(gong)能(neng)。
(6)電源電路設計
本(ben)系統(tong)電(dian)(dian)路設(she)計是在Proteus仿真軟件上(shang)設(she)計,該(gai)仿真軟件有各種電(dian)(dian)源(yuan),可直(zhi)接調用(yong)。無需使(shi)(shi)用(yong)電(dian)(dian)壓(ya)轉(zhuan)換(huan)芯片(pian)。在本(ben)系統(tong)單片(pian)機使(shi)(shi)用(yong)5V電(dian)(dian)壓(ya)供電(dian)(dian),而為了使(shi)(shi)輸出波形幅度為10V,則PCF8591采用(yong)10V電(dian)(dian)壓(ya)供電(dian)(dian),而運算放大器采用(yong)±15V供電(dian)(dian),直(zhi)接從(cong)仿真軟件上(shang)取(qu)電(dian)(dian)源(yuan)即可。
3、系統軟件設計
完(wan)成(cheng)proteus軟件(jian)(jian)(jian)(jian)電路圖設計之后(hou)(hou),接下來需要(yao)對單片機編(bian)(bian)寫驅(qu)動程序(xu),系統(tong)驅(qu)動程序(xu)的編(bian)(bian)寫是在(zai)(zai)(zai)keil軟件(jian)(jian)(jian)(jian)平(ping)臺上(shang)完(wan)成(cheng)的,Keil軟件(jian)(jian)(jian)(jian)打開后(hou)(hou),要(yao)先建立工(gong)程,然后(hou)(hou)在(zai)(zai)(zai)工(gong)程當中建立一(yi)個.c文(wen)件(jian)(jian)(jian)(jian),在(zai)(zai)(zai)此文(wen)件(jian)(jian)(jian)(jian)中編(bian)(bian)寫代碼驅(qu)動程序(xu):
(1)系統主程序設計
主(zhu)程序(xu)(xu)(xu)是(shi)軟件系(xi)統中(zhong)最為(wei)重要(yao)的(de)程序(xu)(xu)(xu),因(yin)為(wei)系(xi)統程序(xu)(xu)(xu)是(shi)由各個子程序(xu)(xu)(xu)所構成,而(er)子程序(xu)(xu)(xu)的(de)調用全部是(shi)在主(zhu)程序(xu)(xu)(xu)中(zhong)來(lai)實(shi)現的(de),主(zhu)程序(xu)(xu)(xu)設(she)計的(de)好壞直(zhi)接能影響(xiang)到(dao)系(xi)統的(de)邏輯結(jie)構,影響(xiang)到(dao)系(xi)統工作的(de)穩定性(xing)。在本系(xi)統中(zhong),系(xi)統開始(shi)運行后(hou)(hou),先會執行主(zhu)程序(xu)(xu)(xu),在主(zhu)程序(xu)(xu)(xu)中(zhong)對單片機及其外圍元件進行初始(shi)化(hua)(hua)設(she)置(zhi),完(wan)成初始(shi)化(hua)(hua)設(she)置(zhi)之后(hou)(hou),系(xi)統就會執行正(zheng)弦波(bo)程序(xu)(xu)(xu),讓(rang)信號發生(sheng)(sheng)器(qi)輸(shu)(shu)(shu)出(chu)正(zheng)弦波(bo)信號,然后(hou)(hou)再(zai)去檢測是(shi)否有按(an)鍵按(an)下(xia),如果有按(an)鍵按(an)下(xia),系(xi)統檢測到(dao)后(hou)(hou),便(bian)會執行相應按(an)鍵的(de)程序(xu)(xu)(xu),從而(er)改變信號發生(sheng)(sheng)器(qi)輸(shu)(shu)(shu)出(chu)的(de)波(bo)形。如果沒有按(an)鍵產生(sheng)(sheng),則系(xi)統繼(ji)續保持(chi)當前波(bo)形輸(shu)(shu)(shu)出(chu),然后(hou)(hou)再(zai)繼(ji)續去訪問(wen)是(shi)否有按(an)鍵按(an)下(xia),如此(ci)循(xun)環下(xia)去。
(2)按鍵掃描程序設計
本系統(tong)是通(tong)過(guo)按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)來改(gai)變信號發生器的波(bo)(bo)(bo)形(xing),系統(tong)一共(gong)有八(ba)個按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)下(xia)不同(tong)按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)時,系統(tong)需要(yao)輸(shu)出(chu)不同(tong)的波(bo)(bo)(bo)形(xing)。定義按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)6為(wei)(wei)(wei)波(bo)(bo)(bo)形(xing)切換按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)0為(wei)(wei)(wei)100HZ頻(pin)率(lv)增(zeng)加按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)1為(wei)(wei)(wei)1HZ頻(pin)率(lv)增(zeng)加按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)2為(wei)(wei)(wei)1HZ頻(pin)率(lv)減(jian)按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)3位(wei)1V幅(fu)度增(zeng)加按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)4為(wei)(wei)(wei)0.1V幅(fu)度增(zeng)加按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)5為(wei)(wei)(wei)0.1V幅(fu)度減(jian)小按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)7位(wei)掃頻(pin)按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian),flang為(wei)(wei)(wei)標志位(wei),用于判斷按(an)(an)(an)(an)鍵(jian)(jian)(jian)(jian)6按(an)(an)(an)(an)下(xia)的次數(shu)當flang為(wei)(wei)(wei)1是默認輸(shu)出(chu)正弦(xian)波(bo)(bo)(bo);當flang為(wei)(wei)(wei)2時,輸(shu)出(chu)三(san)角波(bo)(bo)(bo);當flang為(wei)(wei)(wei)3時輸(shu)出(chu)鋸齒波(bo)(bo)(bo);當flang為(wei)(wei)(wei)4時,輸(shu)出(chu)方(fang)波(bo)(bo)(bo);當flang為(wei)(wei)(wei)5時,則會令flang=1,輸(shu)出(chu)正弦(xian)波(bo)(bo)(bo)。
因此,當(dang)有按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia)時,系統(tong)調用按(an)(an)鍵(jian)(jian)程(cheng)序(xu)會去判斷(duan)是(shi)哪個按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia),如果是(shi)按(an)(an)鍵(jian)(jian)6按(an)(an)下(xia)(xia),表示需要(yao)切換信號發(fa)生器(qi)的(de)(de)輸(shu)出(chu)(chu)波(bo)(bo)形(xing),令flang+1,然后(hou)(hou)判斷(duan)flang的(de)(de)值,再輸(shu)出(chu)(chu)相應的(de)(de)波(bo)(bo)形(xing)信號。當(dang)是(shi)0按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia)時,則(ze)(ze)系統(tong)會在原有的(de)(de)波(bo)(bo)形(xing)上(shang),改變(bian)其輸(shu)出(chu)(chu)頻(pin)率(lv)(lv)(lv),使(shi)頻(pin)率(lv)(lv)(lv)增加100HZ;當(dang)按(an)(an)下(xia)(xia)的(de)(de)是(shi)1按(an)(an)鍵(jian)(jian),則(ze)(ze)將(jiang)頻(pin)率(lv)(lv)(lv)增加1HZ;當(dang)2按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia),則(ze)(ze)將(jiang)頻(pin)率(lv)(lv)(lv)減小1HZ;當(dang)按(an)(an)鍵(jian)(jian)3按(an)(an)下(xia)(xia)時,表示要(yao)在原有波(bo)(bo)形(xing)的(de)(de)基(ji)礎上(shang)增加1V的(de)(de)波(bo)(bo)形(xing)幅度;當(dang)4按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia),則(ze)(ze)幅度增加0.1V;當(dang)5按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia),則(ze)(ze)幅度減小0.1V;當(dang)7按(an)(an)鍵(jian)(jian)按(an)(an)下(xia)(xia),則(ze)(ze)進行掃頻(pin)。當(dang)執(zhi)行完按(an)(an)鍵(jian)(jian)程(cheng)序(xu)后(hou)(hou),返回(hui)系統(tong)主(zhu)程(cheng)序(xu)。
二、信號發生器的設計要求有哪些
基于單片機設計的信號發生器屬于簡易信號發生器,主要能產生方波、三角波和正弦波并進行仿真,這類信號發生器設(she)計(ji)好(hao)后,應滿足以下要求:
1、基本性能指標要求
(1)頻(pin)率范圍:100Hz~1kHz。
(2)輸出電壓(ya):方波 Up-p≤24V,三角波 Up-p=6V,正弦波 Up-p>1V。
2、擴展性能指標要求
頻(pin)率范(fan)圍分段設置(zhi)10Hz~100Hz,100Hz~1kHz,1kHz~10kHz;波形特(te)性方波t r<30us(1kHz,最大輸出時),三角波r△<2%,正(zheng)弦波r~<5%。