CCS5.4+Proteus8的F28027实践课八、内置温度传感器
上午发布的ADC解读部分访问好高,呵呵,我又受鼓舞了,再接再励,把温度传感器这部分弄完就去吃晚饭。
看了下手册,温度传感器东西还真的不多,寄存器就一个ADCCTL1.TEMPCONV,其他的操作跟刚才的ADC采样思路是一样的。
首先来看下基本定义:
其实温度传感器和ADCA5就通过一个开关选择控制,如果大家上节课细心的话,也会在ADC图解中发现温度传感器
ADCCTL1.TEMPCONV这一位就是控制温度传感器连接的
下面看下具体转换和计算
简单明了,计算公式就是:Temperature = (sensor - Offset) * Slope
寄存器说完了,现在看个手册提供的示例程序:
从上面可以知道,温度传感器操作就三步:
1、ADC配置采样温度传感器通道;
2、中断采样;
3、结果换算;
直接贴代码了
void main(void) {// long sum=0;// float vol=0;int16 sensorSample,DegreesC;// int i=0;// Step 1. Initialize System Control:// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP2802x_SysCtrl.c file. InitSysCtrl();// Step 2. Initalize GPIO:// This example function is found in the DSP2802x_Gpio.c file and// illustrates how to set the GPIO to it's default state. InitGpio();// Step 3. Clear all interrupts and initialize PIE vector table:// Disable CPU interrupts DINT;// Initialize PIE control registers to their default state.// The default state is all PIE interrupts disabled and flags// are cleared.// This function is found in the DSP2802x_PieCtrl.c file. InitPieCtrl();// Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;// Initialize the PIE vector table with pointers to the shell Interrupt// Service Routines (ISR).// This will populate the entire table, even if the interrupt// is not used in this example. This is useful for debug purposes.// The shell ISR routines are found in DSP2802x_DefaultIsr.c.// This function is found in DSP2802x_PieVect.c. InitPieVectTable();// Step 4. Initialize all the Device Peripherals:// This function is found in DSP2802x_InitPeripherals.c// InitPeripherals(); // Not required for this example// Step 5. User specific code: InitAdc(); AdcOffsetSelfCal(); InitLCD12864(); EALLOW; AdcRegs.ADCCTL1.bit.TEMPCONV = 1; AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 1; AdcRegs.ADCSOC0CTL.bit.CHSEL = 5; AdcRegs.ADCSOC0CTL.bit.ACQPS = 6;// AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 0; AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcRegs.INTSEL1N2.bit.INT1SEL = 1; AdcRegs.INTSEL1N2.bit.INT1CONT = 0; AdcRegs.INTSEL1N2.bit.INT1E = 1; PieCtrlRegs.PIEIER1.bit.INTx1 = 1; FlashRegs.FOTPWAIT.bit.OTPWAIT = 1; EDIS; CpuTimer0Regs.TCR.bit.TIE = 1; StartCpuTimer0(); EALLOW; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; PieCtrlRegs.PIECTRL.bit.ENPIE = 1; IER |= 0x0001; EINT; EDIS; while(1) { if(AdcRegs.ADCSOCFLG1.bit.SOC0==1) { while(AdcRegs.ADCSOCFLG1.bit.SOC0==1); AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; DELAY_US(10); sensorSample=AdcResult.ADCRESULT0; DegreesC=GetTemperatureC(sensorSample); DISLPLAY_LONGSTRING(2,0,DegreesC);// sum+=AdcResult.ADCRESULT0;// i++; } /* if(i==10) {// sum/=10;// vol=sum*3.3/4095; WRITECMD_LCD12864(0x01); DISLPLAY_LONGSTRING(2,0,sum);// DISLPLAY_FLOATSTRING(3,0,vol);// WRITEDATA_LCD12864('v'); sum=0; i=0; }*/ //sum=AdcResult.ADCRESULT0; //DISLPLAY_LONGSTRING(2,0,sum); } }
不知道为什么,程序一直卡在非法操作中断那里,坑爹呀,都检查好多遍了,先去吃发个饭再回来继续检查。
吃晚饭回来又调试了下,发现是温度转换成摄氏温度的时候算法有问题,但这是TI提供的标准算法,暂时没发现错在哪里。但前面的步骤都是没问题的,能够读取温度的数字量。
看了下地址数据,这两个0x3D7E83和0x3D7E80地址里面根本没有数据,所以导致最后输出转换异常了,请问大家有类似的经验吗,我的CCS版本是5.4
刚才到处找资料,想找这两个地址的默认值,找到一个,0x28A9,不知道对不对,然后自己把这两个地址的值替换计算了下,结果又差不多,不知道了,等待大神解答
赞 (0)