本文來源電子發燒友社區,作者:yjp, 帖子地址:https://bbs.elecfans.com/jishu_2293870_1_1.html
ADC例子如下
首先配置ADC,對ADC進行初始化。
作 用:配置ADC**********************/void ADC_Init(void){ EALLOW; AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; /NT脈沖產生在ADC結果鎖定到其結果寄存器之前發生一個周期/ AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; /中斷選擇3寄存器/ AdcRegs.INTSEL3N4.bit.INT3E = 1; /每當產生EOC脈沖時,都會產生附加脈沖,而不管是否清除了標記位/ AdcRegs.INTSEL3N4.bit.INT3CONT = 0; /EOC6是ADCINT3的觸發器*/ AdcRegs.INTSEL3N4.bit.INT3SEL = 6;AdcRegs.ADCSAMPLEMODE.all = 1;
?
/*將SOC0設置為樣本A0*/
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0;
/*將SOC1設置為樣本A1*/
AdcRegs.ADCSOC1CTL.bit.CHSEL = 1;
/*將SOC2設置為樣本A2*/
AdcRegs.ADCSOC2CTL.bit.CHSEL = 2;
/*將SOC3設置為樣本A3*/
AdcRegs.ADCSOC3CTL.bit.CHSEL = 3;
/*將SOC4設置為樣本A4*/
AdcRegs.ADCSOC4CTL.bit.CHSEL = 4;
/*將SOC5設置為樣本A6*/
AdcRegs.ADCSOC5CTL.bit.CHSEL = 6;
/*將SOC6設置為樣本A7*/
AdcRegs.ADCSOC6CTL.bit.CHSEL = 7;
/*將SOC7設置為樣本B1*/
AdcRegs.ADCSOC7CTL.bit.CHSEL = 9;
/*將SOC8設置為樣本B2*/
AdcRegs.ADCSOC8CTL.bit.CHSEL = 10;
/*將SOC9設置為樣本B3*/
AdcRegs.ADCSOC9CTL.bit.CHSEL = 11;
/*將SOC10設置為樣本B4*/
AdcRegs.ADCSOC10CTL.bit.CHSEL = 12;
/*將SOC11設置為樣本B6*/
AdcRegs.ADCSOC11CTL.bit.CHSEL = 14;
/*將SOC12設置為樣本B7*/
AdcRegs.ADCSOC12CTL.bit.CHSEL = 15;
?
/*SOCx觸發源選擇:ADCTRIG5-ePWM1,ADCSOCA*/
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC4CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC5CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC6CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC7CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC8CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC9CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC10CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC11CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC12CTL.bit.TRIGSEL = 0x05;
?
/*采樣窗口長達6個周期(2n+6個時鐘周期)*/
AdcRegs.ADCSOC0CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC1CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC2CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC3CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC4CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC5CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC6CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC7CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC8CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC9CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC10CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC11CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC12CTL.bit.ACQPS = 0;
?
EDIS;
}
ADC的中斷服務函數如下Uint32 adcVal[16];/***********************函數名:void INTERRUPT adc_isr() *參 數:無 *返回值:無 *作 用:adc中斷服務函數**********************/void INTERRUPT adc_isr(){ while(AdcRegs.ADCCTL1.bit.ADCBSY == 1) { }adcVal[0] = AdcResult.ADCRESULT0;
adcVal[1] = AdcResult.ADCRESULT1;
adcVal[2] = AdcResult.ADCRESULT2;
adcVal[3] = AdcResult.ADCRESULT3;
adcVal[4] = AdcResult.ADCRESULT4;
adcVal[5] = AdcResult.ADCRESULT5;
adcVal[6] = AdcResult.ADCRESULT6;
?
adcVal[7] = AdcResult.ADCRESULT7;
adcVal[8] = AdcResult.ADCRESULT8;
adcVal[9] = AdcResult.ADCRESULT9;
adcVal[10] = AdcResult.ADCRESULT10;
adcVal[11] = AdcResult.ADCRESULT11;
adcVal[12] = AdcResult.ADCRESULT12;
?
EALLOW;
/*清除ADCINTFLG寄存器中各自的標志位*/
AdcRegs.ADCINTFLGCLR.bit.ADCINT3 = 0x1;
/* 清除ADCINTOVF寄存器中相應的溢出位*/
AdcRegs.ADCINTOVFCLR.bit.ADCINT3 = 0x1;
/* 中斷應答*/
PieCtrlRegs.PIEACK.all = PIEACK_GROUP10;
EDIS;}
ADC例子如下
首先配置ADC,對ADC進行初始化。
作 用:配置ADC**********************/void ADC_Init(void){ EALLOW; AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; /NT脈沖產生在ADC結果鎖定到其結果寄存器之前發生一個周期/ AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; /中斷選擇3寄存器/ AdcRegs.INTSEL3N4.bit.INT3E = 1; /每當產生EOC脈沖時,都會產生附加脈沖,而不管是否清除了標記位/ AdcRegs.INTSEL3N4.bit.INT3CONT = 0; /EOC6是ADCINT3的觸發器*/ AdcRegs.INTSEL3N4.bit.INT3SEL = 6;AdcRegs.ADCSAMPLEMODE.all = 1;
?
/*將SOC0設置為樣本A0*/
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0;
/*將SOC1設置為樣本A1*/
AdcRegs.ADCSOC1CTL.bit.CHSEL = 1;
/*將SOC2設置為樣本A2*/
AdcRegs.ADCSOC2CTL.bit.CHSEL = 2;
/*將SOC3設置為樣本A3*/
AdcRegs.ADCSOC3CTL.bit.CHSEL = 3;
/*將SOC4設置為樣本A4*/
AdcRegs.ADCSOC4CTL.bit.CHSEL = 4;
/*將SOC5設置為樣本A6*/
AdcRegs.ADCSOC5CTL.bit.CHSEL = 6;
/*將SOC6設置為樣本A7*/
AdcRegs.ADCSOC6CTL.bit.CHSEL = 7;
/*將SOC7設置為樣本B1*/
AdcRegs.ADCSOC7CTL.bit.CHSEL = 9;
/*將SOC8設置為樣本B2*/
AdcRegs.ADCSOC8CTL.bit.CHSEL = 10;
/*將SOC9設置為樣本B3*/
AdcRegs.ADCSOC9CTL.bit.CHSEL = 11;
/*將SOC10設置為樣本B4*/
AdcRegs.ADCSOC10CTL.bit.CHSEL = 12;
/*將SOC11設置為樣本B6*/
AdcRegs.ADCSOC11CTL.bit.CHSEL = 14;
/*將SOC12設置為樣本B7*/
AdcRegs.ADCSOC12CTL.bit.CHSEL = 15;
?
/*SOCx觸發源選擇:ADCTRIG5-ePWM1,ADCSOCA*/
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC4CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC5CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC6CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC7CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC8CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC9CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC10CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC11CTL.bit.TRIGSEL = 0x05;
AdcRegs.ADCSOC12CTL.bit.TRIGSEL = 0x05;
?
/*采樣窗口長達6個周期(2n+6個時鐘周期)*/
AdcRegs.ADCSOC0CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC1CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC2CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC3CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC4CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC5CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC6CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC7CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC8CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC9CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC10CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC11CTL.bit.ACQPS = 0;
AdcRegs.ADCSOC12CTL.bit.ACQPS = 0;
?
EDIS;
}
ADC的中斷服務函數如下Uint32 adcVal[16];/***********************函數名:void INTERRUPT adc_isr() *參 數:無 *返回值:無 *作 用:adc中斷服務函數**********************/void INTERRUPT adc_isr(){ while(AdcRegs.ADCCTL1.bit.ADCBSY == 1) { }adcVal[0] = AdcResult.ADCRESULT0;
adcVal[1] = AdcResult.ADCRESULT1;
adcVal[2] = AdcResult.ADCRESULT2;
adcVal[3] = AdcResult.ADCRESULT3;
adcVal[4] = AdcResult.ADCRESULT4;
adcVal[5] = AdcResult.ADCRESULT5;
adcVal[6] = AdcResult.ADCRESULT6;
?
adcVal[7] = AdcResult.ADCRESULT7;
adcVal[8] = AdcResult.ADCRESULT8;
adcVal[9] = AdcResult.ADCRESULT9;
adcVal[10] = AdcResult.ADCRESULT10;
adcVal[11] = AdcResult.ADCRESULT11;
adcVal[12] = AdcResult.ADCRESULT12;
?
EALLOW;
/*清除ADCINTFLG寄存器中各自的標志位*/
AdcRegs.ADCINTFLGCLR.bit.ADCINT3 = 0x1;
/* 清除ADCINTOVF寄存器中相應的溢出位*/
AdcRegs.ADCINTOVFCLR.bit.ADCINT3 = 0x1;
/* 中斷應答*/
PieCtrlRegs.PIEACK.all = PIEACK_GROUP10;
EDIS;}
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。
舉報投訴
-
中科昊芯
+關注
關注
5文章
80瀏覽量
5184 -
開發板試用
+關注
關注
3文章
301瀏覽量
2111
發布評論請先 登錄
相關推薦
有獎丨米爾 全志T536開發板免費試用
米爾與全志合作發布的新品基于全志T536應用處理器的MYD-LT536-GK開發板免費試用活動來啦~~米爾提供了3塊價值750元的MYD-LT536-GK開發板發起試用活動您不僅可以免
請問芯海技術支持,我司購買了 CST92F42KEV7HI 開發板,請問這款開發板怎么連接 KIEL V5 進行開發燒寫?
請問芯海技術支持,我司購買了 CST92F42KEV7HI 開發板,請問這款開發板怎么連接 KIEL V5 進行開發燒寫?
發表于 12-14 11:55
瑞芯微主板/開發板Linux系統播放音頻方法,觸覺智能RK3562開發板演示
本文介紹瑞芯微方案主板/開發板Linux系統播放音頻的方法,觸覺智能RK3562開發板演示,通用RK3566、RK3568、RK3588等
追加名額丨米爾瑞芯微RK3576開發板有獎試用
米爾與瑞芯微合作發布的新品基于瑞芯微RK3576應用處理器的MYD-LR3576開發板免費試用活動加碼啦~~米爾追加了2塊價值849元的MYD-LR3576
有獎丨米爾 瑞芯微RK3576開發板免費試用
米爾與瑞芯微合作發布的新品基于瑞芯微RK3576應用處理器的MYD-LR3576開發板免費試用活動來啦~~米爾提供了7塊價值849元的MYD-LR3576
喜報!中科昊芯榮獲國家級專精特新“小巨人”企業稱號
喜訊!近日,國家工業和信息化部門正式揭曉了第六批國家專精特新“小巨人”企業名單,中科昊芯憑借卓越的技術實力和創新能力,榮獲了專精特新“小巨人”企業殊榮。這一榮譽不僅是對
點擊參與米爾NXP i.MX 93開發板有獎試用
米爾與NXP合作發布的新品基于NXPi.MX93應用處理器的MYD-LMX9X開發板免費試用活動來啦~~米爾提供了3塊價值678元的MYD-LMX9X開發板發起試用活動您不僅可以免費體
評論