MCXA153 Multiple ADC interrupt

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MCXA153 Multiple ADC interrupt

893 次查看
MichaelBMiner
Contributor IV

Hello,

I am using the MCXA153 chip for a project and I have 5 ADC inputs. I do not have hardware yet and I want a sanity check on my code. 

My main issue is I do not fully understand lpadcCommandConfig.chainedNextCommandNumber and lpadcTriggerConfig.targetCommandId.

 

So for my code I have an ADC struct that contains gpio info and a windowed averaging struct. 

 

typedef enum {
	SPARE_ADC,
	VBATT_ADC,
	CURRENT_ADC,
	BATT_TEMP_ADC,
	SIGN_TEMP_ADC,

	NUM_ADCS
}ADCS;

struct adc_gpio_data {
	GPIO_Type *gpio;
	PORT_Type *port;
	uint32_t pin;
	uint32_t adc_channel;
};

struct adc {
	struct adc_gpio_data adc_gpio;
	struct windowed_average_t average;
};

This is my ADC IRQ

void ADC0_IRQHandler(void) {
    lpadc_conv_result_t convResult;

    if (LPADC_GetConvResult(ADC0, &convResult)) {
        uint32_t conv_trigger = convResult.triggerIdSource;
        if (conv_trigger < NUM_ADCS) {
            uint32_t result = convResult.convValue;
            windowed_average_add(&adcs[conv_trigger].average, result);
        }
    }
}

And my init code

void adc_init(void) {
	lpadc_conv_trigger_config_t lpadcTriggerConfig;
	lpadc_conv_command_config_t lpadcCommandConfig;
	lpadc_config_t lpadcConfig;

	adc_enable_clocks();
	adc_release_peripherals();
	adc_init_gpio();

	adc_init_adc_array();

    lpadcConfig.enableAnalogPreliminary = true;
    lpadcConfig.referenceVoltageSource = kLPADC_ReferenceVoltageAlt3;
    lpadcConfig.conversionAverageMode = kLPADC_ConversionAverage256;

    LPADC_DoResetConfig(ADC0);
    LPADC_Init(ADC0, &lpadcConfig);
    LPADC_DoOffsetCalibration(ADC0);

    LPADC_GetDefaultConvCommandConfig(&lpadcCommandConfig);
    LPADC_GetDefaultConvTriggerConfig(&lpadcTriggerConfig);
    for(uint8_t i=0U; i<NUM_ADCS; i++) {
    	lpadcCommandConfig.channelNumber = adcs[i].adc_gpio.adc_channel;
    	lpadcCommandConfig.conversionResolutionMode = kLPADC_ConversionResolutionStandard;
		lpadcCommandConfig.sampleTimeMode = kLPADC_SampleTimeADCK11;
		lpadcCommandConfig.chainedNextCommandNumber = i+1U;
		LPADC_SetConvCommandConfig(ADC0, i, &lpadcCommandConfig);

		lpadcTriggerConfig.targetCommandId = (i+1U);
		lpadcTriggerConfig.enableHardwareTrigger = false;
		LPADC_SetConvTriggerConfig(ADC0, i, &lpadcTriggerConfig);
    }

    LPADC_EnableInterrupts(ADC0, kLPADC_FIFO0WatermarkInterruptEnable);
	EnableIRQ(ADC0_IRQn);
}

 

Am I properly configuring my ADC channels as interrupt driven, software triggered, and does my IRQ properly determine which channel interrupted?

标签 (1)
标记 (2)
0 项奖励
回复
2 回复数

885 次查看
MichaelBMiner
Contributor IV

I have 5 ADC that I want to trigger on. It seems there are only 4 available triggers. I may be changing this to a polling ADC.

0 项奖励
回复

828 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @MichaelBMiner 

Yes, the MCXA153 only has 4 triggers. We can configure the next command to be executed after one command completes using the "Next Command Select" feature in CMD. We recommend using the Configure tool inside MCUXpresso IDE to set this up. It can generate the code automatically.

Alice_Yang_0-1729489669978.png

 

BR

Alice

 

0 项奖励
回复