标签:
DSP28377S - ADC学习编程笔记
彭会锋
2016-08-04 20:19:52
1 ADC类型导致的配置区别
F28377S的ADC类型是Type 4类型,我的理解是不同类型的ADC采样方式是不一样的:F28335ADC 采样序列可以配置为顺序采样和同步采样模式,而F28377S采样序列可以配置为round-robin or burst模式,这两种模式下面再讲解。
2 ADC上电配置步骤
//Write ADC configurations and power up the ADC for both ADC A and ADC B void ConfigureADC(void) { EALLOW; //write configurations AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 //配置ADC时钟,ADC时钟有系统时钟直接提供参考时钟,计算的时候需要注意 AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); // 设置ADC的采样分辨率为12bit,单输入模式(区别于差分模式) AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4 AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); //Set pulse positions to late AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; //设置ADC的中断产生时机在转换完成后产生中断(Interrupt pulse generation occurs at the end of the conversion) AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; //power up the ADC AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; //给ADC上电,注意需要延时1ms左右等待上电完成
AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; //delay for 1ms to allow ADC time to power up DELAY_US(1000); EDIS; }
3 ADC采样通道、保持时间和触发信号配置,这里和中断配置在一起讲了!
AdcbRegs.ADCSOC7CTL.bit.CHSEL = 14; //SOC0 will convert internal connection B0 AdcbRegs.ADCSOC7CTL.bit.ACQPS = tempsensor_acqps; //sample window is 100 SYSCLK cycles AdcbRegs.ADCSOC7CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C,这里根据需要进行配置
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 7; //end of SOC0 will set INT1 flag (这里一般配置为最后一个优先级的SOC即可!注意要随时修改,这里栽跟头了)(优先级放最后讲解,可以不用理解!) AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag (如果不配置这里,那么ADC采样完成后中断flag不会置位,所以必须配置为1) AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
在配置过程中需要注意的是:
为了进行测试,有时候会使用13 temp sensor做测试用(需要注意必须先初始化此温度端口,然后在使用,否则ADC采样会被卡在这个地方导致莫名其妙问题)
//Initialize the temperature sensor
//Note: The argument needs to change if using a VREFHI voltage other than 3.0V
InitTempSensor(3.0); (这里已经有现成的封装函数可以使用,直接调用即可!)(如果不初始化,会导致采样无法正常顺序进行,切记切记!)
AdcaRegs.ADCSOC6CTL.bit.CHSEL = 13; //SOC0 will convert internal connection A13 AdcaRegs.ADCSOC6CTL.bit.ACQPS = tempsensor_acqps; //sample window is 100 SYSCLK cycles AdcaRegs.ADCSOC6CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
4 epwm触发配置
注意:epwm可以配置为在ZERO和PERIOD两个时刻都可以触发SOCA采样信号,所以在逆变器中可以连续采样两次,这个对于编程很重要,差点有栽跟头了,所以一定要看官方文档!
void ConfigureEPWM(void) { EALLOW; // Assumes ePWM clock is already enabled EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Select SOC on up-count EPwm1Regs.ETPS.bit.SOCAPRD = ET_CTR_PRDZERO; // Generate pulse on 1st event(注意这里EPWM可以配置为在ZERO 和 PERIOD时触发ADC采样,这和F28335不一样!又差点栽跟头了!) EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze counter EDIS; }
最后还有关于EOC 转换优先级 和 ADC采样结构等内容,作为了解性质,晚点补充,今天先到次为止!
标签:
原文地址:http://www.cnblogs.com/qiufenghui/p/5738350.html