/** * \brief Set PDC transfer request mode. * * \note If configure Synchronous channels update mode as 'PWM_SYNC_UPDATE_MODE_0' or 'PWM_SYNC_UPDATE_MODE_1' via pwm_sync_init(), ul_pdc_request will be ignored and PDC transfer request will never occur. * * \param p_pwm Pointer to a PWM instance. * \param request_mode PDC transfer request mode. * \param ul_cmp_unit PWM comparison unit number for PDC transfer request. */ void pwm_pdc_set_request_mode(Pwm *p_pwm, pwm_pdc_request_mode_t request_mode, uint32_t ul_cmp_unit) { uint32_t sync_mode = p_pwm->PWM_SCM; sync_mode &= ~(PWM_SCM_PTRCS_Msk | PWM_SCM_PTRM); sync_mode |= (PWM_SCM_PTRCS(ul_cmp_unit) | request_mode); p_pwm->PWM_SCM = sync_mode; }
/*------------------------------------------------------------------------------ Name: configurePWMC parameters: - description: initializes the PWM controller ------------------------------------------------------------------------------*/ void BldcControl::configurePWMC(void) { uint32_t clka = 0; /* clock A not used */ uint32_t clkb = 0; /* clock B not used */ uint32_t mck = MCK_CLOCK_42MHZ; uint16_t duty = 0; uint16_t deadTime; pwmPeriod = MCK_CLOCK_42MHZ / this->periphery->Pwm.pwmSwFrq; deadTime = (uint16_t)(pwmPeriod * (DEAD_TIME * this->periphery->Pwm.pwmSwFrq * 2)); /* disable all 3 channels */ PWMC_DisableChannel(PWM, this->periphery->Pwm.pwmChU); PWMC_DisableChannel(PWM, this->periphery->Pwm.pwmChV); PWMC_DisableChannel(PWM, this->periphery->Pwm.pwmChW); PWMC_ConfigureClocks(clka, clkb, mck); /* initialize all 3 channels */ PWMC_ConfigureChannelExt(PWM, this->periphery->Pwm.pwmChU, /* channel ID */ PWM_CMR_CPRE_MCK, /* use main clock */ PWM_CMR_CALG, /* center alligned */ 0, /* polarity low level */ 0, /* event counter = 0 */ PWM_CMR_DTE, /* enable dead time */ 0, /* no inversion of dead time H */ 0); /* no inversion of dead time L */ PWMC_ConfigureChannelExt(PWM, this->periphery->Pwm.pwmChV, /* channel ID */ PWM_CMR_CPRE_MCK, PWM_CMR_CALG, /* center alligned */ 0, /* polarity low level */ 0, /* event counter = 0 */ PWM_CMR_DTE, /* enable dead time */ 0, /* no inversion of dead time H */ 0); /* no inversion of dead time L */ PWMC_ConfigureChannelExt(PWM, this->periphery->Pwm.pwmChW, /* channel ID */ PWM_CMR_CPRE_MCK, PWM_CMR_CALG, /* center alligned */ 0, /* polarity low level */ 0, /* event counter = 0 */ PWM_CMR_DTE, /* enable dead time */ 0, /* no inversion of dead time H */ 0); /* no inversion of dead time L */ PWMC_ConfigureSyncChannel(PWM, PWM_SCM_SYNC0|PWM_SCM_SYNC1|PWM_SCM_SYNC2, PWM_SCM_UPDM_MODE0, PWM_SCM_PTRM, PWM_SCM_PTRCS(0)) ; /* set periods */ PWMC_SetPeriod(PWM, this->periphery->Pwm.pwmChU, pwmPeriod); PWMC_SetPeriod(PWM, this->periphery->Pwm.pwmChV, pwmPeriod); PWMC_SetPeriod(PWM, this->periphery->Pwm.pwmChW, pwmPeriod); /* set duty cycles */ PWMC_SetDutyCycle(PWM, this->periphery->Pwm.pwmChU, duty); PWMC_SetDutyCycle(PWM, this->periphery->Pwm.pwmChV, duty); PWMC_SetDutyCycle(PWM, this->periphery->Pwm.pwmChW, duty); /* set dead times */ PWMC_SetDeadTime(PWM, this->periphery->Pwm.pwmChU, deadTime, deadTime); PWMC_SetDeadTime(PWM, this->periphery->Pwm.pwmChV, deadTime, deadTime); PWMC_SetDeadTime(PWM, this->periphery->Pwm.pwmChW, deadTime, deadTime); /* set overwrites to 0 */ PWMC_SetOverrideValue(PWM, 0); /* set event for ADC trigger */ PWM->PWM_CMP[this->periphery->Pwm.pwmChU].PWM_CMPM |= PWM_CMPM_CEN | /* enable */ PWM_CMPM_CTR(0) | /* each period */ PWM_CMPM_CPR(0); PWM->PWM_CMP[this->periphery->Pwm.pwmChU].PWM_CMPV = pwmPeriod/2; /* set trigger */ PWM->PWM_ELMR[0] |= PWM_ELMR_CSEL0; /* enable event line 0 */ }