TIDUF67 April 2024
The PWMDAC module converts the software variables into PWM signals using ePWM 5A, 5B, 6A, and 6B as shown in Figure 4-32. The PWMDAC module is only supported on the high voltage kit (TMDSHVMTRINSPIN) since the module has extra PWM outputs with RC filters available on the board. If the PWMDAC module is used with a motor driver board that does not support the PWMDAC module, then the PWM signals is routed to spare PWMs on the TI LaunchPad and the user needs to add RC filters to those pins to utilize the PWMDAC design.
The PWMDAC module can be used to view the signal, represented by the variable, at the outputs of the related pins through the external low-pass filters. Therefore, the external low-pass filters are necessary to view the actual signal waveforms as seen in Figure 4-33. The (1st-order) RC low-pass filter is used to filter out the high frequency component embedded in the actual low frequency signals. To select R and C values, the time constant can be expressed in terms of the cut-off frequency (fc) as shown in the following equations.
To enable the ePWM DAC functionality, the predefined symbol EPWMDAC_MODE must be added in the project properties as shown in Figure 4-2.
The following code shows the declaration of the PWMDAC object. This code is located in the sys_main.c file.
#if defined(EPWMDAC_MODE)
#if defined(HVMTRPFC_REV1P1)
__attribute__ ((section("sys_data"))) HAL_PWMDACData_t pwmDACData;
// HVMTRPFC_REV1P1
#else
#error EPWMDAC is not supported on this kit!
#endif // !HVMTRPFC_REV1P1
#endif // EPWMDAC_MODE
The following code shows the initialization and setting up of the PWMDAC object, handle and parameters. Four module inputs, ptrData[0], ptrData[1], ptrData[2], and ptrData[3] are configured to point to the addresses of four variables. The PWMDAC module inputs point to different system variables depending on the build level. This code is located in the sys_main.c file.
// set DAC parameters
pwmDACData.periodMax =
PWMDAC_getPeriod(halHandle->pwmDACHandle[PWMDAC_NUMBER_1]);
pwmDACData.ptrData[0] = &motorVars_M1.angleFOC_rad; // PWMDAC1
pwmDACData.ptrData[1] = &motorVars_M1.speedAbs_Hz; // PWMDAC2
pwmDACData.ptrData[2] = &motorVars_M1.speedAbs_Hz; // PWMDAC3
pwmDACData.ptrData[3] = &motorVars_M1.adcData.I_A.value[1]; // PWMDAC4
pwmDACData.offset[0] = 0.5f; // PWMDAC1
pwmDACData.offset[1] = 0.0f; // PWMDAC2
pwmDACData.offset[1] = 0.0f; // PWMDAC3
pwmDACData.offset[3] = 0.5f; // PWMDAC4
pwmDACData.gain[0] = 1.0f / MATH_TWO_PI; // PWMDAC1
pwmDACData.gain[1] = 1.0f / USER_MOTOR1_FREQ_MAX_Hz; // PWMDAC2
pwmDACData.gain[2] = 1.0f / USER_MOTOR1_FREQ_MAX_Hz; // PWMDAC3
pwmDACData.gain[3] = 2.0f / USER_M1_ADC_FULL_SCALE_CURRENT_A; // PWMDAC4
The following code shows the updating of the PWM outputs with new data during the execution of the motor1ctrlISR() interrupt. This code is located in the motor1_drive.c file.
// connect inputs of the PWMDAC module.
HAL_writePWMDACData(halHandle, &pwmDACData);