參考ControlSuit範例 adc_soc_epwm_tempsensor
透過epwm產生adc中斷,但我的目的不是要使用epwm
而是在主程式main底下的while(1)去偵測溫度
不知道為何溫度轉換完後,出現-262度C
這些副程式都是從範例上抓取,未修改任何值
還請協助測試,並提供修改的方式
感謝!
/****************************************************************************************************/
InitTempSensor(3.0);
while(1)
{
// Sample the temperature sensor
AdcaRegs.ADCSOCFRC1.bit.SOC0 = 0x1; //SOC0
while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
sensorSample = AdcaResultRegs.ADCRESULT0; //Get temp sensor sample result
//Convert raw temperature sensor output to a temperature (degC)
slope = GetTemperatureC(sensorSample);
}
void ConfigureADC(void)
{
EALLOW;
//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//
//power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
//
//delay for 1ms to allow ADC time to power up
//
DELAY_US(1000);
EDIS;
}
void SetupADCEpwm(void)
{
Uint16 tempsensor_acqps;
tempsensor_acqps = 139; //temperature sensor needs at least 700ns
//acquisition time
//
//Select the channels to convert and end of conversion flag
//
EALLOW;
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 13; //SOC0 will convert internal
//connection A13
AdcaRegs.ADCSOC0CTL.bit.ACQPS = tempsensor_acqps; //sample window is 100
//SYSCLK cycles
AdcaRegs.ADCINTSOCSEL2.bit.SOC13 = 1;
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
EDIS;
}
/***************************************************************************************************/
SHIH CIH-HUEI:
有發現問題,在F2837xD_TempSensorConv.c裡面
程式預設是會抓取內部ic的Offset值
我目前做法是將Offset 強制為0
得到的溫度是43C,跟我用F28069板子驗證;其溫度大致相同
但不曉得這樣是對或錯?
另外為何程式開機執行InitTempSensor(3.0);
Offset值會有16xxx?
修改程式如下:
tempSensor_tempOffset = 0; // getTempOffset();
參考ControlSuit範例 adc_soc_epwm_tempsensor
透過epwm產生adc中斷,但我的目的不是要使用epwm
而是在主程式main底下的while(1)去偵測溫度
不知道為何溫度轉換完後,出現-262度C
這些副程式都是從範例上抓取,未修改任何值
還請協助測試,並提供修改的方式
感謝!
/****************************************************************************************************/
InitTempSensor(3.0);
while(1)
{
// Sample the temperature sensor
AdcaRegs.ADCSOCFRC1.bit.SOC0 = 0x1; //SOC0
while(AdcaRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
sensorSample = AdcaResultRegs.ADCRESULT0; //Get temp sensor sample result
//Convert raw temperature sensor output to a temperature (degC)
slope = GetTemperatureC(sensorSample);
}
void ConfigureADC(void)
{
EALLOW;
//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//
//power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
//
//delay for 1ms to allow ADC time to power up
//
DELAY_US(1000);
EDIS;
}
void SetupADCEpwm(void)
{
Uint16 tempsensor_acqps;
tempsensor_acqps = 139; //temperature sensor needs at least 700ns
//acquisition time
//
//Select the channels to convert and end of conversion flag
//
EALLOW;
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 13; //SOC0 will convert internal
//connection A13
AdcaRegs.ADCSOC0CTL.bit.ACQPS = tempsensor_acqps; //sample window is 100
//SYSCLK cycles
AdcaRegs.ADCINTSOCSEL2.bit.SOC13 = 1;
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
EDIS;
}
/***************************************************************************************************/
Johnson Chen1:
回复 SHIH CIH-HUEI:
芯片出厂时会做校准,把OFFSET 存在内部OTP中。因此需要使用OFFSET值。InitTempSensor(3.0)是指VREFHI为3.0V,如果是其他值需要做相应更改。