static volatile int tempSample = 0;
static volatile bool tempSeqComplete = false;
static volatile int tempTimer = 1;
static uint32_t temp[10];
uint32_t temp_result;
float temperature;
void ADCA_IRQHandler(void)
{
uint32_t pending;
/* Get pending interrupts */
pending = Chip_ADC_GetFlags(LPC_ADC);
/* Sequence A completion interrupt */
if (pending & ADC_FLAGS_SEQA_INT_MASK) {
if (tempSample < 10) {
/* Save sample */
temp[tempSample] = Chip_ADC_GetDataReg(LPC_ADC, 0);
tempSample++;
if (tempSample >= 10) {
Chip_ADC_StopBurstSequencer(LPC_ADC, ADC_SEQA_IDX);
tempSeqComplete = true;
}
}
}
/* Clear any pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC, pending);
}
|
// Runs every ~10ms
void TIMER32_0_IRQHandler(void){
// Temperature Sequencer
if(tempTimer == 20){
Chip_ADC_StartBurstSequencer(LPC_ADC, ADC_SEQA_IDX);
tempSeqComplete = false;
tempSample = 0;
tempTimer = 0;
}else{
tempTimer++;
}
}
|
// Inside main function
// ADC channel 0 - Temperature sensor
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 9, (IOCON_FUNC3 | IOCON_MODE_INACT | IOCON_ADMODE_EN ));
//*****************************************************************************
// Init and Config ADC
//*****************************************************************************
Chip_ADC_Init(LPC_ADC,0);
Chip_ADC_StartCalibration(LPC_ADC);
while(!Chip_ADC_IsCalibrationDone(LPC_ADC)); // Wait until calibration is done
Chip_ADC_SetClockRate(LPC_ADC,ADC_MAX_SAMPLE_RATE);
Chip_ADC_SetupSequencer(LPC_ADC,ADC_SEQA_IDX,(ADC_SEQ_CTRL_CHANSEL(0) | ADC_SEQ_CTRL_MODE_EOS));
// Enable temperature sensor on ADC channel 0
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_TS_PD); // Clear TEMPSENSE_PD
Chip_ADC_SetTrim(LPC_ADC,ADC_TRIM_VRANGE_HIGHV);
Chip_ADC_SetThrLowValue(LPC_ADC, 0, ((1 * 0xFFF) / 4));
Chip_ADC_SetThrHighValue(LPC_ADC, 0, ((3 * 0xFFF) / 4));
/* Clear all pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC));
Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC));
/* Enable ADC sequence A completion interrupt */
Chip_ADC_EnableInt(LPC_ADC, ADC_INTEN_SEQA_ENABLE);
/* Enable ADC NVIC interrupt */
NVIC_EnableIRQ(ADC_A_IRQn);
while(1){
if(tempSeqComplete){
temp_result = ADC_DR_RESULT(temp[9]);
temp_result = 0xFFF - temp_result;
temperature = ((temp_result/4095.0)*145.0)-40.0;
}
}
|
I think this answers the question.
PS: If he means LPC11E67JBD48, than he has a 12bit ADC as well.
Hello!
I am using an LPC11U68 which has a 12 bit ADC and a temperature range from -40 to 105°C. At least the data sheet says so.
I also do get a value of about 80°C.
My calculation was:
auto temp = 105 - ((int)(rawValue * 145 / rawMax));
How do you get the values "-578,34" and "-2,366"?
Thanks!