shabaz designed a development kit for the recent Texas Instruments MSPM0 microcontroller series.
|
Goal of this 2nd post
- add single ADC conversion logic, based on TI adc12_single_conversion
- use ADC hardware to return value in same Q16 format used in the PID library
Set up ADC SysConfig
The Conversion Data Format, 2s complement, left aligned, happens to be the same Q15 format that our PID library uses.
Code adaption from post 1:
I use a flag to check if sampling is done. The Result Loaded trigger will set that flag.
volatile bool gCheckADC; uint32_t gAdcResult; // ... void ADC12_0_INST_IRQHandler(void) { switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST)) { case DL_ADC12_IIDX_MEM0_RESULT_LOADED: gCheckADC = true; break; default: break; } }
In main(), the IRQ gets enabled
int main(void) { SYSCFG_DL_init(); // ... NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN); gCheckADC = false; // ...
The perform_adc() placeholder that I wrote in the 1st post, gets implemented now:
void perform_adc() { DL_ADC12_startConversion(ADC12_0_INST); while (false == gCheckADC) { __WFE(); } gAdcResult = (uint32_t)DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0); gCheckADC = false; DL_ADC12_enableConversions(ADC12_0_INST); }
I could make gAdcResult a return value instead of a global variable. Maybe later ...
Thanks for reading. Next, get PWM working.
ccs project for EasyL1105: pid_EasyL1105_20250927.zip