【中科昊芯Start_DSC28034PNT湖人开发板试用体验】--学写一个ADC

描述

本文来源电子发烧友社区,作者: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;}
打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分