38 uint32_t u32PWMClockSrc;
39 uint32_t u32NearestUnitTimeNsec;
40 uint16_t u16Prescale = 1U, u16CNR = 0xFFFFU;
70 u32PWMClockSrc /= 1000UL;
71 for(u16Prescale = 1U; u16Prescale <= 0x1000U; u16Prescale++)
73 uint32_t u32Exit = 0U;
74 u32NearestUnitTimeNsec = (1000000UL * u16Prescale) / u32PWMClockSrc;
75 if(u32NearestUnitTimeNsec < u32UnitTimeNsec)
77 if (u16Prescale == 0x1000U)
85 if (!(1000000UL * (u16Prescale + 1UL) > (u32NearestUnitTimeNsec * u32PWMClockSrc)))
111 (bpwm)->CTL1 = (1UL);
115 return (u32NearestUnitTimeNsec);
133 uint32_t u32PWMClockSrc;
135 uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
165 for(u32Prescale = 1U; u32Prescale < 0xFFFU; u32Prescale++)
167 i = (u32PWMClockSrc / u32Frequency) / u32Prescale;
176 i = u32PWMClockSrc / (u32Prescale * u32CNR);
183 (bpwm)->CTL1 = (1UL);
189 BPWM_SET_CMR(bpwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1UL) / 100UL - 1UL);
271 if(u32ChannelNum < 4U)
294 if(u32ChannelNum < 4U)
346 (bpwm)->CAPINEN |= u32ChannelMask;
347 (bpwm)->CAPCTL |= u32ChannelMask;
362 (bpwm)->CAPINEN &= ~u32ChannelMask;
363 (bpwm)->CAPCTL &= ~u32ChannelMask;
378 (bpwm)->POEN |= u32ChannelMask;
393 (bpwm)->POEN &= ~u32ChannelMask;
410 (bpwm)->CAPIEN |= (u32Edge << u32ChannelNum);
427 (bpwm)->CAPIEN &= ~(u32Edge << u32ChannelNum);
444 (bpwm)->CAPIF = (u32Edge << u32ChannelNum);
478 (bpwm)->INTEN |= (u32IntDutyType << u32ChannelNum);
665 (bpwm)->CTL0 |= (u32LoadMode << u32ChannelNum);
682 (bpwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum);
703 (bpwm)->CLKSRC = (u32ClkSrcSel);
NuMicro peripheral access layer header file.
#define BPWM_DUTY_INT_UP_COUNT_MATCH_CMP
#define BPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP
void BPWM_EnableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)
Enable selected channel to trigger ADC.
#define BPWM_SET_CNR(bpwm, u32ChannelNum, u32CNR)
This macro set the period of all channels.
void BPWM_ClearCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Clear capture interrupt of selected channel.
void BPWM_Start(BPWM_T *bpwm, uint32_t u32ChannelMask)
Start BPWM module.
void BPWM_ClearWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear the time-base counter reached its maximum value flag of selected channel.
void BPWM_EnableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)
Enable capture of selected channel(s)
uint32_t BPWM_GetWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get the time-base counter reached its maximum value flag of selected channel.
void BPWM_ClearDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear duty interrupt flag of selected channel.
void BPWM_DisablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable period interrupt of selected channel.
void BPWM_Stop(BPWM_T *bpwm, uint32_t u32ChannelMask)
Stop BPWM module.
void BPWM_EnableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
Enable load mode of selected channel.
void BPWM_DisableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Disable capture interrupt of selected channel.
uint32_t BPWM_GetCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get capture interrupt of selected channel.
void BPWM_EnablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
Enable period interrupt of selected channel.
uint32_t BPWM_ConfigOutputChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function Configure BPWM generator and get the nearest frequency in edge aligned auto-reload mode...
uint32_t BPWM_GetZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get zero interrupt of selected channel.
uint32_t BPWM_GetDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get duty interrupt flag of selected channel.
void BPWM_EnableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Enable capture interrupt of selected channel.
void BPWM_DisableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)
Disable capture of selected channel(s)
void BPWM_DisableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable duty interrupt of selected channel.
void BPWM_ClearADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)
Clear selected channel trigger ADC flag.
void BPWM_DisableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)
Disables BPWM output generation of selected channel(s)
#define BPWM_SET_CMR(bpwm, u32ChannelNum, u32CMR)
This macro set the duty of the selected channel.
uint32_t BPWM_ConfigCaptureChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
Configure BPWM capture and get the nearest unit time.
#define BPWM_SET_PRESCALER(bpwm, u32ChannelNum, u32Prescaler)
This macro set the prescaler of all channels.
void BPWM_EnableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)
Enables BPWM output generation of selected channel(s)
void BPWM_ClearZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear zero interrupt of selected channel.
uint32_t BPWM_GetPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get period interrupt of selected channel.
void BPWM_EnableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
Enable duty interrupt of selected channel.
uint32_t BPWM_GetADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get selected channel trigger ADC flag.
void BPWM_DisableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
Disable load mode of selected channel.
void BPWM_ForceStop(BPWM_T *bpwm, uint32_t u32ChannelMask)
Stop BPWM generation immediately by clear channel enable bit.
void BPWM_SetClockSource(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)
Set BPWM clock source.
void BPWM_ClearPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear period interrupt of selected channel.
void BPWM_DisableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable zero interrupt of selected channel.
void BPWM_EnableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Enable zero interrupt of selected channel.
void BPWM_DisableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable selected channel to trigger ADC.
uint32_t CLK_GetPCLK1Freq(void)
Get PCLK1 frequency.
uint32_t CLK_GetPCLK0Freq(void)
Get PCLK0 frequency.
uint32_t CLK_GetPLLClockFreq(void)
Get PLL clock frequency.
#define BPWM_WGCTL0_PRDPCTL0_Pos
#define BPWM_INTSTS_CMPDIF0_Msk
#define BPWM_STATUS_EADCTRG0_Msk
#define BPWM_WGCTL1_CMPDCTL0_Pos
#define BPWM_EADCTS1_TRGSEL4_Msk
#define BPWM_CAPIF_CAPRIF0_Msk
#define BPWM_WGCTL1_CMPUCTL0_Msk
#define BPWM_EADCTS1_TRGEN4_Msk
#define BPWM_WGCTL0_ZPCTL0_Msk
#define BPWM_INTSTS_CMPUIF0_Msk
#define BPWM_CNTEN_CNTEN0_Msk
#define BPWM_EADCTS0_TRGSEL0_Msk
#define BPWM_INTEN_ZIEN0_Msk
#define BPWM_INTSTS_PIF0_Msk
#define BPWM_EADCTS0_TRGEN0_Msk
#define BPWM_INTEN_PIEN0_Msk
#define BPWM_WGCTL0_PRDPCTL0_Msk
#define BPWM_WGCTL1_CMPDCTL0_Msk
#define CLK_CLKSEL2_BPWM1SEL_Msk
#define BPWM_INTSTS_ZIF0_Msk
#define BPWM_WGCTL0_ZPCTL0_Pos
#define CLK_CLKSEL2_BPWM0SEL_Msk
#define BPWM_CAPIF_CAPFIF0_Msk
#define BPWM_STATUS_CNTMAX0_Msk
void SystemCoreClockUpdate(void)
Updates the SystemCoreClock with current core Clock retrieved from cpu registers.