Hi,
I recently changed from working with the Double Sampling Configuration to Single Sampling using the Dual Motor FCL Projects. When using double sampling the M1 and M2 ISRs were offset by 1/2 a Period. I.e. If running at 10 Khz (100 us) each ISR was 50 uS apart from each other. After I switched from Double -> Single, I see that the M2 waveform is shifted by 1/4 of a period instead of 1/2. This behavior is causing some timing issues with other parts of our system.
I believe that the following code from HAL_setupMotorPWMs is responsible for synchronizing the time base between the two motors:
else if(handle == &halMtr[MTR_2]) { halfPeriod = M2_INV_PWM_TICKS/2; // 100MHz EPWMCLK EPWM_setPhaseShift(obj->pwmHandle[0], ((halfPeriod>>1) + 0)); EPWM_setPhaseShift(obj->pwmHandle[1], ((halfPeriod>>1) + 2)); EPWM_setPhaseShift(obj->pwmHandle[2], ((halfPeriod>>1) + 4)); EPWM_setTimeBasePeriod(obj->pwmHandle[0], halfPeriod); EPWM_setTimeBasePeriod(obj->pwmHandle[1], halfPeriod); EPWM_setTimeBasePeriod(obj->pwmHandle[2], halfPeriod); }
Questions
- When running in Single Sampling mode, is there any reason that the period is divided by two again? When I remove the ">>1" the setPhaseShift the motor draws a lot of current and doesn't rotate (as if Id is really high). However, when I look at the ISR timing on a scope, they are evenly split across the PWM period.
- While I was trying to root cause this behavior, I noticed that the carrierMid value is scaled differently for Dual and Single Sampling Setups. (initMotorParameters function in dual_axis_servo_drive_user.c) Is this intentional?
#if(SAMPLING_METHOD == SINGLE_SAMPLING) pMotor->maxModIndex = (M1_TPWM_CARRIER - (2 * M1_FCL_COMPUTATION_TIME)) / M1_TPWM_CARRIER; pMotor->FCL_params.carrierMid = pMotor->maxModIndex * M1_INV_PWM_HALF_TBPRD * 0x10000L; #elif(SAMPLING_METHOD == DOUBLE_SAMPLING) pMotor->maxModIndex = (M1_TPWM_CARRIER - (4 * M1_FCL_COMPUTATION_TIME)) / M1_TPWM_CARRIER; pMotor->FCL_params.carrierMid = M1_INV_PWM_HALF_TBPRD * 0x10000L; #endif
Thanks,
-Colin