hello,现在碰到个难题,我想使用pwm的溢出标志去触发两个adc外设分别采集三路模拟信号,发现配置完后,有pwm输出但是无法触发adc中断获取到采集信息。sdk中也没相关应用,所以可以帮忙看下是什么问题吗?
下面是配置代码。
1. adc配置
const lpadc_config_t ADC0_config = {
.enableInDozeMode = false,
.conversionAverageMode = kLPADC_ConversionAverage256,
.enableAnalogPreliminary = true,
.powerUpDelay = 0x80UL,
.referenceVoltageSource = kLPADC_ReferenceVoltageAlt3,
.powerLevelMode = kLPADC_PowerLevelAlt4,
.triggerPriorityPolicy = kLPADC_TriggerPriorityExceptionDisabled,
.enableConvPause = false,
.convPauseDelay = 0UL,
.FIFOWatermark = 0UL,
};
lpadc_conv_command_config_t ADC0_commandsConfig[3] = {
{
.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
.channelNumber = 4U,
.chainedNextCommandNumber = 2,
.enableAutoChannelIncrement = false,
.loopCount = 0UL,
.hardwareAverageMode = kLPADC_HardwareAverageCount1,
.sampleTimeMode = kLPADC_SampleTimeADCK3,
.hardwareCompareMode = kLPADC_HardwareCompareDisabled,
.hardwareCompareValueHigh = 0UL,
.hardwareCompareValueLow = 0UL,
.conversionResolutionMode = kLPADC_ConversionResolutionHigh,
.enableWaitTrigger = true
},
{
.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
.channelNumber = 5U,
.chainedNextCommandNumber = 3,
.enableAutoChannelIncrement = false,
.loopCount = 0UL,
.hardwareAverageMode = kLPADC_HardwareAverageCount1,
.sampleTimeMode = kLPADC_SampleTimeADCK3,
.hardwareCompareMode = kLPADC_HardwareCompareDisabled,
.hardwareCompareValueHigh = 0UL,
.hardwareCompareValueLow = 0UL,
.conversionResolutionMode = kLPADC_ConversionResolutionHigh,
.enableWaitTrigger = true
},
{
.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
.channelNumber = 7U,
.chainedNextCommandNumber = 0,
.enableAutoChannelIncrement = false,
.loopCount = 0UL,
.hardwareAverageMode = kLPADC_HardwareAverageCount1,
.sampleTimeMode = kLPADC_SampleTimeADCK3,
.hardwareCompareMode = kLPADC_HardwareCompareDisabled,
.hardwareCompareValueHigh = 0UL,
.hardwareCompareValueLow = 0UL,
.conversionResolutionMode = kLPADC_ConversionResolutionHigh,
.enableWaitTrigger = false
}
};
lpadc_conv_trigger_config_t ADC0_triggersConfig[1] = {
{
.targetCommandId = 1,
.delayPower = 0UL,
.priority = 0,
.enableHardwareTrigger = true
},
};
static void ADC0_init(void) {
/* Initialize LPADC converter */
LPADC_Init(ADC0_PERIPHERAL, &ADC0_config);
/* Perform auto calibration */
LPADC_DoAutoCalibration(ADC0_PERIPHERAL);
/* Configure conversion command 1. */
LPADC_SetConvCommandConfig(ADC0_PERIPHERAL, ADC0_ADC0_CMD1, &ADC0_commandsConfig[0]);
/* Configure conversion command 2. */
LPADC_SetConvCommandConfig(ADC0_PERIPHERAL, ADC0_ADC0_CMD2, &ADC0_commandsConfig[1]);
/* Configure conversion command 3. */
LPADC_SetConvCommandConfig(ADC0_PERIPHERAL, ADC0_ADC0_CMD3, &ADC0_commandsConfig[2]);
/* Configure trigger 0. */
LPADC_SetConvTriggerConfig(ADC0_PERIPHERAL, ADC0_TRIGGER_0, &ADC0_triggersConfig[0]);
LPADC_EnableInterrupts(ADC0_PERIPHERAL, (kLPADC_Trigger0CompletionInterruptEnable));
/* Interrupt vector ADC1_IRQn priority settings in the NVIC. */
NVIC_SetPriority(ADC0_IRQn, 0);
/* Enable interrupt ADC1_IRQN request in the NVIC */
EnableIRQ(ADC0_IRQn);
}
const lpadc_config_t ADC1_config = {
.enableInDozeMode = false,
.conversionAverageMode = kLPADC_ConversionAverage256,
.enableAnalogPreliminary = true,
.powerUpDelay = 0x80UL,
.referenceVoltageSource = kLPADC_ReferenceVoltageAlt3,
.powerLevelMode = kLPADC_PowerLevelAlt4,
.triggerPriorityPolicy = kLPADC_TriggerPriorityExceptionDisabled,
.enableConvPause = false,
.convPauseDelay = 0UL,
.FIFOWatermark = 0UL,
};
lpadc_conv_command_config_t ADC1_commandsConfig[3] = {
{
.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
.channelNumber = 8U,
.chainedNextCommandNumber = 2,
.enableAutoChannelIncrement = false,
.loopCount = 0UL,
.hardwareAverageMode = kLPADC_HardwareAverageCount1,
.sampleTimeMode = kLPADC_SampleTimeADCK3,
.hardwareCompareMode = kLPADC_HardwareCompareDisabled,
.hardwareCompareValueHigh = 0UL,
.hardwareCompareValueLow = 0UL,
.conversionResolutionMode = kLPADC_ConversionResolutionHigh,
.enableWaitTrigger = true
},
{
.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
.channelNumber = 9U,
.chainedNextCommandNumber = 3,
.enableAutoChannelIncrement = false,
.loopCount = 0UL,
.hardwareAverageMode = kLPADC_HardwareAverageCount1,
.sampleTimeMode = kLPADC_SampleTimeADCK3,
.hardwareCompareMode = kLPADC_HardwareCompareDisabled,
.hardwareCompareValueHigh = 0UL,
.hardwareCompareValueLow = 0UL,
.conversionResolutionMode = kLPADC_ConversionResolutionHigh,
.enableWaitTrigger = true
},
{
.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA,
.channelNumber = 3U,
.chainedNextCommandNumber = 0,
.enableAutoChannelIncrement = false,
.loopCount = 0UL,
.hardwareAverageMode = kLPADC_HardwareAverageCount1,
.sampleTimeMode = kLPADC_SampleTimeADCK3,
.hardwareCompareMode = kLPADC_HardwareCompareDisabled,
.hardwareCompareValueHigh = 0UL,
.hardwareCompareValueLow = 0UL,
.conversionResolutionMode = kLPADC_ConversionResolutionHigh,
.enableWaitTrigger = false
}
};
lpadc_conv_trigger_config_t ADC1_triggersConfig[1] = {
{
.targetCommandId = 1,
.delayPower = 0UL,
.priority = 0,
.enableHardwareTrigger = true
},
};
static void ADC1_init(void) {
/* Initialize LPADC converter */
LPADC_Init(ADC1_PERIPHERAL, &ADC1_config);
/* Perform auto calibration */
LPADC_DoAutoCalibration(ADC1_PERIPHERAL);
/* Configure conversion command 1. */
LPADC_SetConvCommandConfig(ADC1_PERIPHERAL, ADC1_ADC1_CMD1, &ADC1_commandsConfig[0]);
/* Configure conversion command 2. */
LPADC_SetConvCommandConfig(ADC1_PERIPHERAL, ADC1_ADC1_CMD2, &ADC1_commandsConfig[1]);
/* Configure conversion command 3. */
LPADC_SetConvCommandConfig(ADC1_PERIPHERAL, ADC1_ADC1_CMD3, &ADC1_commandsConfig[2]);
/* Configure trigger 0. */
LPADC_SetConvTriggerConfig(ADC1_PERIPHERAL, ADC1_TRIGGER_0, &ADC1_triggersConfig[0]);
NVIC_SetPriority(ADC1_IRQn, 0);
}
2. pwm配置
pwm_config_t FLEXPWM0_SM0_config = {
.clockSource = kPWM_BusClock,
.prescale = kPWM_Prescale_Divide_1,
.pairOperation = kPWM_ComplementaryPwmA,
.initializationControl = kPWM_Initialize_LocalSync,
.reloadLogic = kPWM_ReloadPwmFullCycle,
.reloadSelect = kPWM_LocalReload,
.reloadFrequency = kPWM_LoadEveryOportunity,
.forceTrigger = kPWM_Force_Local,
.enableDebugMode = true,
};
pwm_signal_param_t FLEXPWM0_SM0_pwm_function_config[2]= {
{
.pwmChannel = kPWM_PwmA,
.dutyCyclePercent = 50U,
.level = kPWM_HighTrue,
.faultState = kPWM_PwmFaultState2,
.pwmchannelenable = true,
.deadtimeValue = 58U
},
{
.pwmChannel = kPWM_PwmB,
.dutyCyclePercent = 50U,
.level = kPWM_HighTrue,
.faultState = kPWM_PwmFaultState2,
.pwmchannelenable = true,
.deadtimeValue = 58U
},
};
pwm_config_t FLEXPWM0_SM1_config = {
.clockSource = kPWM_Submodule0Clock,
.prescale = kPWM_Prescale_Divide_1,
.pairOperation = kPWM_ComplementaryPwmA,
.initializationControl = kPWM_Initialize_MasterSync,//,
.reloadLogic = kPWM_ReloadPwmFullCycle,
.reloadSelect = kPWM_LocalReload,//kPWM_MasterReload,
.reloadFrequency = kPWM_LoadEveryOportunity,
.forceTrigger = kPWM_Force_Local,//kPWM_Force_Master,
.enableDebugMode = true,
};
pwm_signal_param_t FLEXPWM0_SM1_pwm_function_config[2]= {
{
.pwmChannel = kPWM_PwmA,
.dutyCyclePercent = 0U,
.level = kPWM_HighTrue,
.faultState = kPWM_PwmFaultState2,
.pwmchannelenable = true,
.deadtimeValue = 58U
},
{
.pwmChannel = kPWM_PwmB,
.dutyCyclePercent = 0U,
.level = kPWM_HighTrue,
.faultState = kPWM_PwmFaultState2,
.pwmchannelenable = true,
.deadtimeValue = 58U
},
};
pwm_config_t FLEXPWM0_SM2_config = {
.clockSource = kPWM_BusClock,
.prescale = kPWM_Prescale_Divide_1,
.pairOperation = kPWM_ComplementaryPwmA,
.initializationControl = kPWM_Initialize_MasterSync,
.reloadLogic = kPWM_ReloadPwmFullCycle,
.reloadSelect = kPWM_MasterReload,
.reloadFrequency = kPWM_LoadEveryOportunity,
.forceTrigger = kPWM_Force_Master,
.enableDebugMode = true,
};
pwm_signal_param_t FLEXPWM0_SM2_pwm_function_config[2]= {
{
.pwmChannel = kPWM_PwmA,
.dutyCyclePercent = 0U,
.level = kPWM_HighTrue,
.faultState = kPWM_PwmFaultState2,
.pwmchannelenable = true,
.deadtimeValue = 58U
},
{
.pwmChannel = kPWM_PwmB,
.dutyCyclePercent = 0U,
.level = kPWM_HighTrue,
.faultState = kPWM_PwmFaultState2,
.pwmchannelenable = true,
.deadtimeValue = 58U
},
};
const pwm_fault_input_filter_param_t FLEXPWM0_faultInputFilter_config = {
.faultFilterPeriod = 2U,
.faultFilterCount = 4U,
.faultGlitchStretch = true
};
const pwm_fault_param_t FLEXPWM0_Fault0_fault_config = {
.faultClearingMode = kPWM_ManualSafety,
.faultLevel = true,
.enableCombinationalPath = true,
.recoverMode = kPWM_RecoverFullCycle,
};
const pwm_fault_param_t FLEXPWM0_Fault1_fault_config = {
.faultClearingMode = kPWM_Automatic,
.faultLevel = true,
.enableCombinationalPath = true,
.recoverMode = kPWM_NoRecovery
};
const pwm_fault_param_t FLEXPWM0_Fault2_fault_config = {
.faultClearingMode = kPWM_Automatic,
.faultLevel = true,
.enableCombinationalPath = true,
.recoverMode = kPWM_NoRecovery
};
const pwm_fault_param_t FLEXPWM0_Fault3_fault_config = {
.faultClearingMode = kPWM_Automatic,
.faultLevel = true,
.enableCombinationalPath = true,
.recoverMode = kPWM_NoRecovery
};
static void FLEXPWM0_init(void) {
/* Initialize PWM submodule SM0 main configuration */
PWM_Init(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM0, &FLEXPWM0_SM0_config);
/* Initialize PWM submodule SM1 main configuration */
PWM_Init(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM1, &FLEXPWM0_SM1_config);
/* Initialize PWM submodule SM2 main configuration */
PWM_Init(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM2, &FLEXPWM0_SM2_config);
/* Initialize PWM submodule SM1 phase delay */
PWM_SetPhaseDelay(FLEXPWM0_PERIPHERAL, FLEXPWM0_UNUSED_CHANNEL_PARAM, FLEXPWM0_SM1, FLEXPWM0_SM1_DELAY_CYCLES);
/* Initialize PWM submodule SM2 phase delay */
PWM_SetPhaseDelay(FLEXPWM0_PERIPHERAL, FLEXPWM0_UNUSED_CHANNEL_PARAM, FLEXPWM0_SM2, FLEXPWM0_SM2_DELAY_CYCLES);
/* Initialize fault input filter configuration */
PWM_SetupFaultInputFilter(FLEXPWM0_PERIPHERAL, &FLEXPWM0_faultInputFilter_config);
/* Initialize fault channel 0 fault Fault0 configuration */
PWM_SetupFaults(FLEXPWM0_PERIPHERAL, FLEXPWM0_F0_FAULT0, &FLEXPWM0_Fault0_fault_config);
/* Initialize fault channel 0 fault Fault1 configuration */
PWM_SetupFaults(FLEXPWM0_PERIPHERAL, FLEXPWM0_F0_FAULT1, &FLEXPWM0_Fault1_fault_config);
/* Initialize fault channel 0 fault Fault2 configuration */
PWM_SetupFaults(FLEXPWM0_PERIPHERAL, FLEXPWM0_F0_FAULT2, &FLEXPWM0_Fault2_fault_config);
/* Initialize fault channel 0 fault Fault3 configuration */
PWM_SetupFaults(FLEXPWM0_PERIPHERAL, FLEXPWM0_F0_FAULT3, &FLEXPWM0_Fault3_fault_config);
/* Initialize deadtime logic input for the channel A */
PWM_SetupForceSignal(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM0, FLEXPWM0_SM0_A, kPWM_UsePwm);
/* Initialize deadtime logic input for the channel B */
PWM_SetupForceSignal(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM0, FLEXPWM0_SM0_B, kPWM_UsePwm);
/* Initialize deadtime logic input for the channel A */
PWM_SetupForceSignal(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM1, FLEXPWM0_SM1_A, kPWM_UsePwm);
/* Initialize deadtime logic input for the channel B */
PWM_SetupForceSignal(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM1, FLEXPWM0_SM1_B, kPWM_UsePwm);
/* Initialize deadtime logic input for the channel A */
PWM_SetupForceSignal(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM2, FLEXPWM0_SM2_A, kPWM_UsePwm);
/* Initialize deadtime logic input for the channel B */
PWM_SetupForceSignal(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM2, FLEXPWM0_SM2_B, kPWM_UsePwm);
/* Setup PWM output setting for submodule SM0 */
PWM_SetupPwm(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM0, FLEXPWM0_SM0_pwm_function_config, 2U, kPWM_CenterAligned, FLEXPWM0_SM0_COUNTER_FREQ_HZ, FLEXPWM0_SM0_SM_CLK_SOURCE_FREQ_HZ);
/* Setup PWM output setting for submodule SM1 */
PWM_SetupPwm(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM1, FLEXPWM0_SM1_pwm_function_config, 2U, kPWM_CenterAligned, FLEXPWM0_SM1_COUNTER_FREQ_HZ, FLEXPWM0_SM1_SM_CLK_SOURCE_FREQ_HZ);
/* Setup PWM output setting for submodule SM2 */
PWM_SetupPwm(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM2, FLEXPWM0_SM2_pwm_function_config, 2U, kPWM_CenterAligned, FLEXPWM0_SM2_COUNTER_FREQ_HZ, FLEXPWM0_SM2_SM_CLK_SOURCE_FREQ_HZ);
/* Initialize output trigger for VAL4 compare of submodule SM0 */
PWM_OutputTriggerEnable(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM0, kPWM_ValueRegister_1, true);
/* Enable interrupts from main config of the submodule SM0 */
PWM_EnableInterrupts(FLEXPWM0_PERIPHERAL, FLEXPWM0_SM0, (kPWM_ReloadInterruptEnable | kPWM_ReloadErrorInterruptEnable));
/* Initialize LDOK for update of the working registers */
PWM_SetPwmLdok(FLEXPWM0_PERIPHERAL, (kPWM_Control_Module_0 | kPWM_Control_Module_1 | kPWM_Control_Module_2), true);
/* Start selected counters */
PWM_StartTimer(FLEXPWM0_PERIPHERAL, (kPWM_Control_Module_0 | kPWM_Control_Module_1 | kPWM_Control_Module_2));
}
3. inputmux配置
INPUTMUX_Init(INPUTMUX0);
INPUTMUX_AttachSignal(INPUTMUX0, 0U, kINPUTMUX_Pwm0Sm0OutTrig0ToAdc0Trigger);
INPUTMUX_AttachSignal(INPUTMUX0, 0U, kINPUTMUX_Pwm0Sm0OutTrig0ToAdc1Trigger);