37 uint32_t u32PWMClockSrc;
38 uint32_t u32NearestUnitTimeNsec;
39 uint16_t u16Prescale = 1, u16CNR = 0xFFFF;
58 u32PWMClockSrc /= 1000;
59 for(u16Prescale = 1; u16Prescale <= 0x1000; u16Prescale++)
61 u32NearestUnitTimeNsec = (1000000 * u16Prescale) / u32PWMClockSrc;
62 if(u32NearestUnitTimeNsec < u32UnitTimeNsec)
64 if(u16Prescale == 0x1000)
66 if(!((1000000 * (u16Prescale + 1) > (u32NearestUnitTimeNsec * u32PWMClockSrc))))
78 (pwm)->CTL1 = ((pwm)->CTL1 & ~(
PWM_CTL1_CNTTYPE0_Msk << (2 * u32ChannelNum))) | (1UL << (2 * u32ChannelNum));
83 return (u32NearestUnitTimeNsec);
101 uint32_t u32PWMClockSrc;
103 uint16_t u16Prescale = 1, u16CNR = 0xFFFF;
122 for(u16Prescale = 1; u16Prescale < 0xFFF; u16Prescale++)
124 i = (u32PWMClockSrc / u32Frequency) / u16Prescale;
133 i = u32PWMClockSrc / (u16Prescale * u16CNR);
139 (pwm)->CTL1 = ((pwm)->CTL1 & ~(
PWM_CTL1_CNTTYPE0_Msk << (2 * u32ChannelNum))) | (1UL << (2 * u32ChannelNum));
146 PWM_SET_CMR(pwm, u32ChannelNum, u32DutyCycle * (u16CNR + 1) / 100 - 1);
176 (pwm)->CNTEN |= u32ChannelMask;
194 if(u32ChannelMask & (1 << i))
196 (pwm)->PERIOD[i] = 0;
213 (pwm)->CNTEN &= ~u32ChannelMask;
244 if(u32ChannelNum < 4)
267 if(u32ChannelNum < 4)
336 if(u32ChannelMask & (1 << i))
343 (pwm)->FAILBRK |= (u32BrakeSource & 0xF);
347 *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= u32BrakeSource;
351 if(u32LevelMask & (1 << i))
397 (pwm)->CAPINEN |= u32ChannelMask;
398 (pwm)->CAPCTL |= u32ChannelMask;
413 (pwm)->CAPINEN &= ~u32ChannelMask;
414 (pwm)->CAPCTL &= ~u32ChannelMask;
429 (pwm)->POEN |= u32ChannelMask;
444 (pwm)->POEN &= ~u32ChannelMask;
465 u32IsOddCh = u32ChannelNum % 2;
500 *(__IO uint32_t *)(&((pwm)->DTCTL0_1) + (u32ChannelNum >> 1)) &= ~PWM_DTCTL0_1_DTCNT_Msk;
501 *(__IO uint32_t *)(&((pwm)->DTCTL0_1) + (u32ChannelNum >> 1)) |=
PWM_DTCTL0_1_DTEN_Msk | u32Duration;
517 *(__IO uint32_t *)(&((pwm)->DTCTL0_1) + (u32ChannelNum >> 1)) &= ~PWM_DTCTL0_1_DTEN_Msk;
534 (pwm)->CAPIEN |= (u32Edge << u32ChannelNum);
551 (pwm)->CAPIEN &= ~(u32Edge << u32ChannelNum);
568 (pwm)->CAPIF = (u32Edge << u32ChannelNum);
602 (pwm)->INTEN0 |= (u32IntDutyType << u32ChannelNum);
662 (pwm)->INTEN1 |= (0x7 << u32BrakeSource);
678 (pwm)->INTEN1 &= ~(0x7 << u32BrakeSource);
693 (pwm)->INTSTS1 = (0x3f << u32BrakeSource);
709 return (((pwm)->INTSTS1 & (0x3f << u32BrakeSource)) ? 1 : 0);
976 (pwm)->CTL0 |= (u32LoadMode << u32ChannelNum);
994 (pwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum);
1019 u32ChannelNum >>= 1;
1022 *(__IO uint32_t *)(&((pwm)->PHS0_1) + u32ChannelNum) = u32StartPhase;
1042 if(u32ChannelMask & (1 << i))
1065 if(u32ChannelMask & (1 << i))
#define PWM_INTEN0_PIEN0_Msk
#define PWM_INTEN0_ZIEN0_Msk
#define PWM_CLKSRC_ECLKSRC0_Msk
#define PWM_SYNC_PHSEN0_Msk
#define PWM_BRKCTL0_1_BRKAODD_Pos
#define PWM_PDMACTL_CAPORD0_1_Pos
#define PWM_WGCTL1_CMPDCTL0_Msk
#define PWM_SYNC_SINPINV_Msk
#define PWM_INTSTS0_CMPDIF0_Msk
#define PWM_BNF_BRK0NFEN_Msk
#define PWM_BRKCTL0_1_BRKAEVEN_Pos
#define PWM_INTSTS0_ZIF0_Msk
#define PWM_SYNC_SFLTCNT_Msk
#define PWM_BNF_BRK0NFSEL_Msk
#define PWM_INTSTS0_CMPUIF0_Msk
#define PWM_SYNC_SFLTCSEL_Pos
#define PWM_SYNC_SINSRC0_Pos
#define PWM_WGCTL0_ZPCTL0_Pos
#define PWM_IFA_IFSEL0_1_Msk
#define PWM_INTSTS0_IFAIF0_1_Msk
#define PWM_BNF_BK0SRC_Pos
#define PWM_CAPIF_CRLIF0_Msk
#define PWM_SYNC_PHSDIR0_Pos
#define PWM_WGCTL1_CMPUCTL0_Msk
#define PWM_BNF_BRK0FCNT_Pos
#define PWM_PDMACTL_CHSEL0_1_Pos
#define PWM_WGCTL0_ZPCTL0_Msk
#define PWM_SYNC_SFLTCSEL_Msk
#define PWM_PDMACTL_CAPORD0_1_Msk
#define PWM_STATUS_ADCTRGF0_Msk
#define PWM_SYNC_SFLTCNT_Pos
#define PWM_SYNC_SINSRC0_Msk
#define PWM_FTCI_FTCMD0_Msk
#define PWM_SYNC_PHSDIR0_Msk
#define PWM_PDMACTL_CHSEL0_1_Msk
#define PWM_CLKSRC_ECLKSRC2_Pos
#define PWM_FTCI_FTCMU0_Msk
#define PWM_BNF_BRK1NFEN_Pos
#define PWM_BRKCTL0_1_SYSEBEN_Msk
#define PWM_BNF_BRK0NFSEL_Pos
#define PWM_CAPIF_CFLIF0_Msk
#define PWM_CTL1_CNTTYPE0_Msk
#define PWM_EADCTS1_TRGEN4_Msk
#define PWM_WGCTL1_CMPDCTL0_Pos
#define PWM_IFA_IFAEN0_1_Msk
#define PWM_PDMACTL_CHEN0_1_Msk
#define PWM_EADCTS0_TRGSEL0_Msk
#define PWM_WGCTL0_PRDPCTL0_Msk
#define PWM_BRKCTL0_1_BRKAODD_Msk
#define PWM_CTL1_CNTMODE0_Msk
#define PWM_INTSTS0_PIF0_Msk
#define PWM_EADCTS1_TRGSEL4_Msk
#define PWM_BRKCTL0_1_BRKAEVEN_Msk
#define PWM_PDMACTL_CAPMOD0_1_Msk
#define PWM_WGCTL0_PRDPCTL0_Pos
#define PWM_BRKCTL0_1_SYSLBEN_Msk
#define PWM_BNF_BRK0FCNT_Msk
#define PWM_BNF_BK0SRC_Msk
#define PWM_DTCTL0_1_DTEN_Msk
#define PWM_BNF_BRK0PINV_Msk
#define PWM_INTEN0_IFAIEN0_1_Msk
#define PWM_IFA_IFCNT0_1_Msk
#define PWM_STATUS_CNTMAXF0_Msk
#define PWM_IFA_IFSEL0_1_Pos
#define PWM_SYNC_SNFLTEN_Msk
#define PWM_EADCTS0_TRGEN0_Msk
NuMicro peripheral access layer header file.
__STATIC_INLINE uint32_t CLK_GetPLLClockFreq(void)
Get PLL clock frequency.
#define CLK_CLKSEL2_PWM0SEL_Msk
#define CLK_CLKSEL2_PWM1SEL_Msk
#define PWM_DUTY_INT_UP_COUNT_MATCH_CMP
#define PWM_FB_LEVEL_SYS_COR
#define PWM_FB_LEVEL_SYS_CSS
#define PWM_FB_EDGE_SYS_COR
#define PWM_DUTY_INT_DOWN_COUNT_MATCH_CMP
#define PWM_FB_EDGE_SYS_BOD
#define PWM_FB_EDGE_SYS_CSS
#define PWM_FB_LEVEL_SYS_BOD
void PWM_ClearZeroIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Clear zero interrupt of selected channel.
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
Stop PWM generation immediately by clear channel enable bit.
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
Stop PWM module.
void PWM_EnableSyncPhase(PWM_T *pwm, uint32_t u32ChannelMask)
Enable SYNC phase of selected channel(s)
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
Enable capture of selected channel(s)
void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
Enables PDMA transfer of selected channel for PWM capture.
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
Enable Dead zone of selected channel.
void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Clear capture interrupt of selected channel.
void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
Clear selected channel trigger EADC flag.
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
Disable selected channel to trigger EADC.
uint32_t PWM_ConfigCaptureChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
Configure PWM capture and get the nearest unit time.
void PWM_EnableBrakeNoiseFilter(PWM_T *pwm, uint32_t u32BrakePinNum, uint32_t u32ClkCnt, uint32_t u32ClkDivSel)
Enable PWM brake noise filter function.
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
Disable period interrupt of selected channel.
void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
Enable duty interrupt of selected channel.
uint32_t PWM_GetAccInt(PWM_T *pwm, uint32_t u32ChannelNum)
Get interrupt flag accumulator interrupt of selected channel.
uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function get fault brake interrupt flag of selected source.
uint32_t PWM_GetFTDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get free trigger duty interrupt flag of selected channel.
void PWM_ClearFTDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Clear free trigger duty interrupt flag of selected channel.
void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Disable capture interrupt of selected channel.
void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function disable fault brake interrupt.
uint32_t PWM_ConfigOutputChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function Configure PWM generator and get the nearest frequency in edge aligned auto-reload mode.
void PWM_DisableLoadMode(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
Disable load mode of selected channel.
void PWM_ConfigSyncPhase(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32SyncSrc, uint32_t u32Direction, uint32_t u32StartPhase)
Configure synchronization phase of selected channel.
void PWM_DisableSyncNoiseFilter(PWM_T *pwm)
Disable PWM SYNC_IN noise filter function.
void PWM_DisableBrakeNoiseFilter(PWM_T *pwm, uint32_t u32BrakePinNum)
Disable PWM brake noise filter function.
void PWM_SetClockSource(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)
Set PWM clock source.
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get selected channel trigger EADC flag.
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
Disable capture of selected channel(s)
void PWM_ClearWrapAroundFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Clear the time-base counter reached its maximum value flag of selected channel.
uint32_t PWM_GetZeroIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get zero interrupt of selected channel.
void PWM_EnableAcc(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntFlagCnt, uint32_t u32IntAccSrc)
Enable interrupt flag accumulator of selected channel.
#define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR)
This macro set the comparator of the selected channel.
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
Disable duty interrupt of selected channel.
void PWM_EnableBrakePinInverse(PWM_T *pwm, uint32_t u32BrakePinNum)
Enable PWM brake pin inverse function.
void PWM_EnableLoadMode(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
Enable load mode of selected channel.
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Clear duty interrupt flag of selected channel.
#define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR)
This macro set the period of the selected channel.
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
Enable period interrupt of selected channel.
void PWM_EnableFaultBrake(PWM_T *pwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
This function enable fault brake of selected channel(s)
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get duty interrupt flag of selected channel.
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
Disable Dead zone of selected channel.
void PWM_ClearAccInt(PWM_T *pwm, uint32_t u32ChannelNum)
Clear interrupt flag accumulator interrupt of selected channel.
uint32_t PWM_GetWrapAroundFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get the time-base counter reached its maximum value flag of selected channel.
void PWM_EnableAccInt(PWM_T *pwm, uint32_t u32ChannelNum)
Enable interrupt flag accumulator interrupt of selected channel.
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
Disables PWM output generation of selected channel(s)
void PWM_SetBrakePinSource(PWM_T *pwm, uint32_t u32BrakePinNum, uint32_t u32SelAnotherModule)
Set PWM brake pin source.
void PWM_DisableAcc(PWM_T *pwm, uint32_t u32ChannelNum)
Disable interrupt flag accumulator of selected channel.
void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake interrupt of selected source.
void PWM_EnableZeroInt(PWM_T *pwm, uint32_t u32ChannelNum)
Enable zero interrupt of selected channel.
#define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler)
This macro set the prescaler of the selected channel.
void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum)
Disables PDMA transfer of selected channel for PWM capture.
void PWM_DisableSyncPinInverse(PWM_T *pwm)
Disable PWM SYNC input pin inverse function.
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
Start PWM module.
void PWM_DisableZeroInt(PWM_T *pwm, uint32_t u32ChannelNum)
Disable zero interrupt of selected channel.
void PWM_DisableBrakePinInverse(PWM_T *pwm, uint32_t u32BrakePinNum)
Disable PWM brake pin inverse function.
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Clear period interrupt of selected channel.
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
Enables PWM output generation of selected channel(s)
void PWM_DisableSyncPhase(PWM_T *pwm, uint32_t u32ChannelMask)
Disable SYNC phase of selected channel(s)
void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function enable fault brake interrupt.
void PWM_EnableSyncPinInverse(PWM_T *pwm)
Enable PWM SYNC input pin inverse function.
void PWM_DisableAccInt(PWM_T *pwm, uint32_t u32ChannelNum)
Disable interrupt flag accumulator interrupt of selected channel.
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get capture interrupt of selected channel.
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
Get period interrupt of selected channel.
void PWM_EnableSyncNoiseFilter(PWM_T *pwm, uint32_t u32ClkCnt, uint32_t u32ClkDivSel)
Enable PWM SYNC_IN noise filter function.
void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Enable capture interrupt of selected channel.
void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
Enable selected channel to trigger EADC.
void SystemCoreClockUpdate(void)
Updates the SystemCoreClock with current core Clock retrieved from cpu registers.