Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_pwm.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file pwm.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V3.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 21 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 15/08/11 10:26a $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief M451 series PWM driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #include "M451Series.h" |
sahilmgandhi | 18:6a4db94011d3 | 12 | |
sahilmgandhi | 18:6a4db94011d3 | 13 | /** @addtogroup Standard_Driver Standard Driver |
sahilmgandhi | 18:6a4db94011d3 | 14 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 15 | */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | |
sahilmgandhi | 18:6a4db94011d3 | 17 | /** @addtogroup PWM_Driver PWM Driver |
sahilmgandhi | 18:6a4db94011d3 | 18 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 19 | */ |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | /** @addtogroup PWM_EXPORTED_FUNCTIONS PWM Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 23 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 24 | */ |
sahilmgandhi | 18:6a4db94011d3 | 25 | |
sahilmgandhi | 18:6a4db94011d3 | 26 | /** |
sahilmgandhi | 18:6a4db94011d3 | 27 | * @brief Configure PWM capture and get the nearest unit time. |
sahilmgandhi | 18:6a4db94011d3 | 28 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 29 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 30 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 31 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 32 | * @param[in] u32UnitTimeNsec The unit time of counter |
sahilmgandhi | 18:6a4db94011d3 | 33 | * @param[in] u32CaptureEdge The condition to latch the counter. This parameter is not used |
sahilmgandhi | 18:6a4db94011d3 | 34 | * @return The nearest unit time in nano second. |
sahilmgandhi | 18:6a4db94011d3 | 35 | * @details This function is used to Configure PWM capture and get the nearest unit time. |
sahilmgandhi | 18:6a4db94011d3 | 36 | */ |
sahilmgandhi | 18:6a4db94011d3 | 37 | uint32_t PWM_ConfigCaptureChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge) |
sahilmgandhi | 18:6a4db94011d3 | 38 | { |
sahilmgandhi | 18:6a4db94011d3 | 39 | uint32_t u32Src; |
sahilmgandhi | 18:6a4db94011d3 | 40 | uint32_t u32PWMClockSrc; |
sahilmgandhi | 18:6a4db94011d3 | 41 | uint32_t u32NearestUnitTimeNsec; |
sahilmgandhi | 18:6a4db94011d3 | 42 | uint16_t u16Prescale = 1, u16CNR = 0xFFFF; |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | if(pwm == PWM0) |
sahilmgandhi | 18:6a4db94011d3 | 45 | u32Src = CLK->CLKSEL2 & CLK_CLKSEL2_PWM0SEL_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 46 | else//(pwm == PWM1) |
sahilmgandhi | 18:6a4db94011d3 | 47 | u32Src = CLK->CLKSEL2 & CLK_CLKSEL2_PWM1SEL_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 48 | |
sahilmgandhi | 18:6a4db94011d3 | 49 | if(u32Src == 0) |
sahilmgandhi | 18:6a4db94011d3 | 50 | { |
sahilmgandhi | 18:6a4db94011d3 | 51 | //clock source is from PLL clock |
sahilmgandhi | 18:6a4db94011d3 | 52 | u32PWMClockSrc = CLK_GetPLLClockFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 53 | } |
sahilmgandhi | 18:6a4db94011d3 | 54 | else |
sahilmgandhi | 18:6a4db94011d3 | 55 | { |
sahilmgandhi | 18:6a4db94011d3 | 56 | //clock source is from PCLK |
sahilmgandhi | 18:6a4db94011d3 | 57 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 58 | if(pwm == PWM0) |
sahilmgandhi | 18:6a4db94011d3 | 59 | u32PWMClockSrc = CLK_GetPCLK0Freq(); |
sahilmgandhi | 18:6a4db94011d3 | 60 | else//(pwm == PWM1) |
sahilmgandhi | 18:6a4db94011d3 | 61 | u32PWMClockSrc = CLK_GetPCLK1Freq(); |
sahilmgandhi | 18:6a4db94011d3 | 62 | |
sahilmgandhi | 18:6a4db94011d3 | 63 | } |
sahilmgandhi | 18:6a4db94011d3 | 64 | |
sahilmgandhi | 18:6a4db94011d3 | 65 | u32PWMClockSrc /= 1000; |
sahilmgandhi | 18:6a4db94011d3 | 66 | for(u16Prescale = 1; u16Prescale <= 0x1000; u16Prescale++) |
sahilmgandhi | 18:6a4db94011d3 | 67 | { |
sahilmgandhi | 18:6a4db94011d3 | 68 | u32NearestUnitTimeNsec = (1000000 * u16Prescale) / u32PWMClockSrc; |
sahilmgandhi | 18:6a4db94011d3 | 69 | if(u32NearestUnitTimeNsec < u32UnitTimeNsec) |
sahilmgandhi | 18:6a4db94011d3 | 70 | { |
sahilmgandhi | 18:6a4db94011d3 | 71 | if(u16Prescale == 0x1000) //limit to the maximum unit time(nano second) |
sahilmgandhi | 18:6a4db94011d3 | 72 | break; |
sahilmgandhi | 18:6a4db94011d3 | 73 | if(!((1000000 * (u16Prescale + 1) > (u32NearestUnitTimeNsec * u32PWMClockSrc)))) |
sahilmgandhi | 18:6a4db94011d3 | 74 | break; |
sahilmgandhi | 18:6a4db94011d3 | 75 | continue; |
sahilmgandhi | 18:6a4db94011d3 | 76 | } |
sahilmgandhi | 18:6a4db94011d3 | 77 | break; |
sahilmgandhi | 18:6a4db94011d3 | 78 | } |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | // convert to real register value |
sahilmgandhi | 18:6a4db94011d3 | 81 | // every two channels share a prescaler |
sahilmgandhi | 18:6a4db94011d3 | 82 | PWM_SET_PRESCALER(pwm, u32ChannelNum, --u16Prescale); |
sahilmgandhi | 18:6a4db94011d3 | 83 | |
sahilmgandhi | 18:6a4db94011d3 | 84 | // set PWM to down count type(edge aligned) |
sahilmgandhi | 18:6a4db94011d3 | 85 | (pwm)->CTL1 = ((pwm)->CTL1 & ~(PWM_CTL1_CNTTYPE0_Msk << (2 * u32ChannelNum))) | (1UL << (2 * u32ChannelNum)); |
sahilmgandhi | 18:6a4db94011d3 | 86 | // set PWM to auto-reload mode |
sahilmgandhi | 18:6a4db94011d3 | 87 | (pwm)->CTL1 &= ~(PWM_CTL1_CNTMODE0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 88 | PWM_SET_CNR(pwm, u32ChannelNum, u16CNR); |
sahilmgandhi | 18:6a4db94011d3 | 89 | |
sahilmgandhi | 18:6a4db94011d3 | 90 | return (u32NearestUnitTimeNsec); |
sahilmgandhi | 18:6a4db94011d3 | 91 | } |
sahilmgandhi | 18:6a4db94011d3 | 92 | |
sahilmgandhi | 18:6a4db94011d3 | 93 | /** |
sahilmgandhi | 18:6a4db94011d3 | 94 | * @brief This function Configure PWM generator and get the nearest frequency in edge aligned auto-reload mode |
sahilmgandhi | 18:6a4db94011d3 | 95 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 96 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 97 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 98 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @param[in] u32Frequency Target generator frequency |
sahilmgandhi | 18:6a4db94011d3 | 100 | * @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%... |
sahilmgandhi | 18:6a4db94011d3 | 101 | * @return Nearest frequency clock in nano second |
sahilmgandhi | 18:6a4db94011d3 | 102 | * @note Since every two channels, (0 & 1), (2 & 3), shares a prescaler. Call this API to configure PWM frequency may affect |
sahilmgandhi | 18:6a4db94011d3 | 103 | * existing frequency of other channel. |
sahilmgandhi | 18:6a4db94011d3 | 104 | */ |
sahilmgandhi | 18:6a4db94011d3 | 105 | uint32_t PWM_ConfigOutputChannel (PWM_T *pwm, |
sahilmgandhi | 18:6a4db94011d3 | 106 | uint32_t u32ChannelNum, |
sahilmgandhi | 18:6a4db94011d3 | 107 | uint32_t u32Frequency, |
sahilmgandhi | 18:6a4db94011d3 | 108 | uint32_t u32DutyCycle) |
sahilmgandhi | 18:6a4db94011d3 | 109 | { |
sahilmgandhi | 18:6a4db94011d3 | 110 | return PWM_ConfigOutputChannel2(pwm, u32ChannelNum, u32Frequency, u32DutyCycle, 1); |
sahilmgandhi | 18:6a4db94011d3 | 111 | } |
sahilmgandhi | 18:6a4db94011d3 | 112 | |
sahilmgandhi | 18:6a4db94011d3 | 113 | /** |
sahilmgandhi | 18:6a4db94011d3 | 114 | * @brief This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode |
sahilmgandhi | 18:6a4db94011d3 | 115 | * @param[in] pwm The base address of PWM module |
sahilmgandhi | 18:6a4db94011d3 | 116 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 117 | * @param[in] u32Frequency Target generator frequency = u32Frequency / u32Frequency2 |
sahilmgandhi | 18:6a4db94011d3 | 118 | * @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%... |
sahilmgandhi | 18:6a4db94011d3 | 119 | * @param[in] u32Frequency2 Target generator frequency = u32Frequency / u32Frequency2 |
sahilmgandhi | 18:6a4db94011d3 | 120 | * @return Nearest frequency clock in nano second |
sahilmgandhi | 18:6a4db94011d3 | 121 | * @note Since every two channels, (0 & 1), (2 & 3), (4 & 5), shares a prescaler. Call this API to configure PWM frequency may affect |
sahilmgandhi | 18:6a4db94011d3 | 122 | * existing frequency of other channel. |
sahilmgandhi | 18:6a4db94011d3 | 123 | */ |
sahilmgandhi | 18:6a4db94011d3 | 124 | uint32_t PWM_ConfigOutputChannel2(PWM_T *pwm, |
sahilmgandhi | 18:6a4db94011d3 | 125 | uint32_t u32ChannelNum, |
sahilmgandhi | 18:6a4db94011d3 | 126 | uint32_t u32Frequency, |
sahilmgandhi | 18:6a4db94011d3 | 127 | uint32_t u32DutyCycle, |
sahilmgandhi | 18:6a4db94011d3 | 128 | uint32_t u32Frequency2) |
sahilmgandhi | 18:6a4db94011d3 | 129 | { |
sahilmgandhi | 18:6a4db94011d3 | 130 | uint32_t u32Src; |
sahilmgandhi | 18:6a4db94011d3 | 131 | uint32_t u32PWMClockSrc; |
sahilmgandhi | 18:6a4db94011d3 | 132 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 133 | uint16_t u16Prescale = 1, u16CNR = 0xFFFF; |
sahilmgandhi | 18:6a4db94011d3 | 134 | |
sahilmgandhi | 18:6a4db94011d3 | 135 | if(pwm == PWM0) |
sahilmgandhi | 18:6a4db94011d3 | 136 | u32Src = CLK->CLKSEL2 & CLK_CLKSEL2_PWM0SEL_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 137 | else//(pwm == PWM1) |
sahilmgandhi | 18:6a4db94011d3 | 138 | u32Src = CLK->CLKSEL2 & CLK_CLKSEL2_PWM1SEL_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 139 | |
sahilmgandhi | 18:6a4db94011d3 | 140 | if(u32Src == 0) |
sahilmgandhi | 18:6a4db94011d3 | 141 | { |
sahilmgandhi | 18:6a4db94011d3 | 142 | //clock source is from PLL clock |
sahilmgandhi | 18:6a4db94011d3 | 143 | u32PWMClockSrc = CLK_GetPLLClockFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 144 | } |
sahilmgandhi | 18:6a4db94011d3 | 145 | else |
sahilmgandhi | 18:6a4db94011d3 | 146 | { |
sahilmgandhi | 18:6a4db94011d3 | 147 | //clock source is from PCLK |
sahilmgandhi | 18:6a4db94011d3 | 148 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 149 | if(pwm == PWM0) |
sahilmgandhi | 18:6a4db94011d3 | 150 | u32PWMClockSrc = CLK_GetPCLK0Freq(); |
sahilmgandhi | 18:6a4db94011d3 | 151 | else//(pwm == PWM1) |
sahilmgandhi | 18:6a4db94011d3 | 152 | u32PWMClockSrc = CLK_GetPCLK1Freq(); |
sahilmgandhi | 18:6a4db94011d3 | 153 | |
sahilmgandhi | 18:6a4db94011d3 | 154 | } |
sahilmgandhi | 18:6a4db94011d3 | 155 | |
sahilmgandhi | 18:6a4db94011d3 | 156 | for(u16Prescale = 1; u16Prescale < 0xFFF; u16Prescale++)//prescale could be 0~0xFFF |
sahilmgandhi | 18:6a4db94011d3 | 157 | { |
sahilmgandhi | 18:6a4db94011d3 | 158 | // Note: Support frequency < 1 |
sahilmgandhi | 18:6a4db94011d3 | 159 | i = (uint64_t) u32PWMClockSrc * u32Frequency2 / u32Frequency / u16Prescale; |
sahilmgandhi | 18:6a4db94011d3 | 160 | // If target value is larger than CNR, need to use a larger prescaler |
sahilmgandhi | 18:6a4db94011d3 | 161 | if(i > (0x10000)) |
sahilmgandhi | 18:6a4db94011d3 | 162 | continue; |
sahilmgandhi | 18:6a4db94011d3 | 163 | |
sahilmgandhi | 18:6a4db94011d3 | 164 | u16CNR = i; |
sahilmgandhi | 18:6a4db94011d3 | 165 | break; |
sahilmgandhi | 18:6a4db94011d3 | 166 | } |
sahilmgandhi | 18:6a4db94011d3 | 167 | // Store return value here 'cos we're gonna change u16Prescale & u16CNR to the real value to fill into register |
sahilmgandhi | 18:6a4db94011d3 | 168 | i = u32PWMClockSrc / (u16Prescale * u16CNR); |
sahilmgandhi | 18:6a4db94011d3 | 169 | |
sahilmgandhi | 18:6a4db94011d3 | 170 | // convert to real register value |
sahilmgandhi | 18:6a4db94011d3 | 171 | // every two channels share a prescaler |
sahilmgandhi | 18:6a4db94011d3 | 172 | PWM_SET_PRESCALER(pwm, u32ChannelNum, --u16Prescale); |
sahilmgandhi | 18:6a4db94011d3 | 173 | // set PWM to down count type(edge aligned) |
sahilmgandhi | 18:6a4db94011d3 | 174 | (pwm)->CTL1 = ((pwm)->CTL1 & ~(PWM_CTL1_CNTTYPE0_Msk << (2 * u32ChannelNum))) | (1UL << (2 * u32ChannelNum)); |
sahilmgandhi | 18:6a4db94011d3 | 175 | // set PWM to auto-reload mode |
sahilmgandhi | 18:6a4db94011d3 | 176 | (pwm)->CTL1 &= ~(PWM_CTL1_CNTMODE0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 177 | |
sahilmgandhi | 18:6a4db94011d3 | 178 | PWM_SET_CNR(pwm, u32ChannelNum, --u16CNR); |
sahilmgandhi | 18:6a4db94011d3 | 179 | if(u32DutyCycle) |
sahilmgandhi | 18:6a4db94011d3 | 180 | { |
sahilmgandhi | 18:6a4db94011d3 | 181 | PWM_SET_CMR(pwm, u32ChannelNum, u32DutyCycle * (u16CNR + 1) / 100 - 1); |
sahilmgandhi | 18:6a4db94011d3 | 182 | (pwm)->WGCTL0 &= ~((PWM_WGCTL0_PRDPCTL0_Msk | PWM_WGCTL0_ZPCTL0_Msk) << (u32ChannelNum * 2)); |
sahilmgandhi | 18:6a4db94011d3 | 183 | (pwm)->WGCTL0 |= (PWM_OUTPUT_LOW << (u32ChannelNum * 2 + PWM_WGCTL0_PRDPCTL0_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 184 | (pwm)->WGCTL1 &= ~((PWM_WGCTL1_CMPDCTL0_Msk | PWM_WGCTL1_CMPUCTL0_Msk) << (u32ChannelNum * 2)); |
sahilmgandhi | 18:6a4db94011d3 | 185 | (pwm)->WGCTL1 |= (PWM_OUTPUT_HIGH << (u32ChannelNum * 2 + PWM_WGCTL1_CMPDCTL0_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 186 | } |
sahilmgandhi | 18:6a4db94011d3 | 187 | else |
sahilmgandhi | 18:6a4db94011d3 | 188 | { |
sahilmgandhi | 18:6a4db94011d3 | 189 | PWM_SET_CMR(pwm, u32ChannelNum, 0); |
sahilmgandhi | 18:6a4db94011d3 | 190 | (pwm)->WGCTL0 &= ~((PWM_WGCTL0_PRDPCTL0_Msk | PWM_WGCTL0_ZPCTL0_Msk) << (u32ChannelNum * 2)); |
sahilmgandhi | 18:6a4db94011d3 | 191 | (pwm)->WGCTL0 |= (PWM_OUTPUT_LOW << (u32ChannelNum * 2 + PWM_WGCTL0_ZPCTL0_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 192 | (pwm)->WGCTL1 &= ~((PWM_WGCTL1_CMPDCTL0_Msk | PWM_WGCTL1_CMPUCTL0_Msk) << (u32ChannelNum * 2)); |
sahilmgandhi | 18:6a4db94011d3 | 193 | (pwm)->WGCTL1 |= (PWM_OUTPUT_HIGH << (u32ChannelNum * 2 + PWM_WGCTL1_CMPDCTL0_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 194 | } |
sahilmgandhi | 18:6a4db94011d3 | 195 | |
sahilmgandhi | 18:6a4db94011d3 | 196 | return(i); |
sahilmgandhi | 18:6a4db94011d3 | 197 | } |
sahilmgandhi | 18:6a4db94011d3 | 198 | |
sahilmgandhi | 18:6a4db94011d3 | 199 | /** |
sahilmgandhi | 18:6a4db94011d3 | 200 | * @brief Start PWM module |
sahilmgandhi | 18:6a4db94011d3 | 201 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 202 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 203 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 204 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 205 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 206 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 207 | * @details This function is used to start PWM module. |
sahilmgandhi | 18:6a4db94011d3 | 208 | */ |
sahilmgandhi | 18:6a4db94011d3 | 209 | void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 210 | { |
sahilmgandhi | 18:6a4db94011d3 | 211 | (pwm)->CNTEN |= u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 212 | } |
sahilmgandhi | 18:6a4db94011d3 | 213 | |
sahilmgandhi | 18:6a4db94011d3 | 214 | /** |
sahilmgandhi | 18:6a4db94011d3 | 215 | * @brief Stop PWM module |
sahilmgandhi | 18:6a4db94011d3 | 216 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 217 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 218 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 219 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 220 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 221 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 222 | * @details This function is used to stop PWM module. |
sahilmgandhi | 18:6a4db94011d3 | 223 | */ |
sahilmgandhi | 18:6a4db94011d3 | 224 | void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 225 | { |
sahilmgandhi | 18:6a4db94011d3 | 226 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 227 | for(i = 0; i < PWM_CHANNEL_NUM; i ++) |
sahilmgandhi | 18:6a4db94011d3 | 228 | { |
sahilmgandhi | 18:6a4db94011d3 | 229 | if(u32ChannelMask & (1 << i)) |
sahilmgandhi | 18:6a4db94011d3 | 230 | { |
sahilmgandhi | 18:6a4db94011d3 | 231 | (pwm)->PERIOD[i] = 0; |
sahilmgandhi | 18:6a4db94011d3 | 232 | } |
sahilmgandhi | 18:6a4db94011d3 | 233 | } |
sahilmgandhi | 18:6a4db94011d3 | 234 | } |
sahilmgandhi | 18:6a4db94011d3 | 235 | |
sahilmgandhi | 18:6a4db94011d3 | 236 | /** |
sahilmgandhi | 18:6a4db94011d3 | 237 | * @brief Stop PWM generation immediately by clear channel enable bit |
sahilmgandhi | 18:6a4db94011d3 | 238 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 239 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 240 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 241 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 242 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 243 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 244 | * @details This function is used to stop PWM generation immediately by clear channel enable bit. |
sahilmgandhi | 18:6a4db94011d3 | 245 | */ |
sahilmgandhi | 18:6a4db94011d3 | 246 | void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 247 | { |
sahilmgandhi | 18:6a4db94011d3 | 248 | (pwm)->CNTEN &= ~u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 249 | } |
sahilmgandhi | 18:6a4db94011d3 | 250 | |
sahilmgandhi | 18:6a4db94011d3 | 251 | /** |
sahilmgandhi | 18:6a4db94011d3 | 252 | * @brief Enable selected channel to trigger EADC |
sahilmgandhi | 18:6a4db94011d3 | 253 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 254 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 255 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 256 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 257 | * @param[in] u32Condition The condition to trigger EADC. Combination of following conditions: |
sahilmgandhi | 18:6a4db94011d3 | 258 | * - \ref PWM_TRIGGER_ADC_EVEN_ZERO_POINT |
sahilmgandhi | 18:6a4db94011d3 | 259 | * - \ref PWM_TRIGGER_ADC_EVEN_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 260 | * - \ref PWM_TRIGGER_ADC_EVEN_ZERO_OR_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 261 | * - \ref PWM_TRIGGER_ADC_EVEN_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 262 | * - \ref PWM_TRIGGER_ADC_EVEN_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 263 | * - \ref PWM_TRIGGER_ADC_ODD_ZERO_POINT |
sahilmgandhi | 18:6a4db94011d3 | 264 | * - \ref PWM_TRIGGER_ADC_ODD_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 265 | * - \ref PWM_TRIGGER_ADC_ODD_ZERO_OR_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 266 | * - \ref PWM_TRIGGER_ADC_ODD_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 267 | * - \ref PWM_TRIGGER_ADC_ODD_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 268 | * - \ref PWM_TRIGGER_ADC_CH_0_FREE_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 269 | * - \ref PWM_TRIGGER_ADC_CH_0_FREE_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 270 | * - \ref PWM_TRIGGER_ADC_CH_2_FREE_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 271 | * - \ref PWM_TRIGGER_ADC_CH_2_FREE_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 272 | * - \ref PWM_TRIGGER_ADC_CH_4_FREE_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 273 | * - \ref PWM_TRIGGER_ADC_CH_4_FREE_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 274 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 275 | * @details This function is used to enable selected channel to trigger EADC. |
sahilmgandhi | 18:6a4db94011d3 | 276 | */ |
sahilmgandhi | 18:6a4db94011d3 | 277 | void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition) |
sahilmgandhi | 18:6a4db94011d3 | 278 | { |
sahilmgandhi | 18:6a4db94011d3 | 279 | if(u32ChannelNum < 4) |
sahilmgandhi | 18:6a4db94011d3 | 280 | { |
sahilmgandhi | 18:6a4db94011d3 | 281 | (pwm)->EADCTS0 &= ~((PWM_EADCTS0_TRGSEL0_Msk) << (u32ChannelNum * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 282 | (pwm)->EADCTS0 |= ((PWM_EADCTS0_TRGEN0_Msk | u32Condition) << (u32ChannelNum * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 283 | } |
sahilmgandhi | 18:6a4db94011d3 | 284 | else |
sahilmgandhi | 18:6a4db94011d3 | 285 | { |
sahilmgandhi | 18:6a4db94011d3 | 286 | (pwm)->EADCTS1 &= ~((PWM_EADCTS1_TRGSEL4_Msk) << ((u32ChannelNum - 4) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 287 | (pwm)->EADCTS1 |= ((PWM_EADCTS1_TRGEN4_Msk | u32Condition) << ((u32ChannelNum - 4) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 288 | } |
sahilmgandhi | 18:6a4db94011d3 | 289 | } |
sahilmgandhi | 18:6a4db94011d3 | 290 | |
sahilmgandhi | 18:6a4db94011d3 | 291 | /** |
sahilmgandhi | 18:6a4db94011d3 | 292 | * @brief Disable selected channel to trigger EADC |
sahilmgandhi | 18:6a4db94011d3 | 293 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 294 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 295 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 296 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 297 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 298 | * @details This function is used to disable selected channel to trigger EADC. |
sahilmgandhi | 18:6a4db94011d3 | 299 | */ |
sahilmgandhi | 18:6a4db94011d3 | 300 | void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 301 | { |
sahilmgandhi | 18:6a4db94011d3 | 302 | if(u32ChannelNum < 4) |
sahilmgandhi | 18:6a4db94011d3 | 303 | { |
sahilmgandhi | 18:6a4db94011d3 | 304 | (pwm)->EADCTS0 &= ~(PWM_EADCTS0_TRGEN0_Msk << (u32ChannelNum * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 305 | } |
sahilmgandhi | 18:6a4db94011d3 | 306 | else |
sahilmgandhi | 18:6a4db94011d3 | 307 | { |
sahilmgandhi | 18:6a4db94011d3 | 308 | (pwm)->EADCTS1 &= ~(PWM_EADCTS1_TRGEN4_Msk << ((u32ChannelNum - 4) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 309 | } |
sahilmgandhi | 18:6a4db94011d3 | 310 | } |
sahilmgandhi | 18:6a4db94011d3 | 311 | |
sahilmgandhi | 18:6a4db94011d3 | 312 | /** |
sahilmgandhi | 18:6a4db94011d3 | 313 | * @brief Clear selected channel trigger EADC flag |
sahilmgandhi | 18:6a4db94011d3 | 314 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 315 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 316 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 317 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 318 | * @param[in] u32Condition This parameter is not used |
sahilmgandhi | 18:6a4db94011d3 | 319 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 320 | * @details This function is used to clear selected channel trigger EADC flag. |
sahilmgandhi | 18:6a4db94011d3 | 321 | */ |
sahilmgandhi | 18:6a4db94011d3 | 322 | void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition) |
sahilmgandhi | 18:6a4db94011d3 | 323 | { |
sahilmgandhi | 18:6a4db94011d3 | 324 | (pwm)->STATUS = (PWM_STATUS_ADCTRGF0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 325 | } |
sahilmgandhi | 18:6a4db94011d3 | 326 | |
sahilmgandhi | 18:6a4db94011d3 | 327 | /** |
sahilmgandhi | 18:6a4db94011d3 | 328 | * @brief Get selected channel trigger EADC flag |
sahilmgandhi | 18:6a4db94011d3 | 329 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 330 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 331 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 332 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 333 | * @retval 0 The specified channel trigger EADC to start of conversion flag is not set |
sahilmgandhi | 18:6a4db94011d3 | 334 | * @retval 1 The specified channel trigger EADC to start of conversion flag is set |
sahilmgandhi | 18:6a4db94011d3 | 335 | * @details This function is used to get PWM trigger EADC to start of conversion flag for specified channel. |
sahilmgandhi | 18:6a4db94011d3 | 336 | */ |
sahilmgandhi | 18:6a4db94011d3 | 337 | uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 338 | { |
sahilmgandhi | 18:6a4db94011d3 | 339 | return (((pwm)->STATUS & (PWM_STATUS_ADCTRGF0_Msk << u32ChannelNum)) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 340 | } |
sahilmgandhi | 18:6a4db94011d3 | 341 | |
sahilmgandhi | 18:6a4db94011d3 | 342 | /** |
sahilmgandhi | 18:6a4db94011d3 | 343 | * @brief Enable selected channel to trigger DAC |
sahilmgandhi | 18:6a4db94011d3 | 344 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 345 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 346 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 347 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 348 | * @param[in] u32Condition The condition to trigger DAC. Combination of following conditions: |
sahilmgandhi | 18:6a4db94011d3 | 349 | * - \ref PWM_TRIGGER_DAC_ZERO_POINT |
sahilmgandhi | 18:6a4db94011d3 | 350 | * - \ref PWM_TRIGGER_DAC_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 351 | * - \ref PWM_TRIGGER_DAC_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 352 | * - \ref PWM_TRIGGER_DAC_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 353 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 354 | * @details This function is used to enable selected channel to trigger DAC. |
sahilmgandhi | 18:6a4db94011d3 | 355 | */ |
sahilmgandhi | 18:6a4db94011d3 | 356 | void PWM_EnableDACTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition) |
sahilmgandhi | 18:6a4db94011d3 | 357 | { |
sahilmgandhi | 18:6a4db94011d3 | 358 | (pwm)->DACTRGEN |= (u32Condition << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 359 | } |
sahilmgandhi | 18:6a4db94011d3 | 360 | |
sahilmgandhi | 18:6a4db94011d3 | 361 | /** |
sahilmgandhi | 18:6a4db94011d3 | 362 | * @brief Disable selected channel to trigger DAC |
sahilmgandhi | 18:6a4db94011d3 | 363 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 364 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 365 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 366 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 367 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 368 | * @details This function is used to disable selected channel to trigger DAC. |
sahilmgandhi | 18:6a4db94011d3 | 369 | */ |
sahilmgandhi | 18:6a4db94011d3 | 370 | void PWM_DisableDACTrigger(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 371 | { |
sahilmgandhi | 18:6a4db94011d3 | 372 | (pwm)->DACTRGEN &= ~((PWM_TRIGGER_DAC_ZERO_POINT | PWM_TRIGGER_DAC_PERIOD_POINT | PWM_TRIGGER_DAC_COMPARE_UP_COUNT_POINT | \ |
sahilmgandhi | 18:6a4db94011d3 | 373 | PWM_TRIGGER_DAC_COMPARE_DOWN_COUNT_POINT) << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 374 | } |
sahilmgandhi | 18:6a4db94011d3 | 375 | |
sahilmgandhi | 18:6a4db94011d3 | 376 | /** |
sahilmgandhi | 18:6a4db94011d3 | 377 | * @brief Clear selected channel trigger DAC flag |
sahilmgandhi | 18:6a4db94011d3 | 378 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 379 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 380 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 381 | * @param[in] u32ChannelNum PWM channel number. This parameter is not used |
sahilmgandhi | 18:6a4db94011d3 | 382 | * @param[in] u32Condition The condition to trigger DAC. This parameter is not used |
sahilmgandhi | 18:6a4db94011d3 | 383 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 384 | * @details This function is used to clear selected channel trigger DAC flag. |
sahilmgandhi | 18:6a4db94011d3 | 385 | */ |
sahilmgandhi | 18:6a4db94011d3 | 386 | void PWM_ClearDACTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition) |
sahilmgandhi | 18:6a4db94011d3 | 387 | { |
sahilmgandhi | 18:6a4db94011d3 | 388 | (pwm)->STATUS = PWM_STATUS_DACTRGF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 389 | } |
sahilmgandhi | 18:6a4db94011d3 | 390 | |
sahilmgandhi | 18:6a4db94011d3 | 391 | /** |
sahilmgandhi | 18:6a4db94011d3 | 392 | * @brief Get selected channel trigger DAC flag |
sahilmgandhi | 18:6a4db94011d3 | 393 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 394 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 395 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 396 | * @param[in] u32ChannelNum PWM channel number. This parameter is not used |
sahilmgandhi | 18:6a4db94011d3 | 397 | * @retval 0 The specified channel trigger DAC to start of conversion flag is not set |
sahilmgandhi | 18:6a4db94011d3 | 398 | * @retval 1 The specified channel trigger DAC to start of conversion flag is set |
sahilmgandhi | 18:6a4db94011d3 | 399 | * @details This function is used to get selected channel trigger DAC flag. |
sahilmgandhi | 18:6a4db94011d3 | 400 | */ |
sahilmgandhi | 18:6a4db94011d3 | 401 | uint32_t PWM_GetDACTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 402 | { |
sahilmgandhi | 18:6a4db94011d3 | 403 | return (((pwm)->STATUS & PWM_STATUS_DACTRGF_Msk) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 404 | } |
sahilmgandhi | 18:6a4db94011d3 | 405 | |
sahilmgandhi | 18:6a4db94011d3 | 406 | /** |
sahilmgandhi | 18:6a4db94011d3 | 407 | * @brief This function enable fault brake of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 408 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 409 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 410 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 411 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 412 | * @param[in] u32LevelMask Output high or low while fault brake occurs, each bit represent the level of a channel |
sahilmgandhi | 18:6a4db94011d3 | 413 | * while fault brake occurs. Bit 0 represents channel 0, bit 1 represents channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 414 | * @param[in] u32BrakeSource Fault brake source, could be one of following source |
sahilmgandhi | 18:6a4db94011d3 | 415 | * - \ref PWM_FB_EDGE_ACMP0 |
sahilmgandhi | 18:6a4db94011d3 | 416 | * - \ref PWM_FB_EDGE_ACMP1 |
sahilmgandhi | 18:6a4db94011d3 | 417 | * - \ref PWM_FB_EDGE_BKP0 |
sahilmgandhi | 18:6a4db94011d3 | 418 | * - \ref PWM_FB_EDGE_BKP1 |
sahilmgandhi | 18:6a4db94011d3 | 419 | * - \ref PWM_FB_EDGE_SYS_CSS |
sahilmgandhi | 18:6a4db94011d3 | 420 | * - \ref PWM_FB_EDGE_SYS_BOD |
sahilmgandhi | 18:6a4db94011d3 | 421 | * - \ref PWM_FB_EDGE_SYS_RAM |
sahilmgandhi | 18:6a4db94011d3 | 422 | * - \ref PWM_FB_EDGE_SYS_COR |
sahilmgandhi | 18:6a4db94011d3 | 423 | * - \ref PWM_FB_LEVEL_ACMP0 |
sahilmgandhi | 18:6a4db94011d3 | 424 | * - \ref PWM_FB_LEVEL_ACMP1 |
sahilmgandhi | 18:6a4db94011d3 | 425 | * - \ref PWM_FB_LEVEL_BKP0 |
sahilmgandhi | 18:6a4db94011d3 | 426 | * - \ref PWM_FB_LEVEL_BKP1 |
sahilmgandhi | 18:6a4db94011d3 | 427 | * - \ref PWM_FB_LEVEL_SYS_CSS |
sahilmgandhi | 18:6a4db94011d3 | 428 | * - \ref PWM_FB_LEVEL_SYS_BOD |
sahilmgandhi | 18:6a4db94011d3 | 429 | * - \ref PWM_FB_LEVEL_SYS_RAM |
sahilmgandhi | 18:6a4db94011d3 | 430 | * - \ref PWM_FB_LEVEL_SYS_COR |
sahilmgandhi | 18:6a4db94011d3 | 431 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 432 | * @details This function is used to enable fault brake of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 433 | * The write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 434 | */ |
sahilmgandhi | 18:6a4db94011d3 | 435 | void PWM_EnableFaultBrake(PWM_T *pwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource) |
sahilmgandhi | 18:6a4db94011d3 | 436 | { |
sahilmgandhi | 18:6a4db94011d3 | 437 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 438 | for(i = 0; i < PWM_CHANNEL_NUM; i ++) |
sahilmgandhi | 18:6a4db94011d3 | 439 | { |
sahilmgandhi | 18:6a4db94011d3 | 440 | if(u32ChannelMask & (1 << i)) |
sahilmgandhi | 18:6a4db94011d3 | 441 | { |
sahilmgandhi | 18:6a4db94011d3 | 442 | if((u32BrakeSource == PWM_FB_EDGE_SYS_CSS) || (u32BrakeSource == PWM_FB_EDGE_SYS_BOD) || \ |
sahilmgandhi | 18:6a4db94011d3 | 443 | (u32BrakeSource == PWM_FB_EDGE_SYS_RAM) || (u32BrakeSource == PWM_FB_EDGE_SYS_COR) || \ |
sahilmgandhi | 18:6a4db94011d3 | 444 | (u32BrakeSource == PWM_FB_LEVEL_SYS_CSS) || (u32BrakeSource == PWM_FB_LEVEL_SYS_BOD) || \ |
sahilmgandhi | 18:6a4db94011d3 | 445 | (u32BrakeSource == PWM_FB_LEVEL_SYS_RAM) || (u32BrakeSource == PWM_FB_LEVEL_SYS_COR)) |
sahilmgandhi | 18:6a4db94011d3 | 446 | { |
sahilmgandhi | 18:6a4db94011d3 | 447 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= (u32BrakeSource & (PWM_BRKCTL0_1_SYSEBEN_Msk | PWM_BRKCTL0_1_SYSLBEN_Msk)); |
sahilmgandhi | 18:6a4db94011d3 | 448 | (pwm)->FAILBRK |= (u32BrakeSource & 0xF); |
sahilmgandhi | 18:6a4db94011d3 | 449 | } |
sahilmgandhi | 18:6a4db94011d3 | 450 | else |
sahilmgandhi | 18:6a4db94011d3 | 451 | { |
sahilmgandhi | 18:6a4db94011d3 | 452 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= u32BrakeSource; |
sahilmgandhi | 18:6a4db94011d3 | 453 | } |
sahilmgandhi | 18:6a4db94011d3 | 454 | } |
sahilmgandhi | 18:6a4db94011d3 | 455 | |
sahilmgandhi | 18:6a4db94011d3 | 456 | if(u32LevelMask & (1 << i)) |
sahilmgandhi | 18:6a4db94011d3 | 457 | { |
sahilmgandhi | 18:6a4db94011d3 | 458 | if(i % 2 == 0) |
sahilmgandhi | 18:6a4db94011d3 | 459 | { |
sahilmgandhi | 18:6a4db94011d3 | 460 | //set brake action as high level for even channel |
sahilmgandhi | 18:6a4db94011d3 | 461 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) &= ~PWM_BRKCTL0_1_BRKAEVEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 462 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= ((3UL) << PWM_BRKCTL0_1_BRKAEVEN_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 463 | } |
sahilmgandhi | 18:6a4db94011d3 | 464 | else |
sahilmgandhi | 18:6a4db94011d3 | 465 | { |
sahilmgandhi | 18:6a4db94011d3 | 466 | //set brake action as high level for odd channel |
sahilmgandhi | 18:6a4db94011d3 | 467 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) &= ~PWM_BRKCTL0_1_BRKAODD_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 468 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= ((3UL) << PWM_BRKCTL0_1_BRKAODD_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 469 | } |
sahilmgandhi | 18:6a4db94011d3 | 470 | } |
sahilmgandhi | 18:6a4db94011d3 | 471 | else |
sahilmgandhi | 18:6a4db94011d3 | 472 | { |
sahilmgandhi | 18:6a4db94011d3 | 473 | if(i % 2 == 0) |
sahilmgandhi | 18:6a4db94011d3 | 474 | { |
sahilmgandhi | 18:6a4db94011d3 | 475 | //set brake action as low level for even channel |
sahilmgandhi | 18:6a4db94011d3 | 476 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) &= ~PWM_BRKCTL0_1_BRKAEVEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 477 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= ((2UL) << PWM_BRKCTL0_1_BRKAEVEN_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 478 | } |
sahilmgandhi | 18:6a4db94011d3 | 479 | else |
sahilmgandhi | 18:6a4db94011d3 | 480 | { |
sahilmgandhi | 18:6a4db94011d3 | 481 | //set brake action as low level for odd channel |
sahilmgandhi | 18:6a4db94011d3 | 482 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) &= ~PWM_BRKCTL0_1_BRKAODD_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 483 | *(__IO uint32_t *)(&((pwm)->BRKCTL0_1) + (i >> 1)) |= ((2UL) << PWM_BRKCTL0_1_BRKAODD_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 484 | } |
sahilmgandhi | 18:6a4db94011d3 | 485 | } |
sahilmgandhi | 18:6a4db94011d3 | 486 | } |
sahilmgandhi | 18:6a4db94011d3 | 487 | |
sahilmgandhi | 18:6a4db94011d3 | 488 | } |
sahilmgandhi | 18:6a4db94011d3 | 489 | |
sahilmgandhi | 18:6a4db94011d3 | 490 | /** |
sahilmgandhi | 18:6a4db94011d3 | 491 | * @brief Enable capture of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 492 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 493 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 494 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 495 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 496 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 497 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 498 | * @details This function is used to enable capture of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 499 | */ |
sahilmgandhi | 18:6a4db94011d3 | 500 | void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 501 | { |
sahilmgandhi | 18:6a4db94011d3 | 502 | (pwm)->CAPINEN |= u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 503 | (pwm)->CAPCTL |= u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 504 | } |
sahilmgandhi | 18:6a4db94011d3 | 505 | |
sahilmgandhi | 18:6a4db94011d3 | 506 | /** |
sahilmgandhi | 18:6a4db94011d3 | 507 | * @brief Disable capture of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 508 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 509 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 510 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 511 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 512 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 513 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 514 | * @details This function is used to disable capture of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 515 | */ |
sahilmgandhi | 18:6a4db94011d3 | 516 | void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 517 | { |
sahilmgandhi | 18:6a4db94011d3 | 518 | (pwm)->CAPINEN &= ~u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 519 | (pwm)->CAPCTL &= ~u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 520 | } |
sahilmgandhi | 18:6a4db94011d3 | 521 | |
sahilmgandhi | 18:6a4db94011d3 | 522 | /** |
sahilmgandhi | 18:6a4db94011d3 | 523 | * @brief Enables PWM output generation of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 524 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 525 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 526 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 527 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 528 | * Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output... |
sahilmgandhi | 18:6a4db94011d3 | 529 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 530 | * @details This function is used to enable PWM output generation of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 531 | */ |
sahilmgandhi | 18:6a4db94011d3 | 532 | void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 533 | { |
sahilmgandhi | 18:6a4db94011d3 | 534 | (pwm)->POEN |= u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 535 | } |
sahilmgandhi | 18:6a4db94011d3 | 536 | |
sahilmgandhi | 18:6a4db94011d3 | 537 | /** |
sahilmgandhi | 18:6a4db94011d3 | 538 | * @brief Disables PWM output generation of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 539 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 540 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 541 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 542 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel |
sahilmgandhi | 18:6a4db94011d3 | 543 | * Set bit 0 to 1 disables channel 0 output, set bit 1 to 1 disables channel 1 output... |
sahilmgandhi | 18:6a4db94011d3 | 544 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 545 | * @details This function is used to disable PWM output generation of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 546 | */ |
sahilmgandhi | 18:6a4db94011d3 | 547 | void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 548 | { |
sahilmgandhi | 18:6a4db94011d3 | 549 | (pwm)->POEN &= ~u32ChannelMask; |
sahilmgandhi | 18:6a4db94011d3 | 550 | } |
sahilmgandhi | 18:6a4db94011d3 | 551 | |
sahilmgandhi | 18:6a4db94011d3 | 552 | /** |
sahilmgandhi | 18:6a4db94011d3 | 553 | * @brief Enables PDMA transfer of selected channel for PWM capture |
sahilmgandhi | 18:6a4db94011d3 | 554 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 555 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 556 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 557 | * @param[in] u32ChannelNum PWM channel number. |
sahilmgandhi | 18:6a4db94011d3 | 558 | * @param[in] u32RisingFirst The capture order is rising, falling first. Every two channels share the same setting. Valid values are TRUE and FALSE. |
sahilmgandhi | 18:6a4db94011d3 | 559 | * @param[in] u32Mode Captured data transferred by PDMA interrupt type. It could be either |
sahilmgandhi | 18:6a4db94011d3 | 560 | * - \ref PWM_CAPTURE_PDMA_RISING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 561 | * - \ref PWM_CAPTURE_PDMA_FALLING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 562 | * - \ref PWM_CAPTURE_PDMA_RISING_FALLING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 563 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 564 | * @details This function is used to enable PDMA transfer of selected channel(s) for PWM capture. |
sahilmgandhi | 18:6a4db94011d3 | 565 | * @note This function can only selects even or odd channel of pairs to do PDMA transfer. |
sahilmgandhi | 18:6a4db94011d3 | 566 | */ |
sahilmgandhi | 18:6a4db94011d3 | 567 | void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode) |
sahilmgandhi | 18:6a4db94011d3 | 568 | { |
sahilmgandhi | 18:6a4db94011d3 | 569 | uint32_t u32IsOddCh; |
sahilmgandhi | 18:6a4db94011d3 | 570 | u32IsOddCh = u32ChannelNum % 2; |
sahilmgandhi | 18:6a4db94011d3 | 571 | (pwm)->PDMACTL = ((pwm)->PDMACTL & ~((PWM_PDMACTL_CHSEL0_1_Msk | PWM_PDMACTL_CAPORD0_1_Msk | PWM_PDMACTL_CAPMOD0_1_Msk) << ((u32ChannelNum >> 1) * 8))) | \ |
sahilmgandhi | 18:6a4db94011d3 | 572 | (((u32IsOddCh << PWM_PDMACTL_CHSEL0_1_Pos) | (u32RisingFirst << PWM_PDMACTL_CAPORD0_1_Pos) | \ |
sahilmgandhi | 18:6a4db94011d3 | 573 | u32Mode | PWM_PDMACTL_CHEN0_1_Msk) << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 574 | } |
sahilmgandhi | 18:6a4db94011d3 | 575 | |
sahilmgandhi | 18:6a4db94011d3 | 576 | /** |
sahilmgandhi | 18:6a4db94011d3 | 577 | * @brief Disables PDMA transfer of selected channel for PWM capture |
sahilmgandhi | 18:6a4db94011d3 | 578 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 579 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 580 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 581 | * @param[in] u32ChannelNum PWM channel number. |
sahilmgandhi | 18:6a4db94011d3 | 582 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 583 | * @details This function is used to enable PDMA transfer of selected channel(s) for PWM capture. |
sahilmgandhi | 18:6a4db94011d3 | 584 | */ |
sahilmgandhi | 18:6a4db94011d3 | 585 | void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 586 | { |
sahilmgandhi | 18:6a4db94011d3 | 587 | (pwm)->PDMACTL &= ~(PWM_PDMACTL_CHEN0_1_Msk << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 588 | } |
sahilmgandhi | 18:6a4db94011d3 | 589 | |
sahilmgandhi | 18:6a4db94011d3 | 590 | /** |
sahilmgandhi | 18:6a4db94011d3 | 591 | * @brief Enable Dead zone of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 592 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 593 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 594 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 595 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 596 | * @param[in] u32Duration Dead zone length in PWM clock count, valid values are between 0~0xFFF, but 0 means there is no Dead zone. |
sahilmgandhi | 18:6a4db94011d3 | 597 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 598 | * @details This function is used to enable Dead zone of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 599 | * The write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 600 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 601 | */ |
sahilmgandhi | 18:6a4db94011d3 | 602 | void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration) |
sahilmgandhi | 18:6a4db94011d3 | 603 | { |
sahilmgandhi | 18:6a4db94011d3 | 604 | // every two channels share the same setting |
sahilmgandhi | 18:6a4db94011d3 | 605 | *(__IO uint32_t *)(&((pwm)->DTCTL0_1) + (u32ChannelNum >> 1)) &= ~PWM_DTCTL0_1_DTCNT_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 606 | *(__IO uint32_t *)(&((pwm)->DTCTL0_1) + (u32ChannelNum >> 1)) |= PWM_DTCTL0_1_DTEN_Msk | u32Duration; |
sahilmgandhi | 18:6a4db94011d3 | 607 | } |
sahilmgandhi | 18:6a4db94011d3 | 608 | |
sahilmgandhi | 18:6a4db94011d3 | 609 | /** |
sahilmgandhi | 18:6a4db94011d3 | 610 | * @brief Disable Dead zone of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 611 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 612 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 613 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 614 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 615 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 616 | * @details This function is used to disable Dead zone of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 617 | * The write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 618 | */ |
sahilmgandhi | 18:6a4db94011d3 | 619 | void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 620 | { |
sahilmgandhi | 18:6a4db94011d3 | 621 | // every two channels shares the same setting |
sahilmgandhi | 18:6a4db94011d3 | 622 | *(__IO uint32_t *)(&((pwm)->DTCTL0_1) + (u32ChannelNum >> 1)) &= ~PWM_DTCTL0_1_DTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 623 | } |
sahilmgandhi | 18:6a4db94011d3 | 624 | |
sahilmgandhi | 18:6a4db94011d3 | 625 | /** |
sahilmgandhi | 18:6a4db94011d3 | 626 | * @brief Enable capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 627 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 628 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 629 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 630 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 631 | * @param[in] u32Edge Rising or falling edge to latch counter. |
sahilmgandhi | 18:6a4db94011d3 | 632 | * - \ref PWM_CAPTURE_INT_RISING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 633 | * - \ref PWM_CAPTURE_INT_FALLING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 634 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 635 | * @details This function is used to enable capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 636 | */ |
sahilmgandhi | 18:6a4db94011d3 | 637 | void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge) |
sahilmgandhi | 18:6a4db94011d3 | 638 | { |
sahilmgandhi | 18:6a4db94011d3 | 639 | (pwm)->CAPIEN |= (u32Edge << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 640 | } |
sahilmgandhi | 18:6a4db94011d3 | 641 | |
sahilmgandhi | 18:6a4db94011d3 | 642 | /** |
sahilmgandhi | 18:6a4db94011d3 | 643 | * @brief Disable capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 644 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 645 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 646 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 647 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 648 | * @param[in] u32Edge Rising or falling edge to latch counter. |
sahilmgandhi | 18:6a4db94011d3 | 649 | * - \ref PWM_CAPTURE_INT_RISING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 650 | * - \ref PWM_CAPTURE_INT_FALLING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 651 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 652 | * @details This function is used to disable capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 653 | */ |
sahilmgandhi | 18:6a4db94011d3 | 654 | void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge) |
sahilmgandhi | 18:6a4db94011d3 | 655 | { |
sahilmgandhi | 18:6a4db94011d3 | 656 | (pwm)->CAPIEN &= ~(u32Edge << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 657 | } |
sahilmgandhi | 18:6a4db94011d3 | 658 | |
sahilmgandhi | 18:6a4db94011d3 | 659 | /** |
sahilmgandhi | 18:6a4db94011d3 | 660 | * @brief Clear capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 661 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 662 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 663 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 664 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 665 | * @param[in] u32Edge Rising or falling edge to latch counter. |
sahilmgandhi | 18:6a4db94011d3 | 666 | * - \ref PWM_CAPTURE_INT_RISING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 667 | * - \ref PWM_CAPTURE_INT_FALLING_LATCH |
sahilmgandhi | 18:6a4db94011d3 | 668 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 669 | * @details This function is used to clear capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 670 | */ |
sahilmgandhi | 18:6a4db94011d3 | 671 | void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge) |
sahilmgandhi | 18:6a4db94011d3 | 672 | { |
sahilmgandhi | 18:6a4db94011d3 | 673 | (pwm)->CAPIF = (u32Edge << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 674 | } |
sahilmgandhi | 18:6a4db94011d3 | 675 | |
sahilmgandhi | 18:6a4db94011d3 | 676 | /** |
sahilmgandhi | 18:6a4db94011d3 | 677 | * @brief Get capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 678 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 679 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 680 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 681 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 682 | * @retval 0 No capture interrupt |
sahilmgandhi | 18:6a4db94011d3 | 683 | * @retval 1 Rising edge latch interrupt |
sahilmgandhi | 18:6a4db94011d3 | 684 | * @retval 2 Falling edge latch interrupt |
sahilmgandhi | 18:6a4db94011d3 | 685 | * @retval 3 Rising and falling latch interrupt |
sahilmgandhi | 18:6a4db94011d3 | 686 | * @details This function is used to get capture interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 687 | */ |
sahilmgandhi | 18:6a4db94011d3 | 688 | uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 689 | { |
sahilmgandhi | 18:6a4db94011d3 | 690 | return (((((pwm)->CAPIF & (PWM_CAPIF_CFLIF0_Msk << u32ChannelNum)) ? 1 : 0) << 1) | \ |
sahilmgandhi | 18:6a4db94011d3 | 691 | (((pwm)->CAPIF & (PWM_CAPIF_CRLIF0_Msk << u32ChannelNum)) ? 1 : 0)); |
sahilmgandhi | 18:6a4db94011d3 | 692 | } |
sahilmgandhi | 18:6a4db94011d3 | 693 | /** |
sahilmgandhi | 18:6a4db94011d3 | 694 | * @brief Enable duty interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 695 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 696 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 697 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 698 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 699 | * @param[in] u32IntDutyType Duty interrupt type, could be either |
sahilmgandhi | 18:6a4db94011d3 | 700 | * - \ref PWM_DUTY_INT_DOWN_COUNT_MATCH_CMP |
sahilmgandhi | 18:6a4db94011d3 | 701 | * - \ref PWM_DUTY_INT_UP_COUNT_MATCH_CMP |
sahilmgandhi | 18:6a4db94011d3 | 702 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 703 | * @details This function is used to enable duty interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 704 | */ |
sahilmgandhi | 18:6a4db94011d3 | 705 | void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType) |
sahilmgandhi | 18:6a4db94011d3 | 706 | { |
sahilmgandhi | 18:6a4db94011d3 | 707 | (pwm)->INTEN0 |= (u32IntDutyType << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 708 | } |
sahilmgandhi | 18:6a4db94011d3 | 709 | |
sahilmgandhi | 18:6a4db94011d3 | 710 | /** |
sahilmgandhi | 18:6a4db94011d3 | 711 | * @brief Disable duty interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 712 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 713 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 714 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 715 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 716 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 717 | * @details This function is used to disable duty interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 718 | */ |
sahilmgandhi | 18:6a4db94011d3 | 719 | void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 720 | { |
sahilmgandhi | 18:6a4db94011d3 | 721 | (pwm)->INTEN0 &= ~((PWM_DUTY_INT_DOWN_COUNT_MATCH_CMP | PWM_DUTY_INT_UP_COUNT_MATCH_CMP) << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 722 | } |
sahilmgandhi | 18:6a4db94011d3 | 723 | |
sahilmgandhi | 18:6a4db94011d3 | 724 | /** |
sahilmgandhi | 18:6a4db94011d3 | 725 | * @brief Clear duty interrupt flag of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 726 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 727 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 728 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 729 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 730 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 731 | * @details This function is used to clear duty interrupt flag of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 732 | */ |
sahilmgandhi | 18:6a4db94011d3 | 733 | void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 734 | { |
sahilmgandhi | 18:6a4db94011d3 | 735 | (pwm)->INTSTS0 = (PWM_INTSTS0_CMPUIF0_Msk | PWM_INTSTS0_CMPDIF0_Msk) << u32ChannelNum; |
sahilmgandhi | 18:6a4db94011d3 | 736 | } |
sahilmgandhi | 18:6a4db94011d3 | 737 | |
sahilmgandhi | 18:6a4db94011d3 | 738 | /** |
sahilmgandhi | 18:6a4db94011d3 | 739 | * @brief Get duty interrupt flag of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 740 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 741 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 742 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 743 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 744 | * @return Duty interrupt flag of specified channel |
sahilmgandhi | 18:6a4db94011d3 | 745 | * @retval 0 Duty interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 746 | * @retval 1 Duty interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 747 | * @details This function is used to get duty interrupt flag of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 748 | */ |
sahilmgandhi | 18:6a4db94011d3 | 749 | uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 750 | { |
sahilmgandhi | 18:6a4db94011d3 | 751 | return ((((pwm)->INTSTS0 & ((PWM_INTSTS0_CMPDIF0_Msk | PWM_INTSTS0_CMPUIF0_Msk) << u32ChannelNum))) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 752 | } |
sahilmgandhi | 18:6a4db94011d3 | 753 | |
sahilmgandhi | 18:6a4db94011d3 | 754 | /** |
sahilmgandhi | 18:6a4db94011d3 | 755 | * @brief This function enable fault brake interrupt |
sahilmgandhi | 18:6a4db94011d3 | 756 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 757 | * @param[in] u32BrakeSource Fault brake source. |
sahilmgandhi | 18:6a4db94011d3 | 758 | * - \ref PWM_FB_EDGE |
sahilmgandhi | 18:6a4db94011d3 | 759 | * - \ref PWM_FB_LEVEL |
sahilmgandhi | 18:6a4db94011d3 | 760 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 761 | * @details This function is used to enable fault brake interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 762 | * The write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 763 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 764 | */ |
sahilmgandhi | 18:6a4db94011d3 | 765 | void PWM_EnableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource) |
sahilmgandhi | 18:6a4db94011d3 | 766 | { |
sahilmgandhi | 18:6a4db94011d3 | 767 | (pwm)->INTEN1 |= (0x7 << u32BrakeSource); |
sahilmgandhi | 18:6a4db94011d3 | 768 | } |
sahilmgandhi | 18:6a4db94011d3 | 769 | |
sahilmgandhi | 18:6a4db94011d3 | 770 | /** |
sahilmgandhi | 18:6a4db94011d3 | 771 | * @brief This function disable fault brake interrupt |
sahilmgandhi | 18:6a4db94011d3 | 772 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 773 | * @param[in] u32BrakeSource Fault brake source. |
sahilmgandhi | 18:6a4db94011d3 | 774 | * - \ref PWM_FB_EDGE |
sahilmgandhi | 18:6a4db94011d3 | 775 | * - \ref PWM_FB_LEVEL |
sahilmgandhi | 18:6a4db94011d3 | 776 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 777 | * @details This function is used to disable fault brake interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 778 | * The write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 779 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 780 | */ |
sahilmgandhi | 18:6a4db94011d3 | 781 | void PWM_DisableFaultBrakeInt(PWM_T *pwm, uint32_t u32BrakeSource) |
sahilmgandhi | 18:6a4db94011d3 | 782 | { |
sahilmgandhi | 18:6a4db94011d3 | 783 | (pwm)->INTEN1 &= ~(0x7 << u32BrakeSource); |
sahilmgandhi | 18:6a4db94011d3 | 784 | } |
sahilmgandhi | 18:6a4db94011d3 | 785 | |
sahilmgandhi | 18:6a4db94011d3 | 786 | /** |
sahilmgandhi | 18:6a4db94011d3 | 787 | * @brief This function clear fault brake interrupt of selected source |
sahilmgandhi | 18:6a4db94011d3 | 788 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 789 | * @param[in] u32BrakeSource Fault brake source. |
sahilmgandhi | 18:6a4db94011d3 | 790 | * - \ref PWM_FB_EDGE |
sahilmgandhi | 18:6a4db94011d3 | 791 | * - \ref PWM_FB_LEVEL |
sahilmgandhi | 18:6a4db94011d3 | 792 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 793 | * @details This function is used to clear fault brake interrupt of selected source. |
sahilmgandhi | 18:6a4db94011d3 | 794 | * The write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 795 | */ |
sahilmgandhi | 18:6a4db94011d3 | 796 | void PWM_ClearFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource) |
sahilmgandhi | 18:6a4db94011d3 | 797 | { |
sahilmgandhi | 18:6a4db94011d3 | 798 | (pwm)->INTSTS1 = (0x3f << u32BrakeSource); |
sahilmgandhi | 18:6a4db94011d3 | 799 | } |
sahilmgandhi | 18:6a4db94011d3 | 800 | |
sahilmgandhi | 18:6a4db94011d3 | 801 | /** |
sahilmgandhi | 18:6a4db94011d3 | 802 | * @brief This function get fault brake interrupt flag of selected source |
sahilmgandhi | 18:6a4db94011d3 | 803 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 804 | * @param[in] u32BrakeSource Fault brake source, could be either |
sahilmgandhi | 18:6a4db94011d3 | 805 | * - \ref PWM_FB_EDGE |
sahilmgandhi | 18:6a4db94011d3 | 806 | * - \ref PWM_FB_LEVEL |
sahilmgandhi | 18:6a4db94011d3 | 807 | * @return Fault brake interrupt flag of specified source |
sahilmgandhi | 18:6a4db94011d3 | 808 | * @retval 0 Fault brake interrupt did not occurred |
sahilmgandhi | 18:6a4db94011d3 | 809 | * @retval 1 Fault brake interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 810 | * @details This function is used to get fault brake interrupt flag of selected source. |
sahilmgandhi | 18:6a4db94011d3 | 811 | */ |
sahilmgandhi | 18:6a4db94011d3 | 812 | uint32_t PWM_GetFaultBrakeIntFlag(PWM_T *pwm, uint32_t u32BrakeSource) |
sahilmgandhi | 18:6a4db94011d3 | 813 | { |
sahilmgandhi | 18:6a4db94011d3 | 814 | return (((pwm)->INTSTS1 & (0x3f << u32BrakeSource)) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 815 | } |
sahilmgandhi | 18:6a4db94011d3 | 816 | |
sahilmgandhi | 18:6a4db94011d3 | 817 | /** |
sahilmgandhi | 18:6a4db94011d3 | 818 | * @brief Enable period interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 819 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 820 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 821 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 822 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 823 | * @param[in] u32IntPeriodType Period interrupt type. This parameter is not used. |
sahilmgandhi | 18:6a4db94011d3 | 824 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 825 | * @details This function is used to enable period interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 826 | */ |
sahilmgandhi | 18:6a4db94011d3 | 827 | void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType) |
sahilmgandhi | 18:6a4db94011d3 | 828 | { |
sahilmgandhi | 18:6a4db94011d3 | 829 | (pwm)->INTEN0 |= (PWM_INTEN0_PIEN0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 830 | } |
sahilmgandhi | 18:6a4db94011d3 | 831 | |
sahilmgandhi | 18:6a4db94011d3 | 832 | /** |
sahilmgandhi | 18:6a4db94011d3 | 833 | * @brief Disable period interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 834 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 835 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 836 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 837 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 838 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 839 | * @details This function is used to disable period interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 840 | */ |
sahilmgandhi | 18:6a4db94011d3 | 841 | void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 842 | { |
sahilmgandhi | 18:6a4db94011d3 | 843 | (pwm)->INTEN0 &= ~(PWM_INTEN0_PIEN0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 844 | } |
sahilmgandhi | 18:6a4db94011d3 | 845 | |
sahilmgandhi | 18:6a4db94011d3 | 846 | /** |
sahilmgandhi | 18:6a4db94011d3 | 847 | * @brief Clear period interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 848 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 849 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 850 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 851 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 852 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 853 | * @details This function is used to clear period interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 854 | */ |
sahilmgandhi | 18:6a4db94011d3 | 855 | void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 856 | { |
sahilmgandhi | 18:6a4db94011d3 | 857 | (pwm)->INTSTS0 = (PWM_INTSTS0_PIF0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 858 | } |
sahilmgandhi | 18:6a4db94011d3 | 859 | |
sahilmgandhi | 18:6a4db94011d3 | 860 | /** |
sahilmgandhi | 18:6a4db94011d3 | 861 | * @brief Get period interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 862 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 863 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 864 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 865 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 866 | * @return Period interrupt flag of specified channel |
sahilmgandhi | 18:6a4db94011d3 | 867 | * @retval 0 Period interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 868 | * @retval 1 Period interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 869 | * @details This function is used to get period interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 870 | */ |
sahilmgandhi | 18:6a4db94011d3 | 871 | uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 872 | { |
sahilmgandhi | 18:6a4db94011d3 | 873 | return ((((pwm)->INTSTS0 & (PWM_INTSTS0_PIF0_Msk << u32ChannelNum))) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 874 | } |
sahilmgandhi | 18:6a4db94011d3 | 875 | |
sahilmgandhi | 18:6a4db94011d3 | 876 | /** |
sahilmgandhi | 18:6a4db94011d3 | 877 | * @brief Enable zero interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 878 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 879 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 880 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 881 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 882 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 883 | * @details This function is used to enable zero interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 884 | */ |
sahilmgandhi | 18:6a4db94011d3 | 885 | void PWM_EnableZeroInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 886 | { |
sahilmgandhi | 18:6a4db94011d3 | 887 | (pwm)->INTEN0 |= (PWM_INTEN0_ZIEN0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 888 | } |
sahilmgandhi | 18:6a4db94011d3 | 889 | |
sahilmgandhi | 18:6a4db94011d3 | 890 | /** |
sahilmgandhi | 18:6a4db94011d3 | 891 | * @brief Disable zero interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 892 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 893 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 894 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 895 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 896 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 897 | * @details This function is used to disable zero interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 898 | */ |
sahilmgandhi | 18:6a4db94011d3 | 899 | void PWM_DisableZeroInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 900 | { |
sahilmgandhi | 18:6a4db94011d3 | 901 | (pwm)->INTEN0 &= ~(PWM_INTEN0_ZIEN0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 902 | } |
sahilmgandhi | 18:6a4db94011d3 | 903 | |
sahilmgandhi | 18:6a4db94011d3 | 904 | /** |
sahilmgandhi | 18:6a4db94011d3 | 905 | * @brief Clear zero interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 906 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 907 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 908 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 909 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 910 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 911 | * @details This function is used to clear zero interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 912 | */ |
sahilmgandhi | 18:6a4db94011d3 | 913 | void PWM_ClearZeroIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 914 | { |
sahilmgandhi | 18:6a4db94011d3 | 915 | (pwm)->INTSTS0 = (PWM_INTSTS0_ZIF0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 916 | } |
sahilmgandhi | 18:6a4db94011d3 | 917 | |
sahilmgandhi | 18:6a4db94011d3 | 918 | /** |
sahilmgandhi | 18:6a4db94011d3 | 919 | * @brief Get zero interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 920 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 921 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 922 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 923 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 924 | * @return Zero interrupt flag of specified channel |
sahilmgandhi | 18:6a4db94011d3 | 925 | * @retval 0 Zero interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 926 | * @retval 1 Zero interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 927 | * @details This function is used to get zero interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 928 | */ |
sahilmgandhi | 18:6a4db94011d3 | 929 | uint32_t PWM_GetZeroIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 930 | { |
sahilmgandhi | 18:6a4db94011d3 | 931 | return ((((pwm)->INTSTS0 & (PWM_INTSTS0_ZIF0_Msk << u32ChannelNum))) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 932 | } |
sahilmgandhi | 18:6a4db94011d3 | 933 | |
sahilmgandhi | 18:6a4db94011d3 | 934 | /** |
sahilmgandhi | 18:6a4db94011d3 | 935 | * @brief Enable interrupt flag accumulator of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 936 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 937 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 938 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 939 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 940 | * @param[in] u32IntFlagCnt Interrupt flag counter. Valid values are between 0~15. |
sahilmgandhi | 18:6a4db94011d3 | 941 | * @param[in] u32IntAccSrc Interrupt flag accumulator source selection. |
sahilmgandhi | 18:6a4db94011d3 | 942 | * - \ref PWM_IFA_EVEN_ZERO_POINT |
sahilmgandhi | 18:6a4db94011d3 | 943 | * - \ref PWM_IFA_EVEN_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 944 | * - \ref PWM_IFA_EVEN_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 945 | * - \ref PWM_IFA_EVEN_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 946 | * - \ref PWM_IFA_ODD_ZERO_POINT |
sahilmgandhi | 18:6a4db94011d3 | 947 | * - \ref PWM_IFA_ODD_PERIOD_POINT |
sahilmgandhi | 18:6a4db94011d3 | 948 | * - \ref PWM_IFA_ODD_COMPARE_UP_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 949 | * - \ref PWM_IFA_ODD_COMPARE_DOWN_COUNT_POINT |
sahilmgandhi | 18:6a4db94011d3 | 950 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 951 | * @details This function is used to enable interrupt flag accumulator of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 952 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 953 | */ |
sahilmgandhi | 18:6a4db94011d3 | 954 | void PWM_EnableAcc(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntFlagCnt, uint32_t u32IntAccSrc) |
sahilmgandhi | 18:6a4db94011d3 | 955 | { |
sahilmgandhi | 18:6a4db94011d3 | 956 | (pwm)->IFA = ((pwm)->IFA & ~((PWM_IFA_IFCNT0_1_Msk | PWM_IFA_IFSEL0_1_Msk) << ((u32ChannelNum >> 1) * 8))) | \ |
sahilmgandhi | 18:6a4db94011d3 | 957 | ((PWM_IFA_IFAEN0_1_Msk | (u32IntAccSrc << PWM_IFA_IFSEL0_1_Pos) | u32IntFlagCnt) << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 958 | } |
sahilmgandhi | 18:6a4db94011d3 | 959 | |
sahilmgandhi | 18:6a4db94011d3 | 960 | /** |
sahilmgandhi | 18:6a4db94011d3 | 961 | * @brief Disable interrupt flag accumulator of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 962 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 963 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 964 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 965 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 966 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 967 | * @details This function is used to Disable interrupt flag accumulator of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 968 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 969 | */ |
sahilmgandhi | 18:6a4db94011d3 | 970 | void PWM_DisableAcc(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 971 | { |
sahilmgandhi | 18:6a4db94011d3 | 972 | (pwm)->IFA = (pwm)->IFA & ~(PWM_IFA_IFAEN0_1_Msk << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 973 | } |
sahilmgandhi | 18:6a4db94011d3 | 974 | |
sahilmgandhi | 18:6a4db94011d3 | 975 | /** |
sahilmgandhi | 18:6a4db94011d3 | 976 | * @brief Enable interrupt flag accumulator interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 977 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 978 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 979 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 980 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 981 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 982 | * @details This function is used to enable interrupt flag accumulator interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 983 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 984 | */ |
sahilmgandhi | 18:6a4db94011d3 | 985 | void PWM_EnableAccInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 986 | { |
sahilmgandhi | 18:6a4db94011d3 | 987 | (pwm)->INTEN0 |= (PWM_INTEN0_IFAIEN0_1_Msk << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 988 | } |
sahilmgandhi | 18:6a4db94011d3 | 989 | |
sahilmgandhi | 18:6a4db94011d3 | 990 | /** |
sahilmgandhi | 18:6a4db94011d3 | 991 | * @brief Disable interrupt flag accumulator interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 992 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 993 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 994 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 995 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 996 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 997 | * @details This function is used to disable interrupt flag accumulator interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 998 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 999 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1000 | void PWM_DisableAccInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1001 | { |
sahilmgandhi | 18:6a4db94011d3 | 1002 | (pwm)->INTEN0 &= ~(PWM_INTEN0_IFAIEN0_1_Msk << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 1003 | } |
sahilmgandhi | 18:6a4db94011d3 | 1004 | |
sahilmgandhi | 18:6a4db94011d3 | 1005 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1006 | * @brief Clear interrupt flag accumulator interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1007 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1008 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1009 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1010 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1011 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1012 | * @details This function is used to clear interrupt flag accumulator interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1013 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 1014 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1015 | void PWM_ClearAccInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1016 | { |
sahilmgandhi | 18:6a4db94011d3 | 1017 | (pwm)->INTSTS0 = (PWM_INTSTS0_IFAIF0_1_Msk << ((u32ChannelNum >> 1) * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 1018 | } |
sahilmgandhi | 18:6a4db94011d3 | 1019 | |
sahilmgandhi | 18:6a4db94011d3 | 1020 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1021 | * @brief Get interrupt flag accumulator interrupt of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1022 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1023 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1024 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1025 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1026 | * @retval 0 Accumulator interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 1027 | * @retval 1 Accumulator interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 1028 | * @details This function is used to Get interrupt flag accumulator interrupt of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1029 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 1030 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1031 | uint32_t PWM_GetAccInt(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1032 | { |
sahilmgandhi | 18:6a4db94011d3 | 1033 | return (((pwm)->INTSTS0 & (PWM_INTSTS0_IFAIF0_1_Msk << ((u32ChannelNum >> 1) * 8))) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 1034 | } |
sahilmgandhi | 18:6a4db94011d3 | 1035 | |
sahilmgandhi | 18:6a4db94011d3 | 1036 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1037 | * @brief Clear free trigger duty interrupt flag of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1038 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1039 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1040 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1041 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1042 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1043 | * @details This function is used to clear free trigger duty interrupt flag of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1044 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1045 | void PWM_ClearFTDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1046 | { |
sahilmgandhi | 18:6a4db94011d3 | 1047 | (pwm)->FTCI = ((PWM_FTCI_FTCMU0_Msk | PWM_FTCI_FTCMD0_Msk) << (u32ChannelNum >> 1)); |
sahilmgandhi | 18:6a4db94011d3 | 1048 | } |
sahilmgandhi | 18:6a4db94011d3 | 1049 | |
sahilmgandhi | 18:6a4db94011d3 | 1050 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1051 | * @brief Get free trigger duty interrupt flag of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1052 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1053 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1054 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1055 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1056 | * @return Duty interrupt flag of specified channel |
sahilmgandhi | 18:6a4db94011d3 | 1057 | * @retval 0 Free trigger duty interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 1058 | * @retval 1 Free trigger duty interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 1059 | * @details This function is used to get free trigger duty interrupt flag of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1060 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1061 | uint32_t PWM_GetFTDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1062 | { |
sahilmgandhi | 18:6a4db94011d3 | 1063 | return (((pwm)->FTCI & ((PWM_FTCI_FTCMU0_Msk | PWM_FTCI_FTCMD0_Msk) << (u32ChannelNum >> 1))) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 1064 | } |
sahilmgandhi | 18:6a4db94011d3 | 1065 | |
sahilmgandhi | 18:6a4db94011d3 | 1066 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1067 | * @brief Enable load mode of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1068 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1069 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1070 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1071 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1072 | * @param[in] u32LoadMode PWM counter loading mode. |
sahilmgandhi | 18:6a4db94011d3 | 1073 | * - \ref PWM_LOAD_MODE_IMMEDIATE |
sahilmgandhi | 18:6a4db94011d3 | 1074 | * - \ref PWM_LOAD_MODE_WINDOW |
sahilmgandhi | 18:6a4db94011d3 | 1075 | * - \ref PWM_LOAD_MODE_CENTER |
sahilmgandhi | 18:6a4db94011d3 | 1076 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1077 | * @details This function is used to enable load mode of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1078 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1079 | void PWM_EnableLoadMode(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32LoadMode) |
sahilmgandhi | 18:6a4db94011d3 | 1080 | { |
sahilmgandhi | 18:6a4db94011d3 | 1081 | (pwm)->CTL0 |= (u32LoadMode << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 1082 | } |
sahilmgandhi | 18:6a4db94011d3 | 1083 | |
sahilmgandhi | 18:6a4db94011d3 | 1084 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1085 | * @brief Disable load mode of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1086 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1087 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1088 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1089 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1090 | * @param[in] u32LoadMode PWM counter loading mode. |
sahilmgandhi | 18:6a4db94011d3 | 1091 | * - \ref PWM_LOAD_MODE_IMMEDIATE |
sahilmgandhi | 18:6a4db94011d3 | 1092 | * - \ref PWM_LOAD_MODE_WINDOW |
sahilmgandhi | 18:6a4db94011d3 | 1093 | * - \ref PWM_LOAD_MODE_CENTER |
sahilmgandhi | 18:6a4db94011d3 | 1094 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1095 | * @details This function is used to disable load mode of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1096 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1097 | void PWM_DisableLoadMode(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32LoadMode) |
sahilmgandhi | 18:6a4db94011d3 | 1098 | { |
sahilmgandhi | 18:6a4db94011d3 | 1099 | (pwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 1100 | } |
sahilmgandhi | 18:6a4db94011d3 | 1101 | |
sahilmgandhi | 18:6a4db94011d3 | 1102 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1103 | * @brief Configure synchronization phase of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1104 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1105 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1106 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1107 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1108 | * @param[in] u32SyncSrc PWM synchronize source selection. |
sahilmgandhi | 18:6a4db94011d3 | 1109 | * - \ref PWM_SYNC_OUT_FROM_SYNCIN_SWSYNC |
sahilmgandhi | 18:6a4db94011d3 | 1110 | * - \ref PWM_SYNC_OUT_FROM_COUNT_TO_ZERO |
sahilmgandhi | 18:6a4db94011d3 | 1111 | * - \ref PWM_SYNC_OUT_FROM_COUNT_TO_COMPARATOR |
sahilmgandhi | 18:6a4db94011d3 | 1112 | * - \ref PWM_SYNC_OUT_DISABLE |
sahilmgandhi | 18:6a4db94011d3 | 1113 | * @param[in] u32Direction Phase direction. Control PWM counter count decrement or increment after synchronizing. |
sahilmgandhi | 18:6a4db94011d3 | 1114 | * - \ref PWM_PHS_DIR_DECREMENT |
sahilmgandhi | 18:6a4db94011d3 | 1115 | * - \ref PWM_PHS_DIR_INCREMENT |
sahilmgandhi | 18:6a4db94011d3 | 1116 | * @param[in] u32StartPhase Synchronous start phase value. Valid values are between 0~65535. |
sahilmgandhi | 18:6a4db94011d3 | 1117 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1118 | * @details This function is used to configure synchronization phase of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1119 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 1120 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1121 | void PWM_ConfigSyncPhase(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32SyncSrc, uint32_t u32Direction, uint32_t u32StartPhase) |
sahilmgandhi | 18:6a4db94011d3 | 1122 | { |
sahilmgandhi | 18:6a4db94011d3 | 1123 | // every two channels shares the same setting |
sahilmgandhi | 18:6a4db94011d3 | 1124 | u32ChannelNum >>= 1; |
sahilmgandhi | 18:6a4db94011d3 | 1125 | (pwm)->SYNC = (((pwm)->SYNC & ~((PWM_SYNC_SINSRC0_Msk << (u32ChannelNum << 1)) | (PWM_SYNC_PHSDIR0_Msk << u32ChannelNum))) | \ |
sahilmgandhi | 18:6a4db94011d3 | 1126 | (u32Direction << PWM_SYNC_PHSDIR0_Pos << u32ChannelNum) | (u32SyncSrc << PWM_SYNC_SINSRC0_Pos) << (u32ChannelNum << 1)); |
sahilmgandhi | 18:6a4db94011d3 | 1127 | *(__IO uint32_t *)(&((pwm)->PHS0_1) + u32ChannelNum) = u32StartPhase; |
sahilmgandhi | 18:6a4db94011d3 | 1128 | } |
sahilmgandhi | 18:6a4db94011d3 | 1129 | |
sahilmgandhi | 18:6a4db94011d3 | 1130 | |
sahilmgandhi | 18:6a4db94011d3 | 1131 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1132 | * @brief Enable SYNC phase of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 1133 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1134 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1135 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1136 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 1137 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 1138 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1139 | * @details This function is used to enable SYNC phase of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 1140 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 1141 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1142 | void PWM_EnableSyncPhase(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 1143 | { |
sahilmgandhi | 18:6a4db94011d3 | 1144 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 1145 | for(i = 0; i < PWM_CHANNEL_NUM; i ++) |
sahilmgandhi | 18:6a4db94011d3 | 1146 | { |
sahilmgandhi | 18:6a4db94011d3 | 1147 | if(u32ChannelMask & (1 << i)) |
sahilmgandhi | 18:6a4db94011d3 | 1148 | { |
sahilmgandhi | 18:6a4db94011d3 | 1149 | (pwm)->SYNC |= (PWM_SYNC_PHSEN0_Msk << (i >> 1)); |
sahilmgandhi | 18:6a4db94011d3 | 1150 | } |
sahilmgandhi | 18:6a4db94011d3 | 1151 | } |
sahilmgandhi | 18:6a4db94011d3 | 1152 | } |
sahilmgandhi | 18:6a4db94011d3 | 1153 | |
sahilmgandhi | 18:6a4db94011d3 | 1154 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1155 | * @brief Disable SYNC phase of selected channel(s) |
sahilmgandhi | 18:6a4db94011d3 | 1156 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1157 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1158 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1159 | * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel. |
sahilmgandhi | 18:6a4db94011d3 | 1160 | * Bit 0 is channel 0, bit 1 is channel 1... |
sahilmgandhi | 18:6a4db94011d3 | 1161 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1162 | * @details This function is used to disable SYNC phase of selected channel(s). |
sahilmgandhi | 18:6a4db94011d3 | 1163 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 1164 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1165 | void PWM_DisableSyncPhase(PWM_T *pwm, uint32_t u32ChannelMask) |
sahilmgandhi | 18:6a4db94011d3 | 1166 | { |
sahilmgandhi | 18:6a4db94011d3 | 1167 | uint32_t i; |
sahilmgandhi | 18:6a4db94011d3 | 1168 | for(i = 0; i < PWM_CHANNEL_NUM; i ++) |
sahilmgandhi | 18:6a4db94011d3 | 1169 | { |
sahilmgandhi | 18:6a4db94011d3 | 1170 | if(u32ChannelMask & (1 << i)) |
sahilmgandhi | 18:6a4db94011d3 | 1171 | { |
sahilmgandhi | 18:6a4db94011d3 | 1172 | (pwm)->SYNC &= ~(PWM_SYNC_PHSEN0_Msk << (i >> 1)); |
sahilmgandhi | 18:6a4db94011d3 | 1173 | } |
sahilmgandhi | 18:6a4db94011d3 | 1174 | } |
sahilmgandhi | 18:6a4db94011d3 | 1175 | } |
sahilmgandhi | 18:6a4db94011d3 | 1176 | |
sahilmgandhi | 18:6a4db94011d3 | 1177 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1178 | * @brief Enable PWM SYNC_IN noise filter function |
sahilmgandhi | 18:6a4db94011d3 | 1179 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1180 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1181 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1182 | * @param[in] u32ClkCnt SYNC Edge Detector Filter Count. This controls the counter number of edge detector. |
sahilmgandhi | 18:6a4db94011d3 | 1183 | * The valid value is 0~7. |
sahilmgandhi | 18:6a4db94011d3 | 1184 | * @param[in] u32ClkDivSel SYNC Edge Detector Filter Clock Selection. |
sahilmgandhi | 18:6a4db94011d3 | 1185 | * - \ref PWM_NF_CLK_DIV_1 |
sahilmgandhi | 18:6a4db94011d3 | 1186 | * - \ref PWM_NF_CLK_DIV_2 |
sahilmgandhi | 18:6a4db94011d3 | 1187 | * - \ref PWM_NF_CLK_DIV_4 |
sahilmgandhi | 18:6a4db94011d3 | 1188 | * - \ref PWM_NF_CLK_DIV_8 |
sahilmgandhi | 18:6a4db94011d3 | 1189 | * - \ref PWM_NF_CLK_DIV_16 |
sahilmgandhi | 18:6a4db94011d3 | 1190 | * - \ref PWM_NF_CLK_DIV_32 |
sahilmgandhi | 18:6a4db94011d3 | 1191 | * - \ref PWM_NF_CLK_DIV_64 |
sahilmgandhi | 18:6a4db94011d3 | 1192 | * - \ref PWM_NF_CLK_DIV_128 |
sahilmgandhi | 18:6a4db94011d3 | 1193 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1194 | * @details This function is used to enable PWM SYNC_IN noise filter function. |
sahilmgandhi | 18:6a4db94011d3 | 1195 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1196 | void PWM_EnableSyncNoiseFilter(PWM_T *pwm, uint32_t u32ClkCnt, uint32_t u32ClkDivSel) |
sahilmgandhi | 18:6a4db94011d3 | 1197 | { |
sahilmgandhi | 18:6a4db94011d3 | 1198 | (pwm)->SYNC = ((pwm)->SYNC & ~(PWM_SYNC_SFLTCNT_Msk | PWM_SYNC_SFLTCSEL_Msk)) | \ |
sahilmgandhi | 18:6a4db94011d3 | 1199 | ((u32ClkCnt << PWM_SYNC_SFLTCNT_Pos) | (u32ClkDivSel << PWM_SYNC_SFLTCSEL_Pos) | PWM_SYNC_SNFLTEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 1200 | } |
sahilmgandhi | 18:6a4db94011d3 | 1201 | |
sahilmgandhi | 18:6a4db94011d3 | 1202 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1203 | * @brief Disable PWM SYNC_IN noise filter function |
sahilmgandhi | 18:6a4db94011d3 | 1204 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1205 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1206 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1207 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1208 | * @details This function is used to Disable PWM SYNC_IN noise filter function. |
sahilmgandhi | 18:6a4db94011d3 | 1209 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1210 | void PWM_DisableSyncNoiseFilter(PWM_T *pwm) |
sahilmgandhi | 18:6a4db94011d3 | 1211 | { |
sahilmgandhi | 18:6a4db94011d3 | 1212 | (pwm)->SYNC &= ~PWM_SYNC_SNFLTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 1213 | } |
sahilmgandhi | 18:6a4db94011d3 | 1214 | |
sahilmgandhi | 18:6a4db94011d3 | 1215 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1216 | * @brief Enable PWM SYNC input pin inverse function |
sahilmgandhi | 18:6a4db94011d3 | 1217 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1218 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1219 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1220 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1221 | * @details This function is used to enable PWM SYNC input pin inverse function. |
sahilmgandhi | 18:6a4db94011d3 | 1222 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1223 | void PWM_EnableSyncPinInverse(PWM_T *pwm) |
sahilmgandhi | 18:6a4db94011d3 | 1224 | { |
sahilmgandhi | 18:6a4db94011d3 | 1225 | (pwm)->SYNC |= PWM_SYNC_SINPINV_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 1226 | } |
sahilmgandhi | 18:6a4db94011d3 | 1227 | |
sahilmgandhi | 18:6a4db94011d3 | 1228 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1229 | * @brief Disable PWM SYNC input pin inverse function |
sahilmgandhi | 18:6a4db94011d3 | 1230 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1231 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1232 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1233 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1234 | * @details This function is used to Disable PWM SYNC input pin inverse function. |
sahilmgandhi | 18:6a4db94011d3 | 1235 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1236 | void PWM_DisableSyncPinInverse(PWM_T *pwm) |
sahilmgandhi | 18:6a4db94011d3 | 1237 | { |
sahilmgandhi | 18:6a4db94011d3 | 1238 | (pwm)->SYNC &= ~PWM_SYNC_SINPINV_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 1239 | } |
sahilmgandhi | 18:6a4db94011d3 | 1240 | |
sahilmgandhi | 18:6a4db94011d3 | 1241 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1242 | * @brief Set PWM clock source |
sahilmgandhi | 18:6a4db94011d3 | 1243 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1244 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1245 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1246 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1247 | * @param[in] u32ClkSrcSel PWM external clock source. |
sahilmgandhi | 18:6a4db94011d3 | 1248 | * - \ref PWM_CLKSRC_PWM_CLK |
sahilmgandhi | 18:6a4db94011d3 | 1249 | * - \ref PWM_CLKSRC_TIMER0 |
sahilmgandhi | 18:6a4db94011d3 | 1250 | * - \ref PWM_CLKSRC_TIMER1 |
sahilmgandhi | 18:6a4db94011d3 | 1251 | * - \ref PWM_CLKSRC_TIMER2 |
sahilmgandhi | 18:6a4db94011d3 | 1252 | * - \ref PWM_CLKSRC_TIMER3 |
sahilmgandhi | 18:6a4db94011d3 | 1253 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1254 | * @details This function is used to set PWM clock source. |
sahilmgandhi | 18:6a4db94011d3 | 1255 | * @note Every two channels share the same setting. |
sahilmgandhi | 18:6a4db94011d3 | 1256 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1257 | void PWM_SetClockSource(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel) |
sahilmgandhi | 18:6a4db94011d3 | 1258 | { |
sahilmgandhi | 18:6a4db94011d3 | 1259 | (pwm)->CLKSRC = (pwm)->CLKSRC & ~(PWM_CLKSRC_ECLKSRC0_Msk << ((u32ChannelNum >> 1) * PWM_CLKSRC_ECLKSRC2_Pos)) | \ |
sahilmgandhi | 18:6a4db94011d3 | 1260 | (u32ClkSrcSel << ((u32ChannelNum >> 1) * PWM_CLKSRC_ECLKSRC2_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 1261 | } |
sahilmgandhi | 18:6a4db94011d3 | 1262 | |
sahilmgandhi | 18:6a4db94011d3 | 1263 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1264 | * @brief Enable PWM brake noise filter function |
sahilmgandhi | 18:6a4db94011d3 | 1265 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1266 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1267 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1268 | * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1. |
sahilmgandhi | 18:6a4db94011d3 | 1269 | * @param[in] u32ClkCnt SYNC Edge Detector Filter Count. This controls the counter number of edge detector |
sahilmgandhi | 18:6a4db94011d3 | 1270 | * @param[in] u32ClkDivSel SYNC Edge Detector Filter Clock Selection. |
sahilmgandhi | 18:6a4db94011d3 | 1271 | * - \ref PWM_NF_CLK_DIV_1 |
sahilmgandhi | 18:6a4db94011d3 | 1272 | * - \ref PWM_NF_CLK_DIV_2 |
sahilmgandhi | 18:6a4db94011d3 | 1273 | * - \ref PWM_NF_CLK_DIV_4 |
sahilmgandhi | 18:6a4db94011d3 | 1274 | * - \ref PWM_NF_CLK_DIV_8 |
sahilmgandhi | 18:6a4db94011d3 | 1275 | * - \ref PWM_NF_CLK_DIV_16 |
sahilmgandhi | 18:6a4db94011d3 | 1276 | * - \ref PWM_NF_CLK_DIV_32 |
sahilmgandhi | 18:6a4db94011d3 | 1277 | * - \ref PWM_NF_CLK_DIV_64 |
sahilmgandhi | 18:6a4db94011d3 | 1278 | * - \ref PWM_NF_CLK_DIV_128 |
sahilmgandhi | 18:6a4db94011d3 | 1279 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1280 | * @details This function is used to enable PWM brake noise filter function. |
sahilmgandhi | 18:6a4db94011d3 | 1281 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1282 | void PWM_EnableBrakeNoiseFilter(PWM_T *pwm, uint32_t u32BrakePinNum, uint32_t u32ClkCnt, uint32_t u32ClkDivSel) |
sahilmgandhi | 18:6a4db94011d3 | 1283 | { |
sahilmgandhi | 18:6a4db94011d3 | 1284 | (pwm)->BNF = ((pwm)->BNF & ~((PWM_BNF_BRK0FCNT_Msk | PWM_BNF_BRK0NFSEL_Msk) << (u32BrakePinNum * PWM_BNF_BRK1NFEN_Pos))) | \ |
sahilmgandhi | 18:6a4db94011d3 | 1285 | (((u32ClkCnt << PWM_BNF_BRK0FCNT_Pos) | (u32ClkDivSel << PWM_BNF_BRK0NFSEL_Pos) | PWM_BNF_BRK0NFEN_Msk) << (u32BrakePinNum * PWM_BNF_BRK1NFEN_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 1286 | } |
sahilmgandhi | 18:6a4db94011d3 | 1287 | |
sahilmgandhi | 18:6a4db94011d3 | 1288 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1289 | * @brief Disable PWM brake noise filter function |
sahilmgandhi | 18:6a4db94011d3 | 1290 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1291 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1292 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1293 | * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1. |
sahilmgandhi | 18:6a4db94011d3 | 1294 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1295 | * @details This function is used to disable PWM brake noise filter function. |
sahilmgandhi | 18:6a4db94011d3 | 1296 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1297 | void PWM_DisableBrakeNoiseFilter(PWM_T *pwm, uint32_t u32BrakePinNum) |
sahilmgandhi | 18:6a4db94011d3 | 1298 | { |
sahilmgandhi | 18:6a4db94011d3 | 1299 | (pwm)->BNF &= ~(PWM_BNF_BRK0NFEN_Msk << (u32BrakePinNum * PWM_BNF_BRK1NFEN_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 1300 | } |
sahilmgandhi | 18:6a4db94011d3 | 1301 | |
sahilmgandhi | 18:6a4db94011d3 | 1302 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1303 | * @brief Enable PWM brake pin inverse function |
sahilmgandhi | 18:6a4db94011d3 | 1304 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1305 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1306 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1307 | * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1. |
sahilmgandhi | 18:6a4db94011d3 | 1308 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1309 | * @details This function is used to enable PWM brake pin inverse function. |
sahilmgandhi | 18:6a4db94011d3 | 1310 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1311 | void PWM_EnableBrakePinInverse(PWM_T *pwm, uint32_t u32BrakePinNum) |
sahilmgandhi | 18:6a4db94011d3 | 1312 | { |
sahilmgandhi | 18:6a4db94011d3 | 1313 | (pwm)->BNF |= (PWM_BNF_BRK0PINV_Msk << (u32BrakePinNum * PWM_BNF_BRK1NFEN_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 1314 | } |
sahilmgandhi | 18:6a4db94011d3 | 1315 | |
sahilmgandhi | 18:6a4db94011d3 | 1316 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1317 | * @brief Disable PWM brake pin inverse function |
sahilmgandhi | 18:6a4db94011d3 | 1318 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1319 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1320 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1321 | * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1. |
sahilmgandhi | 18:6a4db94011d3 | 1322 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1323 | * @details This function is used to disable PWM brake pin inverse function. |
sahilmgandhi | 18:6a4db94011d3 | 1324 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1325 | void PWM_DisableBrakePinInverse(PWM_T *pwm, uint32_t u32BrakePinNum) |
sahilmgandhi | 18:6a4db94011d3 | 1326 | { |
sahilmgandhi | 18:6a4db94011d3 | 1327 | (pwm)->BNF &= ~(PWM_BNF_BRK0PINV_Msk << (u32BrakePinNum * PWM_BNF_BRK1NFEN_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 1328 | } |
sahilmgandhi | 18:6a4db94011d3 | 1329 | |
sahilmgandhi | 18:6a4db94011d3 | 1330 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1331 | * @brief Set PWM brake pin source |
sahilmgandhi | 18:6a4db94011d3 | 1332 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1333 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1334 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1335 | * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1. |
sahilmgandhi | 18:6a4db94011d3 | 1336 | * @param[in] u32SelAnotherModule Select to another module. Valid values are TRUE or FALSE. |
sahilmgandhi | 18:6a4db94011d3 | 1337 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1338 | * @details This function is used to set PWM brake pin source. |
sahilmgandhi | 18:6a4db94011d3 | 1339 | * @note This function is only supported in M45xD/M45xC. |
sahilmgandhi | 18:6a4db94011d3 | 1340 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1341 | void PWM_SetBrakePinSource(PWM_T *pwm, uint32_t u32BrakePinNum, uint32_t u32SelAnotherModule) |
sahilmgandhi | 18:6a4db94011d3 | 1342 | { |
sahilmgandhi | 18:6a4db94011d3 | 1343 | (pwm)->BNF = ((pwm)->BNF & ~(PWM_BNF_BK0SRC_Msk << (u32BrakePinNum * 8))) | (u32SelAnotherModule << (PWM_BNF_BK0SRC_Pos + u32BrakePinNum * 8)); |
sahilmgandhi | 18:6a4db94011d3 | 1344 | } |
sahilmgandhi | 18:6a4db94011d3 | 1345 | |
sahilmgandhi | 18:6a4db94011d3 | 1346 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1347 | * @brief Get the time-base counter reached its maximum value flag of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1348 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1349 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1350 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1351 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1352 | * @return Count to max interrupt flag of specified channel |
sahilmgandhi | 18:6a4db94011d3 | 1353 | * @retval 0 Count to max interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 1354 | * @retval 1 Count to max interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 1355 | * @details This function is used to get the time-base counter reached its maximum value flag of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1356 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1357 | uint32_t PWM_GetWrapAroundFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1358 | { |
sahilmgandhi | 18:6a4db94011d3 | 1359 | return (((pwm)->STATUS & (PWM_STATUS_CNTMAXF0_Msk << u32ChannelNum)) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 1360 | } |
sahilmgandhi | 18:6a4db94011d3 | 1361 | |
sahilmgandhi | 18:6a4db94011d3 | 1362 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1363 | * @brief Clear the time-base counter reached its maximum value flag of selected channel |
sahilmgandhi | 18:6a4db94011d3 | 1364 | * @param[in] pwm The pointer of the specified PWM module |
sahilmgandhi | 18:6a4db94011d3 | 1365 | * - PWM0 : PWM Group 0 |
sahilmgandhi | 18:6a4db94011d3 | 1366 | * - PWM1 : PWM Group 1 |
sahilmgandhi | 18:6a4db94011d3 | 1367 | * @param[in] u32ChannelNum PWM channel number. Valid values are between 0~5 |
sahilmgandhi | 18:6a4db94011d3 | 1368 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 1369 | * @details This function is used to clear the time-base counter reached its maximum value flag of selected channel. |
sahilmgandhi | 18:6a4db94011d3 | 1370 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1371 | void PWM_ClearWrapAroundFlag(PWM_T *pwm, uint32_t u32ChannelNum) |
sahilmgandhi | 18:6a4db94011d3 | 1372 | { |
sahilmgandhi | 18:6a4db94011d3 | 1373 | (pwm)->STATUS = (PWM_STATUS_CNTMAXF0_Msk << u32ChannelNum); |
sahilmgandhi | 18:6a4db94011d3 | 1374 | } |
sahilmgandhi | 18:6a4db94011d3 | 1375 | |
sahilmgandhi | 18:6a4db94011d3 | 1376 | |
sahilmgandhi | 18:6a4db94011d3 | 1377 | /*@}*/ /* end of group PWM_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 1378 | |
sahilmgandhi | 18:6a4db94011d3 | 1379 | /*@}*/ /* end of group PWM_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 1380 | |
sahilmgandhi | 18:6a4db94011d3 | 1381 | /*@}*/ /* end of group Standard_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 1382 | |
sahilmgandhi | 18:6a4db94011d3 | 1383 | /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/ |