Other Parts Discussed in Thread: SYSCONFIG
Tool/software: Theia
Hi, this is my ADC configuration in syscfg:
ADC121.$name = "ADC12_0";
ADC121.repeatMode = true;
ADC121.resolution = "DL_ADC12_SAMP_CONV_RES_10_BIT";
ADC121.powerDownMode = "DL_ADC12_POWER_DOWN_MODE_MANUAL";
ADC121.trigSrc = "DL_ADC12_TRIG_SRC_EVENT";
ADC121.configWinCompHighThld = 500;
ADC121.adcMem0trig = "DL_ADC12_TRIGGER_MODE_TRIGGER_NEXT";
ADC121.enabledInterrupts = ["DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED"];
ADC121.sampleTime0 = "1.4us";
ADC121.adcMem0chansel = "DL_ADC12_INPUT_CHAN_13";
ADC121.subChanID = 1;
ADC121.pubChanID = 2;
ADC121.enabledEvents = ["DL_ADC12_EVENT_MEM0_RESULT_LOADED"];
Later, I set it for single conversion (averaging 128x).
DL_ADC12_disableConversions(ADC12_0_INST); DL_ADC12_initSingleSample(ADC12_0_INST, DL_ADC12_REPEAT_MODE_ENABLED, DL_ADC12_SAMPLING_SOURCE_AUTO, DL_ADC12_TRIG_SRC_SOFTWARE, DL_ADC12_SAMP_CONV_RES_10_BIT, DL_ADC12_SAMP_CONV_DATA_FORMAT_UNSIGNED); DL_ADC12_configConversionMem(ADC12_0_INST, ADC12_0_ADCMEM_0, DL_ADC12_INPUT_CHAN_13, DL_ADC12_REFERENCE_VOLTAGE_VDDA, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_ENABLED, DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_TRIGGER_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED); DL_ADC12_setPowerDownMode(ADC12_0_INST, DL_ADC12_POWER_DOWN_MODE_MANUAL); DL_ADC12_configHwAverage(ADC12_0_INST, DL_ADC12_HW_AVG_NUM_ACC_128, DL_ADC12_HW_AVG_DEN_DIV_BY_128); // DL_ADC12_disableConversions(ADC12_0_INST); // DL_ADC12_setSampleTime0(ADC12_0_INST, // PARAM_Settings[ADC_SAMPLE_TIME]); // DL_ADC12_enableConversions(ADC12_0_INST); NVIC_ClearPendingIRQ(ADC12_0_INST_INT_IRQN); DL_ADC12_clearInterruptStatus( ADC12_0_INST, (DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED)); DL_ADC12_enableInterrupt(ADC12_0_INST, (DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED)); DL_ADC12_enableConversions(ADC12_0_INST); NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN); DL_ADC12_startConversion(ADC12_0_INST);
I would like to handle the result in my IRQ.
void ADC12_0_INST_IRQHandler(void) { volatile static uint16_t adcCaptureCnt; int timingError = 0; // this IRQ is called only when there is signal volatile int interruptResult = DL_ADC12_getPendingInterrupt(ADC12_0_INST); switch (interruptResult) { case DL_ADC12_IIDX_MEM0_RESULT_LOADED: adcResult = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0); switch (PARAM_State) { case READ_DATA: { // readback values directly handled in parameterization.c } break; case CALIBRATION: { switch (calibrationType) { case DC_CAL: { PARAM_Put16BitValue(DC_L, DC_H, adcResult); // eeprom is saved in parameterization.c CalInProgress = false; } break; case OPT_SHORT_CAL: { CalInProgress = false; } break; default: break; } } break; ....
It is very strange that when I set my compiler optimisation to '0', code runs properly. But when I set optimisation to '2', the IRQ runs but with the interruptResult (IIDX.STAT) of 0. Hence, it skips over my code.
The funny thing is when I run the code under Debug using breakpoints within the IRQ, the IRQ actually runs twice, once with interruptResult of 0 and then the second time with the expected interruptResult of 9 (DL_ADC12_IIDX_MEM0_RESULT_LOADED). While it's not ideal, I could live with it. But this behaviour doesn't happen during normal running.
I have already tried to clear all interrupts, pending interrupts, etc. I am not sure what else to do at this point. Setting optimisation to '0' is not an option as I need the optimisation for other parts of the code to run properly. Please help