Hello,
I want to use PWMDAC module in Motorware in order to monitor internal signal values in my project, such as: svgen, or ramp signals, by an external oscilloscope.
In ControlSuite, I simply use PWM_MACRO in the main_ISR() as following:
// ------------------------------------------------------------------------------
// Connect inputs of the PWMDAC module
// ------------------------------------------------------------------------------
pwmdac1.MfuncC1 = svgen1.Ta;
pwmdac1.MfuncC2 = svgen1.Tb;
PWMDAC_MACRO(6,pwmdac1) // PWMDAC 6A, 6B
pwmdac1.MfuncC1 = svgen1.Tc;
pwmdac1.MfuncC2 = svgen1.Tb-svgen1.Tc;
PWMDAC_MACRO(7,pwmdac1) // PWMDAC 7A, 7B
In my project, I am using PWM6A, 6B and PWM7A, 7B as a debugging pins when connecting them to an external oscilloscope. And now I want the same function in Motorware system. I know that the Motorware provides the following settings:
#ifdef DEBUG // initialize PWM DAC handles obj->pwmDacHandle[0] = PWMDAC_init((void *)PWM_ePWM6_BASE_ADDR,sizeof(PWM_Obj)); //Using 6A obj->pwmDacHandle[1] = PWMDAC_init((void *)PWM_ePWM7_BASE_ADDR,sizeof(PWM_Obj)); //Using 7A #endif //DEBUG
and call the setting function for the parameters of this module:
#ifdef DEBUG // setup the PWM DACs HAL_setupPwmDacs(handle); #endif
and the content of the setupPwmDacs() function as following:
void HAL_setupPwmDacs(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
uint16_t halfPeriod_cycles = 512; // 3000->10kHz, 1500->20kHz, 1000-> 30kHz, 500->60kHz
uint_least8_t cnt;
for(cnt=0;cnt<3;cnt++)
{
// initialize the Time-Base Control Register (TBCTL)
PWMDAC_setCounterMode(obj->pwmDacHandle[cnt],PWM_CounterMode_UpDown);
PWMDAC_disableCounterLoad(obj->pwmDacHandle[cnt]);
PWMDAC_setPeriodLoad(obj->pwmDacHandle[cnt],PWM_PeriodLoad_Immediate);
PWMDAC_setSyncMode(obj->pwmDacHandle[cnt],PWM_SyncMode_EPWMxSYNC);
PWMDAC_setHighSpeedClkDiv(obj->pwmDacHandle[cnt],PWM_HspClkDiv_by_1);
PWMDAC_setClkDiv(obj->pwmDacHandle[cnt],PWM_ClkDiv_by_1);
PWMDAC_setPhaseDir(obj->pwmDacHandle[cnt],PWM_PhaseDir_CountUp);
PWMDAC_setRunMode(obj->pwmDacHandle[cnt],PWM_RunMode_FreeRun);
// initialize the Timer-Based Phase Register (TBPHS)
PWMDAC_setPhase(obj->pwmDacHandle[cnt],0);
// setup the Time-Base Counter Register (TBCTR)
PWMDAC_setCount(obj->pwmDacHandle[cnt],0);
// Initialize the Time-Base Period Register (TBPRD)
// set to zero initially
PWMDAC_setPeriod(obj->pwmDacHandle[cnt],0);
// initialize the Counter-Compare Control Register (CMPCTL)
PWMDAC_setLoadMode_CmpA(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
PWMDAC_setLoadMode_CmpB(obj->pwmDacHandle[cnt],PWM_LoadMode_Zero);
PWMDAC_setShadowMode_CmpA(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
PWMDAC_setShadowMode_CmpB(obj->pwmDacHandle[cnt],PWM_ShadowMode_Shadow);
// Initialize the Action-Qualifier Output A Register (AQCTLA)
PWMDAC_setActionQual_CntUp_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
PWMDAC_setActionQual_CntDown_CmpA_PwmA(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
// account for EPWM6B
if(cnt == 0)
{
PWMDAC_setActionQual_CntUp_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Clear);
PWMDAC_setActionQual_CntDown_CmpB_PwmB(obj->pwmDacHandle[cnt],PWM_ActionQual_Set);
}
// Initialize the Dead-Band Control Register (DBCTL)
PWMDAC_disableDeadBand(obj->pwmDacHandle[cnt]);
// Initialize the PWM-Chopper Control Register (PCCTL)
PWMDAC_disableChopping(obj->pwmDacHandle[cnt]);
// Initialize the Trip-Zone Control Register (TZSEL)
PWMDAC_disableTripZones(obj->pwmDacHandle[cnt]);
// Initialize the Trip-Zone Control Register (TZCTL)
PWMDAC_setTripZoneState_TZA(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
PWMDAC_setTripZoneState_TZB(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
PWMDAC_setTripZoneState_DCAEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
PWMDAC_setTripZoneState_DCAEVT2(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
PWMDAC_setTripZoneState_DCBEVT1(obj->pwmDacHandle[cnt],PWM_TripZoneState_HighImp);
}
// since the PWM is configured as an up/down counter, the period register is set to one-half
// of the desired PWM period
PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_1],halfPeriod_cycles);
PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_2],halfPeriod_cycles);
PWMDAC_setPeriod(obj->pwmDacHandle[PWMDAC_Number_3],halfPeriod_cycles);
return;
} // end of HAL_setupPwmDacs() function
The questions are:
1. How to use this module in the main_ISR() function, for example, to update an internal signal in to PWM6A, 6B and PWM7A, 7B?
2. When I see the HAL_setupPwmDacs(), three channels was setup. But in my project, there were only two channels (PWM6 and PWM7), so how will this setup effect to the third channel?
3. How can I nominalize the signals before writing them to this module?
Many thanks in advance,
Tran





