| MINI58_BSP V3.01.003 The Board Support Package for Mini58 Series 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_CTL_CNTTYPE_Msk)
40#define PWM_TRIGGER_ADC_CNTR_IS_0 PWM_ADCTCTL0_ZPTRGEN0_Msk
41#define PWM_TRIGGER_ADC_CNTR_IS_CMR_D PWM_ADCTCTL0_CDTRGEN0_Msk
42#define PWM_TRIGGER_ADC_CNTR_IS_CNR PWM_ADCTCTL0_CPTRGEN0_Msk
43#define PWM_TRIGGER_ADC_CNTR_IS_CMR_U PWM_ADCTCTL0_CUTRGEN0_Msk
44#define PWM_FB0_EINT0 (PWM_BRKCTL_BRK0EN_Msk)
45#define PWM_FB0_ACMP1 (PWM_BRKCTL_BRK0EN_Msk | PWM_BRKCTL_BRK1SEL_Msk)
46#define PWM_FB1_EINT1 (PWM_BRKCTL_BRK1EN_Msk)
47#define PWM_FB1_ACMP0 (PWM_BRKCTL_BRK1EN_Msk | PWM_BRKCTL_BRK0SEL_Msk)
48#define PWM_PERIOD_INT_UNDERFLOW (0)
49#define PWM_PERIOD_INT_MATCH_CNR (PWM_INTEN_PINTTYPE_Msk)
50/*---------------------------------------------------------------------------------------------------------*/
51/* PWM Group channel number constants definitions */
52/*---------------------------------------------------------------------------------------------------------*/
53#define PWM_CH0 0x0
54#define PWM_CH1 0x1
55#define PWM_CH2 0x2
56#define PWM_CH3 0x3
57#define PWM_CH4 0x4
58#define PWM_CH5 0x5 /* end of group Mini58_PWM_EXPORTED_CONSTANTS */
61
62
73#define PWM_ENABLE_COMPLEMENTARY_MODE(pwm) ((pwm)->CTL = (PWM->CTL & ~PWM_CTL_MODE_Msk) |(1UL << PWM_CTL_MODE_Pos))
74
81#define PWM_DISABLE_COMPLEMENTARY_MODE(pwm) ((pwm)->CTL &= ~PWM_CTL_MODE_Msk)
82
89#define PWM_ENABLE_GROUP_MODE(pwm) ((pwm)->CTL |= PWM_CTL_GROUPEN_Msk)
90
97#define PWM_DISABLE_GROUP_MODE(pwm) ((pwm)->CTL &= ~PWM_CTL_GROUPEN_Msk)
98
105#define PWM_ENABLE_SYNC_MODE(pwm) (PWM->CTL = ((pwm)->CTL & ~PWM_CTL_MODE_Msk) |(2UL << PWM_CTL_MODE_Pos))
106
113#define PWM_DISABLE_SYNC_MODE(pwm) ((pwm)->CTL &= ~PWM_CTL_MODE_Msk)
114
123#define PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask) \
124 do{ \
125 int i;\
126 (pwm)->CTL &= ~(PWM_CTL_PINV0_Msk|PWM_CTL_PINV1_Msk|PWM_CTL_PINV2_Msk|PWM_CTL_PINV3_Msk|PWM_CTL_PINV4_Msk|PWM_CTL_PINV5_Msk);\
127 for(i = 0; i < 6; i++) { \
128 if((u32ChannelMask) & (1 << i)) \
129 (pwm)->CTL |= (1 << (PWM_CTL_PINV0_Pos + (i * 4))); \
130 } \
131 }while(0)
132
143#define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler) \
144 ((pwm)->CLKPSC = ((pwm)->CLKPSC & ~(PWM_CLKPSC_CLKPSC01_Msk << (((u32ChannelNum) >> 1) * 8))) | ((u32Prescaler) << (((u32ChannelNum) >> 1) * 8)))
145
159#define PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider) \
160 ((pwm)->CLKDIV = ((pwm)->CLKDIV & ~(PWM_CLKDIV_CLKDIV0_Msk << ((u32ChannelNum) * 4))) | ((u32Divider) << ((u32ChannelNum) * 4)))
161
171#define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR) (*((__IO uint32_t *)((((uint32_t) & ((pwm)->CMPDAT0)) + u32ChannelNum * 4)))= (u32CMR))
172
183#define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR) (*((__IO uint32_t *) ((((uint32_t)&((pwm)->PERIOD0)) + (u32ChannelNum) * 4))) = (u32CNR))
184
194#define PWM_SET_CMRD(pwm, u32ChannelNum, u32CMRD) (*((__IO uint32_t *)((((uint32_t) & ((pwm)->CMPDAT0)) + (u32ChannelNum) * 4)))= (u32CMRD << 16))
195
206#define PWM_SET_ALIGNED_TYPE(pwm, u32ChannelMask, u32AlignedType) \
207 ((pwm)->CTL = ((pwm)->CTL & ~PWM_CTL_CNTTYPE_Msk) | (u32AlignedType))
208
215#define PWM_ENABLE_ASYMMETRIC_MODE(pwm) ((pwm)->CTL |= PWM_CTL_ASYMEN_Msk)
216
223#define PWM_ENABLE_PCAEN(pwm) (PWM->PCACTL |= PWM_PCACTL_PCAEN_Msk)
224
225uint32_t PWM_ConfigOutputChannel(PWM_T *pwm,
226 uint32_t u32ChannelNum,
227 uint32_t u32Frequency,
228 uint32_t u32DutyCycle);
229 void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask);
230 void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask);
231 void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask);
232 void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
233 void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum);
234 void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
235uint32_t PWM_GetADCTriggerFlag (PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition);
236 void PWM_EnableFaultBrake(PWM_T *pwm,
237 uint32_t u32ChannelMask,
238 uint32_t u32LevelMask,
239 uint32_t u32BrakeSource);
240 void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource);
241 void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
242 void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask);
243 void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration);
244 void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum);
245
246 void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType);
247 void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum);
248 void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
249uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
250
251 void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource);
252 void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource);
253 void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource);
254uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource);
255
256 void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
257 void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum);
258 void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
259uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
260
261 void PWM_EnableCenterInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
262 void PWM_DisableCenterInt(PWM_T *pwm, uint32_t u32ChannelNum);
263 void PWM_ClearCenterIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
264uint32_t PWM_GetCenterIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
265
266 void PWM_EnableRiseInt(PWM_T *pwm, uint32_t u32ChannelNum);
267 void PWM_DisableRiseInt(PWM_T *pwm, uint32_t u32ChannelNum);
268 void PWM_ClearRiseIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
269uint32_t PWM_GetRiseIntFlag(PWM_T *pwm, uint32_t u32ChannelNum);
270 /* end of group Mini58_PWM_EXPORTED_FUNCTIONS */
272 /* end of group Mini58_PWM_Driver */
274 /* end of group Mini58_Device_Driver */
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif //__PWM_H__
282
283/*** (C) COPYRIGHT 2022 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:153
PWM_Stop
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
Definition: pwm.c:133
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:324
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:227
PWM_DisableADCTrigger
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
Definition: pwm.c:202
PWM_DisableRiseInt
void PWM_DisableRiseInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Rise interrupt of selected channel.
Definition: pwm.c:458
PWM_ClearRiseIntFlag
void PWM_ClearRiseIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears Rise interrupt flag of selected channel.
Definition: pwm.c:469
PWM_DisablePeriodInt
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Period interrupt of selected channel.
Definition: pwm.c:412
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:355
PWM_GetFaultBrakeIntFlag
uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function get fault brake interrupt of selected source.
Definition: pwm.c:532
PWM_DisableFaultBrakeInt
void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function disable fault brake interrupt.
Definition: pwm.c:504
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_EnablePeriodInt
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function enable Period interrupt of selected channel.
Definition: pwm.c:401
PWM_DisableCenterInt
void PWM_DisableCenterInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Central interrupt of selected channel.
Definition: pwm.c:558
PWM_EnableRiseInt
void PWM_EnableRiseInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function enable Rise interrupt of selected channel.
Definition: pwm.c:447
PWM_DisableDutyInt
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable duty interrupt of selected channel.
Definition: pwm.c:366
PWM_GetADCTriggerFlag
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function get selected channel trigger ADC flag.
Definition: pwm.c:246
PWM_ClearDutyIntFlag
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
Definition: pwm.c:377
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:272
PWM_GetDutyIntFlag
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag of selected channel.
Definition: pwm.c:390
PWM_DisableDeadZone
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
Definition: pwm.c:340
PWM_DisableOutput
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
Definition: pwm.c:311
PWM_EnableCenterInt
void PWM_EnableCenterInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable Central interrupt of selected channel.
Definition: pwm.c:547
PWM_ClearCenterIntFlag
void PWM_ClearCenterIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear Central interrupt of selected channel.
Definition: pwm.c:569
PWM_GetRiseIntFlag
uint32_t PWM_GetRiseIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get Rise interrupt flag of selected channel.
Definition: pwm.c:482
PWM_ClearFaultBrakeIntFlag
void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake interrupt of selected source.
Definition: pwm.c:517
PWM_Start
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
Definition: pwm.c:112
PWM_ClearPeriodIntFlag
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears Period interrupt flag of selected channel.
Definition: pwm.c:423
PWM_EnableOutput
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
Definition: pwm.c:299
PWM_EnableFaultBrakeInt
void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource)
This function enable fault brake interrupt.
Definition: pwm.c:493
PWM_GetPeriodIntFlag
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get Period interrupt flag of selected channel.
Definition: pwm.c:436
PWM_ClearFaultBrakeFlag
void PWM_ClearFaultBrakeFlag(PWM_T *pwm, uint32_t u32BrakeSource)
This function clear fault brake flag.
Definition: pwm.c:287
PWM_GetCenterIntFlag
uint32_t PWM_GetCenterIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get Central interrupt of selected channel.
Definition: pwm.c:582
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:178
PWM_T
Definition: Mini58Series.h:5379