SLAAEB8 February 2024 MSPM0G1505 , MSPM0G1506 , MSPM0G1507 , MSPM0G3505 , MSPM0G3505-Q1 , MSPM0G3506 , MSPM0G3506-Q1 , MSPM0G3507 , MSPM0G3507-Q1
#define FILTER_ORDER 24
#define FIXED_POINT_PRECISION 16
volatile bool gCheckADC;
uint32_t gDelayLine[FILTER_ORDER];
uint32_t gResult = 0;
/* Filter coefficients are input as 16-bit Precision fixed point values */
static int32_t filterCoeff[FILTER_ORDER] = {
-62, -153, -56, 434, 969, 571,
-1291, -3237, -2173, 3989, 13381, 20518,
20518, 13381, 3989, -2173, -3237, -1291,
571, 969, 434, -56, -153, -62
};
const DL_MathACL_operationConfig gMpyConfig = {
.opType = DL_MATHACL_OP_TYPE_MAC,
.opSign = DL_MATHACL_OPSIGN_SIGNED,
.iterations = 0,
.scaleFactor = 0,
.qType = DL_MATHACL_Q_TYPE_Q16};
int main(void)
{
SYSCFG_DL_init();
NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
gCheckADC = false;
DL_ADC12_startConversion(ADC12_0_INST);
/* Configure MathACL for Multiply */
DL_MathACL_configOperation(MATHACL, &gMpyConfig, 0, 0 );
while (1) {
while (false == gCheckADC) {
__WFE();
}
gCheckADC = false;
gResult = 0;
/* Append the most recent ADC result to the delay line */
memmove(&gDelayLine[1], gDelayLine, sizeof(gDelayLine) - sizeof(gDelayLine[0]));
gDelayLine[0] = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);
/* Calculate FIR Filter Output */
for (int i = 0; i < FILTER_ORDER; i++){
/* Set Operand One last */
DL_MathACL_setOperandTwo(MATHACL, filterCoeff[i]);
DL_MathACL_setOperandOne(MATHACL, gDelayLine[i]);
DL_MathACL_waitForOperation(MATHACL);
}
/* Our result should not exceed the bounds of RES1 register, in other applications you may use both RES1 and RES2 registers */
gResult = DL_MathACL_getResultOne(MATHACL);
DL_DAC12_output12(DAC0, (uint32_t)(gResult));
/* Clear Results Registers */
DL_MathACL_clearResults(MATHACL);
}
}
/* Set the ADC Result flag to trigger our main loop to process the new data */
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;
}
}