Hello. I have custom board with TM4C123GH6PM MCU and drv835 for driving bldc motor. I need to measure current while low side mosfet is opend. I set up pwm in up-down counting mode. I think, PWM should generate trigger event for ADC then counter is equal to zero. There are my code of initialization:
void PWM_Init(){ SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)); PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PWM_PERIOD); PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, PWM_PERIOD); PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, PWM_PERIOD); PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_ZERO); PWMGenEnable(PWM0_BASE, PWM_GEN_0); PWMGenEnable(PWM0_BASE, PWM_GEN_2); PWMGenEnable(PWM0_BASE, PWM_GEN_3); PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0_BIT | PWM_GEN_2_BIT | PWM_GEN_3_BIT); PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_4_BIT | PWM_OUT_6_BIT), true); } void ADC_Init(){ SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // // Wait for the ADC0 module to be ready. // while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)); // // Enable the first sample sequencer to capture the value of channel 0 when // the processor trigger occurs. // ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END); ADCIntRegister(ADC0_BASE, 1, handler_ADC); ADCIntEnable(ADC0_BASE, 1); ADCSequenceEnable(ADC0_BASE, 1); } void handler_ADC(void) { unsigned int state = ADCIntStatus(ADC0_BASE, 0, true); ADCIntClear(ADC0_BASE, 0); //TODO }
So, PWM work as expected. But ADC doesn't. I wanna get interrupts, then ADC finished measuring, and load results from ADCs FIFO. I have no idea, how to fix it. And I have no found examples for this issue.