pwm.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // pwm.h - API function protoypes for Pulse Width Modulation (PWM) ports
4 //
5 // Copyright (c) 2005-2017 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the
18 // distribution.
19 //
20 // Neither the name of Texas Instruments Incorporated nor the names of
21 // its contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 //*****************************************************************************
37 
38 #ifndef __DRIVERLIB_PWM_H__
39 #define __DRIVERLIB_PWM_H__
40 
41 #include <stdint.h>
42 #include <stdbool.h>
43 
44 //*****************************************************************************
45 //
46 // If building with a C++ compiler, make all of the definitions in this header
47 // have a C binding.
48 //
49 //*****************************************************************************
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54 
55 //*****************************************************************************
56 //
57 // The following defines are passed to PWMGenConfigure() as the ui32Config
58 // parameter and specify the configuration of the PWM generator.
59 //
60 //*****************************************************************************
61 #define PWM_GEN_MODE_DOWN 0x00000000 // Down count mode
62 #define PWM_GEN_MODE_UP_DOWN 0x00000002 // Up/Down count mode
63 #define PWM_GEN_MODE_SYNC 0x00000038 // Synchronous updates
64 #define PWM_GEN_MODE_NO_SYNC 0x00000000 // Immediate updates
65 #define PWM_GEN_MODE_DBG_RUN 0x00000004 // Continue running in debug mode
66 #define PWM_GEN_MODE_DBG_STOP 0x00000000 // Stop running in debug mode
67 #define PWM_GEN_MODE_FAULT_LATCHED \
68  0x00040000 // Fault is latched
69 #define PWM_GEN_MODE_FAULT_UNLATCHED \
70  0x00000000 // Fault is not latched
71 #define PWM_GEN_MODE_FAULT_MINPER \
72  0x00020000 // Enable min fault period
73 #define PWM_GEN_MODE_FAULT_NO_MINPER \
74  0x00000000 // Disable min fault period
75 #define PWM_GEN_MODE_FAULT_EXT 0x00010000 // Enable extended fault support
76 #define PWM_GEN_MODE_FAULT_LEGACY \
77  0x00000000 // Disable extended fault support
78 #define PWM_GEN_MODE_DB_NO_SYNC 0x00000000 // Deadband updates occur
79  // immediately
80 #define PWM_GEN_MODE_DB_SYNC_LOCAL \
81  0x0000A800 // Deadband updates locally
82  // synchronized
83 #define PWM_GEN_MODE_DB_SYNC_GLOBAL \
84  0x0000FC00 // Deadband updates globally
85  // synchronized
86 #define PWM_GEN_MODE_GEN_NO_SYNC \
87  0x00000000 // Generator mode updates occur
88  // immediately
89 #define PWM_GEN_MODE_GEN_SYNC_LOCAL \
90  0x00000280 // Generator mode updates locally
91  // synchronized
92 #define PWM_GEN_MODE_GEN_SYNC_GLOBAL \
93  0x000003C0 // Generator mode updates globally
94  // synchronized
95 
96 //*****************************************************************************
97 //
98 // Defines for enabling, disabling, and clearing PWM generator interrupts and
99 // triggers.
100 //
101 //*****************************************************************************
102 #define PWM_INT_CNT_ZERO 0x00000001 // Int if COUNT = 0
103 #define PWM_INT_CNT_LOAD 0x00000002 // Int if COUNT = LOAD
104 #define PWM_INT_CNT_AU 0x00000004 // Int if COUNT = CMPA U
105 #define PWM_INT_CNT_AD 0x00000008 // Int if COUNT = CMPA D
106 #define PWM_INT_CNT_BU 0x00000010 // Int if COUNT = CMPA U
107 #define PWM_INT_CNT_BD 0x00000020 // Int if COUNT = CMPA D
108 #define PWM_TR_CNT_ZERO 0x00000100 // Trig if COUNT = 0
109 #define PWM_TR_CNT_LOAD 0x00000200 // Trig if COUNT = LOAD
110 #define PWM_TR_CNT_AU 0x00000400 // Trig if COUNT = CMPA U
111 #define PWM_TR_CNT_AD 0x00000800 // Trig if COUNT = CMPA D
112 #define PWM_TR_CNT_BU 0x00001000 // Trig if COUNT = CMPA U
113 #define PWM_TR_CNT_BD 0x00002000 // Trig if COUNT = CMPA D
114 
115 //*****************************************************************************
116 //
117 // Defines for enabling, disabling, and clearing PWM interrupts.
118 //
119 //*****************************************************************************
120 #define PWM_INT_GEN_0 0x00000001 // Generator 0 interrupt
121 #define PWM_INT_GEN_1 0x00000002 // Generator 1 interrupt
122 #define PWM_INT_GEN_2 0x00000004 // Generator 2 interrupt
123 #define PWM_INT_GEN_3 0x00000008 // Generator 3 interrupt
124 #define PWM_INT_FAULT0 0x00010000 // Fault0 interrupt
125 #define PWM_INT_FAULT1 0x00020000 // Fault1 interrupt
126 #define PWM_INT_FAULT2 0x00040000 // Fault2 interrupt
127 #define PWM_INT_FAULT3 0x00080000 // Fault3 interrupt
128 #define PWM_INT_FAULT_M 0x000F0000 // Fault interrupt source mask
129 
130 //*****************************************************************************
131 //
132 // Defines to identify the generators within a module.
133 //
134 //*****************************************************************************
135 #define PWM_GEN_0 0x00000040 // Offset address of Gen0
136 #define PWM_GEN_1 0x00000080 // Offset address of Gen1
137 #define PWM_GEN_2 0x000000C0 // Offset address of Gen2
138 #define PWM_GEN_3 0x00000100 // Offset address of Gen3
139 
140 #define PWM_GEN_0_BIT 0x00000001 // Bit-wise ID for Gen0
141 #define PWM_GEN_1_BIT 0x00000002 // Bit-wise ID for Gen1
142 #define PWM_GEN_2_BIT 0x00000004 // Bit-wise ID for Gen2
143 #define PWM_GEN_3_BIT 0x00000008 // Bit-wise ID for Gen3
144 
145 #define PWM_GEN_EXT_0 0x00000800 // Offset of Gen0 ext address range
146 #define PWM_GEN_EXT_1 0x00000880 // Offset of Gen1 ext address range
147 #define PWM_GEN_EXT_2 0x00000900 // Offset of Gen2 ext address range
148 #define PWM_GEN_EXT_3 0x00000980 // Offset of Gen3 ext address range
149 
150 //*****************************************************************************
151 //
152 // Defines to identify the outputs within a module.
153 //
154 //*****************************************************************************
155 #define PWM_OUT_0 0x00000040 // Encoded offset address of PWM0
156 #define PWM_OUT_1 0x00000041 // Encoded offset address of PWM1
157 #define PWM_OUT_2 0x00000082 // Encoded offset address of PWM2
158 #define PWM_OUT_3 0x00000083 // Encoded offset address of PWM3
159 #define PWM_OUT_4 0x000000C4 // Encoded offset address of PWM4
160 #define PWM_OUT_5 0x000000C5 // Encoded offset address of PWM5
161 #define PWM_OUT_6 0x00000106 // Encoded offset address of PWM6
162 #define PWM_OUT_7 0x00000107 // Encoded offset address of PWM7
163 
164 #define PWM_OUT_0_BIT 0x00000001 // Bit-wise ID for PWM0
165 #define PWM_OUT_1_BIT 0x00000002 // Bit-wise ID for PWM1
166 #define PWM_OUT_2_BIT 0x00000004 // Bit-wise ID for PWM2
167 #define PWM_OUT_3_BIT 0x00000008 // Bit-wise ID for PWM3
168 #define PWM_OUT_4_BIT 0x00000010 // Bit-wise ID for PWM4
169 #define PWM_OUT_5_BIT 0x00000020 // Bit-wise ID for PWM5
170 #define PWM_OUT_6_BIT 0x00000040 // Bit-wise ID for PWM6
171 #define PWM_OUT_7_BIT 0x00000080 // Bit-wise ID for PWM7
172 
173 //*****************************************************************************
174 //
175 // Defines to identify each of the possible fault trigger conditions in
176 // PWM_FAULT_GROUP_0.
177 //
178 //*****************************************************************************
179 #define PWM_FAULT_GROUP_0 0
180 
181 #define PWM_FAULT_FAULT0 0x00000001
182 #define PWM_FAULT_FAULT1 0x00000002
183 #define PWM_FAULT_FAULT2 0x00000004
184 #define PWM_FAULT_FAULT3 0x00000008
185 #define PWM_FAULT_ACMP0 0x00010000
186 #define PWM_FAULT_ACMP1 0x00020000
187 #define PWM_FAULT_ACMP2 0x00040000
188 
189 //*****************************************************************************
190 //
191 // Defines to identify each of the possible fault trigger conditions in
192 // PWM_FAULT_GROUP_1.
193 //
194 //*****************************************************************************
195 #define PWM_FAULT_GROUP_1 1
196 
197 #define PWM_FAULT_DCMP0 0x00000001
198 #define PWM_FAULT_DCMP1 0x00000002
199 #define PWM_FAULT_DCMP2 0x00000004
200 #define PWM_FAULT_DCMP3 0x00000008
201 #define PWM_FAULT_DCMP4 0x00000010
202 #define PWM_FAULT_DCMP5 0x00000020
203 #define PWM_FAULT_DCMP6 0x00000040
204 #define PWM_FAULT_DCMP7 0x00000080
205 
206 //*****************************************************************************
207 //
208 // Defines to identify the sense of each of the external FAULTn signals
209 //
210 //*****************************************************************************
211 #define PWM_FAULT0_SENSE_HIGH 0x00000000
212 #define PWM_FAULT0_SENSE_LOW 0x00000001
213 #define PWM_FAULT1_SENSE_HIGH 0x00000000
214 #define PWM_FAULT1_SENSE_LOW 0x00000002
215 #define PWM_FAULT2_SENSE_HIGH 0x00000000
216 #define PWM_FAULT2_SENSE_LOW 0x00000004
217 #define PWM_FAULT3_SENSE_HIGH 0x00000000
218 #define PWM_FAULT3_SENSE_LOW 0x00000008
219 
220 //*****************************************************************************
221 //
222 // Defines that can be passed to the PWMClockSet() API as the ui32Config
223 // parameter, and can be returned by the PWMClockGet() API.
224 //
225 //*****************************************************************************
226 #define PWM_SYSCLK_DIV_1 0x00000000 // PWM clock is system clock
227 #define PWM_SYSCLK_DIV_2 0x00000100 // PWM clock is system clock /2
228 #define PWM_SYSCLK_DIV_4 0x00000101 // PWM clock is system clock /4
229 #define PWM_SYSCLK_DIV_8 0x00000102 // PWM clock is system clock /8
230 #define PWM_SYSCLK_DIV_16 0x00000103 // PWM clock is system clock /16
231 #define PWM_SYSCLK_DIV_32 0x00000104 // PWM clock is system clock /32
232 #define PWM_SYSCLK_DIV_64 0x00000105 // PWM clock is system clock /64
233 
234 //*****************************************************************************
235 //
236 // Defines passed to PWMOutputUpdateMode() to identify the synchronization mode
237 // to use when enabling or disabling outputs using PWMOutputState().
238 //
239 //*****************************************************************************
240 #define PWM_OUTPUT_MODE_NO_SYNC 0x00000000 // Updates to occur immediately
241 #define PWM_OUTPUT_MODE_SYNC_LOCAL \
242  0x00000002 // Updates are locally synchronized
243 #define PWM_OUTPUT_MODE_SYNC_GLOBAL \
244  0x00000003 // Updates are globally synchronized
245 
246 //*****************************************************************************
247 //
248 // API Function prototypes
249 //
250 //*****************************************************************************
251 extern void PWMGenConfigure(uint32_t ui32Base, uint32_t ui32Gen,
252  uint32_t ui32Config);
253 extern void PWMGenPeriodSet(uint32_t ui32Base, uint32_t ui32Gen,
254  uint32_t ui32Period);
255 extern uint32_t PWMGenPeriodGet(uint32_t ui32Base,
256  uint32_t ui32Gen);
257 extern void PWMGenEnable(uint32_t ui32Base, uint32_t ui32Gen);
258 extern void PWMGenDisable(uint32_t ui32Base, uint32_t ui32Gen);
259 extern void PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut,
260  uint32_t ui32Width);
261 extern uint32_t PWMPulseWidthGet(uint32_t ui32Base,
262  uint32_t ui32PWMOut);
263 extern void PWMDeadBandEnable(uint32_t ui32Base, uint32_t ui32Gen,
264  uint16_t ui16Rise, uint16_t ui16Fall);
265 extern void PWMDeadBandDisable(uint32_t ui32Base, uint32_t ui32Gen);
266 extern void PWMSyncUpdate(uint32_t ui32Base, uint32_t ui32GenBits);
267 extern void PWMSyncTimeBase(uint32_t ui32Base, uint32_t ui32GenBits);
268 extern void PWMOutputState(uint32_t ui32Base, uint32_t ui32PWMOutBits,
269  bool bEnable);
270 extern void PWMOutputInvert(uint32_t ui32Base, uint32_t ui32PWMOutBits,
271  bool bInvert);
272 extern void PWMOutputFaultLevel(uint32_t ui32Base,
273  uint32_t ui32PWMOutBits,
274  bool bDriveHigh);
275 extern void PWMOutputFault(uint32_t ui32Base, uint32_t ui32PWMOutBits,
276  bool bFaultSuppress);
277 extern void PWMGenIntRegister(uint32_t ui32Base, uint32_t ui32Gen,
278  void (*pfnIntHandler)(void));
279 extern void PWMGenIntUnregister(uint32_t ui32Base, uint32_t ui32Gen);
280 extern void PWMFaultIntRegister(uint32_t ui32Base,
281  void (*pfnIntHandler)(void));
282 extern void PWMFaultIntUnregister(uint32_t ui32Base);
283 extern void PWMGenIntTrigEnable(uint32_t ui32Base, uint32_t ui32Gen,
284  uint32_t ui32IntTrig);
285 extern void PWMGenIntTrigDisable(uint32_t ui32Base, uint32_t ui32Gen,
286  uint32_t ui32IntTrig);
287 extern uint32_t PWMGenIntStatus(uint32_t ui32Base, uint32_t ui32Gen,
288  bool bMasked);
289 extern void PWMGenIntClear(uint32_t ui32Base, uint32_t ui32Gen,
290  uint32_t ui32Ints);
291 extern void PWMIntEnable(uint32_t ui32Base, uint32_t ui32GenFault);
292 extern void PWMIntDisable(uint32_t ui32Base, uint32_t ui32GenFault);
293 extern uint32_t PWMIntStatus(uint32_t ui32Base, bool bMasked);
294 extern void PWMFaultIntClearExt(uint32_t ui32Base,
295  uint32_t ui32FaultInts);
296 extern void PWMGenFaultConfigure(uint32_t ui32Base, uint32_t ui32Gen,
297  uint32_t ui32MinFaultPeriod,
298  uint32_t ui32FaultSenses);
299 extern void PWMGenFaultTriggerSet(uint32_t ui32Base, uint32_t ui32Gen,
300  uint32_t ui32Group,
301  uint32_t ui32FaultTriggers);
302 extern uint32_t PWMGenFaultTriggerGet(uint32_t ui32Base,
303  uint32_t ui32Gen,
304  uint32_t ui32Group);
305 extern uint32_t PWMGenFaultStatus(uint32_t ui32Base,
306  uint32_t ui32Gen,
307  uint32_t ui32Group);
308 extern void PWMGenFaultClear(uint32_t ui32Base, uint32_t ui32Gen,
309  uint32_t ui32Group,
310  uint32_t ui32FaultTriggers);
311 extern void PWMClockSet(uint32_t ui32Base, uint32_t ui32Config);
312 extern uint32_t PWMClockGet(uint32_t ui32Base);
313 extern void PWMOutputUpdateMode(uint32_t ui32Base,
314  uint32_t ui32PWMOutBits,
315  uint32_t ui32Mode);
316 
317 //*****************************************************************************
318 //
319 // Mark the end of the C bindings section for C++ compilers.
320 //
321 //*****************************************************************************
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif // __DRIVERLIB_PWM_H__
uint32_t PWMPulseWidthGet(uint32_t ui32Base, uint32_t ui32PWMOut)
Definition: pwm.c:515
void PWMGenFaultClear(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Group, uint32_t ui32FaultTriggers)
Definition: pwm.c:1762
void PWMGenIntUnregister(uint32_t ui32Base, uint32_t ui32Gen)
Definition: pwm.c:1039
void PWMDeadBandDisable(uint32_t ui32Base, uint32_t ui32Gen)
Definition: pwm.c:621
void PWMOutputState(uint32_t ui32Base, uint32_t ui32PWMOutBits, bool bEnable)
Definition: pwm.c:723
void PWMFaultIntClearExt(uint32_t ui32Base, uint32_t ui32FaultInts)
Definition: pwm.c:1493
void PWMIntEnable(uint32_t ui32Base, uint32_t ui32GenFault)
Definition: pwm.c:1373
void PWMDeadBandEnable(uint32_t ui32Base, uint32_t ui32Gen, uint16_t ui16Rise, uint16_t ui16Fall)
Definition: pwm.c:578
void PWMFaultIntUnregister(uint32_t ui32Base)
Definition: pwm.c:1154
void PWMGenIntRegister(uint32_t ui32Base, uint32_t ui32Gen, void(*pfnIntHandler)(void))
Definition: pwm.c:989
uint32_t PWMGenFaultStatus(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Group)
Definition: pwm.c:1716
void PWMIntDisable(uint32_t ui32Base, uint32_t ui32GenFault)
Definition: pwm.c:1407
uint32_t PWMGenFaultTriggerGet(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Group)
Definition: pwm.c:1660
void PWMClockSet(uint32_t ui32Base, uint32_t ui32Config)
Definition: pwm.c:1819
void PWMGenFaultTriggerSet(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Group, uint32_t ui32FaultTriggers)
Definition: pwm.c:1600
void PWMGenFaultConfigure(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32MinFaultPeriod, uint32_t ui32FaultSenses)
Definition: pwm.c:1535
uint32_t PWMIntStatus(uint32_t ui32Base, bool bMasked)
Definition: pwm.c:1442
uint32_t PWMClockGet(uint32_t ui32Base)
Definition: pwm.c:1856
void PWMGenPeriodSet(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Period)
Definition: pwm.c:275
void PWMGenIntTrigEnable(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32IntTrig)
Definition: pwm.c:1202
void PWMOutputInvert(uint32_t ui32Base, uint32_t ui32PWMOutBits, bool bInvert)
Definition: pwm.c:771
void PWMOutputFault(uint32_t ui32Base, uint32_t ui32PWMOutBits, bool bFaultSuppress)
Definition: pwm.c:876
void PWMFaultIntRegister(uint32_t ui32Base, void(*pfnIntHandler)(void))
Definition: pwm.c:1110
void PWMSyncUpdate(uint32_t ui32Base, uint32_t ui32GenBits)
Definition: pwm.c:653
uint32_t PWMGenIntStatus(uint32_t ui32Base, uint32_t ui32Gen, bool bMasked)
Definition: pwm.c:1283
void PWMGenDisable(uint32_t ui32Base, uint32_t ui32Gen)
Definition: pwm.c:409
void PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut, uint32_t ui32Width)
Definition: pwm.c:444
void PWMSyncTimeBase(uint32_t ui32Base, uint32_t ui32GenBits)
Definition: pwm.c:685
void PWMOutputFaultLevel(uint32_t ui32Base, uint32_t ui32PWMOutBits, bool bDriveHigh)
Definition: pwm.c:824
void PWMGenIntTrigDisable(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32IntTrig)
Definition: pwm.c:1244
void PWMGenEnable(uint32_t ui32Base, uint32_t ui32Gen)
Definition: pwm.c:380
void PWMGenConfigure(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Config)
Definition: pwm.c:197
uint32_t PWMGenPeriodGet(uint32_t ui32Base, uint32_t ui32Gen)
Definition: pwm.c:333
void PWMGenIntClear(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Ints)
Definition: pwm.c:1338
void PWMOutputUpdateMode(uint32_t ui32Base, uint32_t ui32PWMOutBits, uint32_t ui32Mode)
Definition: pwm.c:1912
Copyright 2017, Texas Instruments Incorporated