| NUC029FAE_BSP V3.02.000 The Board Support Package for NUC029FAE MCU

pwm.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __PWM_H__
13#define __PWM_H__
14
15#ifdef __cplusplus
16 extern "C"
17{
18#endif
19
20
32#define PWM_CHANNEL_NUM (6)
33#define PWM_CLK_DIV_1 (4UL)
34#define PWM_CLK_DIV_2 (0UL)
35#define PWM_CLK_DIV_4 (1UL)
36#define PWM_CLK_DIV_8 (2UL)
37#define PWM_CLK_DIV_16 (3UL)
38#define PWM_EDGE_ALIGNED (0UL)
39#define PWM_CENTER_ALIGNED (PWM_PCR_PWMTYPE_Msk)
40#define PWM_TRIGGER_ADC_CNTR_IS_0 PWM_TRGCON0_P0TRGEN_Msk
41#define PWM_TRIGGER_ADC_CNTR_IS_CMR_D PWM_TRGCON0_CM0TRGFEN_Msk
42#define PWM_TRIGGER_ADC_CNTR_IS_CNR PWM_TRGCON0_CNT0TRGEN_Msk
43#define PWM_TRIGGER_ADC_CNTR_IS_CMR_U PWM_TRGCON0_CM0TRGREN_Msk
44#define PWM_FB0_EINT0 (PWM_PFBCON_BKEN0_Msk)
45#define PWM_FB0_ACMP1 (PWM_PFBCON_BKEN0_Msk | PWM_PFBCON_CPO1BKEN_Msk)
46#define PWM_FB1_EINT1 (PWM_PFBCON_BKEN1_Msk)
47#define PWM_FB1_ACMP0 (PWM_PFBCON_BKEN1_Msk | PWM_PFBCON_CPO0BKEN_Msk)
48#define PWM_PERIOD_INT_UNDERFLOW (0)
49#define PWM_PERIOD_INT_MATCH_CNR (PWM_PIER_INT_TYPE_Msk) /* end of group NUC029FAE_PWM_EXPORTED_CONSTANTS */
52
53
64#define PWM_ENABLE_COMPLEMENTARY_MODE(pwm) (PWM->PCR = (PWM->PCR & ~PWM_PCR_PWMMOD_Msk) |(1UL << PWM_PCR_PWMMOD_Pos))
65
72#define PWM_DISABLE_COMPLEMENTARY_MODE(pwm) (PWM->PCR &= ~PWM_PCR_PWMMOD_Msk)
73
80#define PWM_ENABLE_GROUP_MODE(pwm) (PWM->PCR |= PWM_PCR_GRP_Msk)
81
88#define PWM_DISABLE_GROUP_MODE(pwm) (PWM->PCR &= ~PWM_PCR_GRP_Msk)
89
96#define PWM_ENABLE_SYNC_MODE(pwm) (PWM->PCR = (PWM->PCR & ~PWM_PCR_PWMMOD_Msk) |(2UL << PWM_PCR_PWMMOD_Pos))
97
104#define PWM_DISABLE_SYNC_MODE(pwm) (PWM->PCR &= ~PWM_PCR_PWMMOD_Msk)
105
114#define PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask) \
115 do{ \
116 int i;\
117 for(i = 0; i < 6; i++) { \
118 if((u32ChannelMask) & (1 << i)) \
119 PWM->PCR |= (PWM_PCR_CH0INV_Msk << (PWM_PCR_CH0INV_Pos + (i * 4))); \
120 } \
121 }while(0)
122
133#define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler) \
134 (PWM->PPR = (PWM->PPR & ~(PWM_PPR_CP01_Msk << (((u32ChannelNum) >> 1) * 8))) | ((u32Prescaler) << (((u32ChannelNum) >> 1) * 8)))
135
149#define PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider) \
150 (PWM->CSR = (PWM->CSR & ~(PWM_CSR_CSR0_Msk << ((u32ChannelNum) * 4))) | ((u32Divider) << ((u32ChannelNum) * 4)))
151
161#define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR) (PWM->CMR[u32ChannelNum] = (u32CMR))
162
173#define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR) (PWM->CNR[u32ChannelNum] = (u32CNR))
174
185#define PWM_SET_ALIGNED_TYPE(pwm, u32ChannelMask, u32AlignedType) \
186 (PWM->PCR = (PWM->PCR & ~PWM_PCR_PWMTYPE_Msk) | (u32AlignedType))
187
188
189uint32_t PWM_ConfigOutputChannel(PWM_T *pwm,
190 uint32_t u32ChannelNum,
191 uint32_t u32Frequency,
192 uint32_t u32DutyCycle);
193 void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask);
194 void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask);
195 void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask);
196 void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
197 void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum);
198 void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
199uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum);
200 void PWM_EnableFaultBrake(PWM_T *pwm,
201 uint32_t u32ChannelMask,
202 uint32_t u32LevelMask,
203 uint32_t u32BrakeSource);
204 void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource);
205 void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
206 void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
207 void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration);
208 void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum);
209 void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType);
210 void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum);
211 void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
212uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
213 void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource);
214 void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource);
215 void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource);
216uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource);
217 void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
218 void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
219 void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
220uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
221
222
223 /* end of group NUC029FAE_PWM_EXPORTED_FUNCTIONS */
225 /* end of group NUC029FAE_PWM_Driver */
227 /* end of group NUC029FAE_Device_Driver */
229
230#ifdef __cplusplus
231}
232#endif
233
234#endif //__PWM_H__
235
236/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
PWM_ForceStop
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM generation immediately by clear channel enable bit.
Definition: pwm.c:151
PWM_Stop
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
Definition: pwm.c:131
PWM_EnableDeadZone
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone of selected channel.
Definition: pwm.c:337
PWM_ClearADCTriggerFlag
void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function clear selected channel trigger ADC flag.
Definition: pwm.c:230
PWM_DisableADCTrigger
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
Definition: pwm.c:201
PWM_DisablePeriodInt
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
Definition: pwm.c:479
PWM_EnableDutyInt
void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
This function enable duty interrupt of selected channel.
Definition: pwm.c:368
PWM_GetFaultBrakeIntFlag
uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function get fault brake interrupt of selected source.
Definition: pwm.c:453
PWM_DisableFaultBrakeInt
void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function disable fault brake interrupt.
Definition: pwm.c:425
PWM_ConfigOutputChannel
uint32_t PWM_ConfigOutputChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode.
Definition: pwm.c:37
PWM_GetADCTriggerFlag
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get selected channel trigger ADC flag.
Definition: pwm.c:252
PWM_DisableDutyInt
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable duty interrupt of selected channel.
Definition: pwm.c:379
PWM_ClearDutyIntFlag
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
Definition: pwm.c:390
PWM_EnablePeriodInt
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
Definition: pwm.c:468
PWM_EnableFaultBrake
void PWM_EnableFaultBrake(PWM_T *pwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
This function enable fault brake of selected channels.
Definition: pwm.c:285
PWM_GetDutyIntFlag
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag of selected channel.
Definition: pwm.c:403
PWM_DisableDeadZone
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
Definition: pwm.c:353
PWM_DisableOutput
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
Definition: pwm.c:324
PWM_ClearFaultBrakeIntFlag
void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake interrupt of selected source.
Definition: pwm.c:438
PWM_Start
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:110
PWM_ClearPeriodIntFlag
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
Definition: pwm.c:490
PWM_EnableOutput
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:312
PWM_EnableFaultBrakeInt
void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function enable fault brake interrupt.
Definition: pwm.c:414
PWM_GetPeriodIntFlag
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
Definition: pwm.c:503
PWM_ClearFaultBrakeFlag
void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake flag.
Definition: pwm.c:300
PWM_EnableADCTrigger
void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function enable selected channel to trigger ADC.
Definition: pwm.c:176
PWM_T
Definition: NUC029FAE.h:1172