1
0

pwm.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. //*****************************************************************************
  2. //
  3. // pwm.h - API function protoypes for Pulse Width Modulation (PWM) ports
  4. //
  5. // Copyright (c) 2005-2014 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. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. #ifndef __DRIVERLIB_PWM_H__
  40. #define __DRIVERLIB_PWM_H__
  41. //*****************************************************************************
  42. //
  43. // If building with a C++ compiler, make all of the definitions in this header
  44. // have a C binding.
  45. //
  46. //*****************************************************************************
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif
  51. //*****************************************************************************
  52. //
  53. // The following defines are passed to PWMGenConfigure() as the ui32Config
  54. // parameter and specify the configuration of the PWM generator.
  55. //
  56. //*****************************************************************************
  57. #define PWM_GEN_MODE_DOWN 0x00000000 // Down count mode
  58. #define PWM_GEN_MODE_UP_DOWN 0x00000002 // Up/Down count mode
  59. #define PWM_GEN_MODE_SYNC 0x00000038 // Synchronous updates
  60. #define PWM_GEN_MODE_NO_SYNC 0x00000000 // Immediate updates
  61. #define PWM_GEN_MODE_DBG_RUN 0x00000004 // Continue running in debug mode
  62. #define PWM_GEN_MODE_DBG_STOP 0x00000000 // Stop running in debug mode
  63. #define PWM_GEN_MODE_FAULT_LATCHED \
  64. 0x00040000 // Fault is latched
  65. #define PWM_GEN_MODE_FAULT_UNLATCHED \
  66. 0x00000000 // Fault is not latched
  67. #define PWM_GEN_MODE_FAULT_MINPER \
  68. 0x00020000 // Enable min fault period
  69. #define PWM_GEN_MODE_FAULT_NO_MINPER \
  70. 0x00000000 // Disable min fault period
  71. #define PWM_GEN_MODE_FAULT_EXT 0x00010000 // Enable extended fault support
  72. #define PWM_GEN_MODE_FAULT_LEGACY \
  73. 0x00000000 // Disable extended fault support
  74. #define PWM_GEN_MODE_DB_NO_SYNC 0x00000000 // Deadband updates occur
  75. // immediately
  76. #define PWM_GEN_MODE_DB_SYNC_LOCAL \
  77. 0x0000A800 // Deadband updates locally
  78. // synchronized
  79. #define PWM_GEN_MODE_DB_SYNC_GLOBAL \
  80. 0x0000FC00 // Deadband updates globally
  81. // synchronized
  82. #define PWM_GEN_MODE_GEN_NO_SYNC \
  83. 0x00000000 // Generator mode updates occur
  84. // immediately
  85. #define PWM_GEN_MODE_GEN_SYNC_LOCAL \
  86. 0x00000280 // Generator mode updates locally
  87. // synchronized
  88. #define PWM_GEN_MODE_GEN_SYNC_GLOBAL \
  89. 0x000003C0 // Generator mode updates globally
  90. // synchronized
  91. //*****************************************************************************
  92. //
  93. // Defines for enabling, disabling, and clearing PWM generator interrupts and
  94. // triggers.
  95. //
  96. //*****************************************************************************
  97. #define PWM_INT_CNT_ZERO 0x00000001 // Int if COUNT = 0
  98. #define PWM_INT_CNT_LOAD 0x00000002 // Int if COUNT = LOAD
  99. #define PWM_INT_CNT_AU 0x00000004 // Int if COUNT = CMPA U
  100. #define PWM_INT_CNT_AD 0x00000008 // Int if COUNT = CMPA D
  101. #define PWM_INT_CNT_BU 0x00000010 // Int if COUNT = CMPA U
  102. #define PWM_INT_CNT_BD 0x00000020 // Int if COUNT = CMPA D
  103. #define PWM_TR_CNT_ZERO 0x00000100 // Trig if COUNT = 0
  104. #define PWM_TR_CNT_LOAD 0x00000200 // Trig if COUNT = LOAD
  105. #define PWM_TR_CNT_AU 0x00000400 // Trig if COUNT = CMPA U
  106. #define PWM_TR_CNT_AD 0x00000800 // Trig if COUNT = CMPA D
  107. #define PWM_TR_CNT_BU 0x00001000 // Trig if COUNT = CMPA U
  108. #define PWM_TR_CNT_BD 0x00002000 // Trig if COUNT = CMPA D
  109. //*****************************************************************************
  110. //
  111. // Defines for enabling, disabling, and clearing PWM interrupts.
  112. //
  113. //*****************************************************************************
  114. #define PWM_INT_GEN_0 0x00000001 // Generator 0 interrupt
  115. #define PWM_INT_GEN_1 0x00000002 // Generator 1 interrupt
  116. #define PWM_INT_GEN_2 0x00000004 // Generator 2 interrupt
  117. #define PWM_INT_GEN_3 0x00000008 // Generator 3 interrupt
  118. #define PWM_INT_FAULT0 0x00010000 // Fault0 interrupt
  119. #define PWM_INT_FAULT1 0x00020000 // Fault1 interrupt
  120. #define PWM_INT_FAULT2 0x00040000 // Fault2 interrupt
  121. #define PWM_INT_FAULT3 0x00080000 // Fault3 interrupt
  122. #define PWM_INT_FAULT_M 0x000F0000 // Fault interrupt source mask
  123. //*****************************************************************************
  124. //
  125. // Defines to identify the generators within a module.
  126. //
  127. //*****************************************************************************
  128. #define PWM_GEN_0 0x00000040 // Offset address of Gen0
  129. #define PWM_GEN_1 0x00000080 // Offset address of Gen1
  130. #define PWM_GEN_2 0x000000C0 // Offset address of Gen2
  131. #define PWM_GEN_3 0x00000100 // Offset address of Gen3
  132. #define PWM_GEN_0_BIT 0x00000001 // Bit-wise ID for Gen0
  133. #define PWM_GEN_1_BIT 0x00000002 // Bit-wise ID for Gen1
  134. #define PWM_GEN_2_BIT 0x00000004 // Bit-wise ID for Gen2
  135. #define PWM_GEN_3_BIT 0x00000008 // Bit-wise ID for Gen3
  136. #define PWM_GEN_EXT_0 0x00000800 // Offset of Gen0 ext address range
  137. #define PWM_GEN_EXT_1 0x00000880 // Offset of Gen1 ext address range
  138. #define PWM_GEN_EXT_2 0x00000900 // Offset of Gen2 ext address range
  139. #define PWM_GEN_EXT_3 0x00000980 // Offset of Gen3 ext address range
  140. //*****************************************************************************
  141. //
  142. // Defines to identify the outputs within a module.
  143. //
  144. //*****************************************************************************
  145. #define PWM_OUT_0 0x00000040 // Encoded offset address of PWM0
  146. #define PWM_OUT_1 0x00000041 // Encoded offset address of PWM1
  147. #define PWM_OUT_2 0x00000082 // Encoded offset address of PWM2
  148. #define PWM_OUT_3 0x00000083 // Encoded offset address of PWM3
  149. #define PWM_OUT_4 0x000000C4 // Encoded offset address of PWM4
  150. #define PWM_OUT_5 0x000000C5 // Encoded offset address of PWM5
  151. #define PWM_OUT_6 0x00000106 // Encoded offset address of PWM6
  152. #define PWM_OUT_7 0x00000107 // Encoded offset address of PWM7
  153. #define PWM_OUT_0_BIT 0x00000001 // Bit-wise ID for PWM0
  154. #define PWM_OUT_1_BIT 0x00000002 // Bit-wise ID for PWM1
  155. #define PWM_OUT_2_BIT 0x00000004 // Bit-wise ID for PWM2
  156. #define PWM_OUT_3_BIT 0x00000008 // Bit-wise ID for PWM3
  157. #define PWM_OUT_4_BIT 0x00000010 // Bit-wise ID for PWM4
  158. #define PWM_OUT_5_BIT 0x00000020 // Bit-wise ID for PWM5
  159. #define PWM_OUT_6_BIT 0x00000040 // Bit-wise ID for PWM6
  160. #define PWM_OUT_7_BIT 0x00000080 // Bit-wise ID for PWM7
  161. //*****************************************************************************
  162. //
  163. // Defines to identify each of the possible fault trigger conditions in
  164. // PWM_FAULT_GROUP_0.
  165. //
  166. //*****************************************************************************
  167. #define PWM_FAULT_GROUP_0 0
  168. #define PWM_FAULT_FAULT0 0x00000001
  169. #define PWM_FAULT_FAULT1 0x00000002
  170. #define PWM_FAULT_FAULT2 0x00000004
  171. #define PWM_FAULT_FAULT3 0x00000008
  172. #define PWM_FAULT_ACMP0 0x00010000
  173. #define PWM_FAULT_ACMP1 0x00020000
  174. #define PWM_FAULT_ACMP2 0x00040000
  175. //*****************************************************************************
  176. //
  177. // Defines to identify each of the possible fault trigger conditions in
  178. // PWM_FAULT_GROUP_1.
  179. //
  180. //*****************************************************************************
  181. #define PWM_FAULT_GROUP_1 1
  182. #define PWM_FAULT_DCMP0 0x00000001
  183. #define PWM_FAULT_DCMP1 0x00000002
  184. #define PWM_FAULT_DCMP2 0x00000004
  185. #define PWM_FAULT_DCMP3 0x00000008
  186. #define PWM_FAULT_DCMP4 0x00000010
  187. #define PWM_FAULT_DCMP5 0x00000020
  188. #define PWM_FAULT_DCMP6 0x00000040
  189. #define PWM_FAULT_DCMP7 0x00000080
  190. //*****************************************************************************
  191. //
  192. // Defines to identify the sense of each of the external FAULTn signals
  193. //
  194. //*****************************************************************************
  195. #define PWM_FAULT0_SENSE_HIGH 0x00000000
  196. #define PWM_FAULT0_SENSE_LOW 0x00000001
  197. #define PWM_FAULT1_SENSE_HIGH 0x00000000
  198. #define PWM_FAULT1_SENSE_LOW 0x00000002
  199. #define PWM_FAULT2_SENSE_HIGH 0x00000000
  200. #define PWM_FAULT2_SENSE_LOW 0x00000004
  201. #define PWM_FAULT3_SENSE_HIGH 0x00000000
  202. #define PWM_FAULT3_SENSE_LOW 0x00000008
  203. //*****************************************************************************
  204. //
  205. // Defines that can be passed to the PWMClockSet() API as the ui32Config
  206. // parameter, and can be returned by the PWMClockGet() API.
  207. //
  208. //*****************************************************************************
  209. #define PWM_SYSCLK_DIV_1 0x00000000 // PWM clock is system clock
  210. #define PWM_SYSCLK_DIV_2 0x00000100 // PWM clock is system clock /2
  211. #define PWM_SYSCLK_DIV_4 0x00000101 // PWM clock is system clock /4
  212. #define PWM_SYSCLK_DIV_8 0x00000102 // PWM clock is system clock /8
  213. #define PWM_SYSCLK_DIV_16 0x00000103 // PWM clock is system clock /16
  214. #define PWM_SYSCLK_DIV_32 0x00000104 // PWM clock is system clock /32
  215. #define PWM_SYSCLK_DIV_64 0x00000105 // PWM clock is system clock /64
  216. //*****************************************************************************
  217. //
  218. // Defines passed to PWMOutputUpdateMode() to identify the synchronization mode
  219. // to use when enabling or disabling outputs using PWMOutputState().
  220. //
  221. //*****************************************************************************
  222. #define PWM_OUTPUT_MODE_NO_SYNC 0x00000000 // Updates to occur immediately
  223. #define PWM_OUTPUT_MODE_SYNC_LOCAL \
  224. 0x00000002 // Updates are locally synchronized
  225. #define PWM_OUTPUT_MODE_SYNC_GLOBAL \
  226. 0x00000003 // Updates are globally synchronized
  227. //*****************************************************************************
  228. //
  229. // API Function prototypes
  230. //
  231. //*****************************************************************************
  232. extern void PWMGenConfigure(uint32_t ui32Base, uint32_t ui32Gen,
  233. uint32_t ui32Config);
  234. extern void PWMGenPeriodSet(uint32_t ui32Base, uint32_t ui32Gen,
  235. uint32_t ui32Period);
  236. extern uint32_t PWMGenPeriodGet(uint32_t ui32Base,
  237. uint32_t ui32Gen);
  238. extern void PWMGenEnable(uint32_t ui32Base, uint32_t ui32Gen);
  239. extern void PWMGenDisable(uint32_t ui32Base, uint32_t ui32Gen);
  240. extern void PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut,
  241. uint32_t ui32Width);
  242. extern uint32_t PWMPulseWidthGet(uint32_t ui32Base,
  243. uint32_t ui32PWMOut);
  244. extern void PWMDeadBandEnable(uint32_t ui32Base, uint32_t ui32Gen,
  245. uint16_t ui16Rise, uint16_t ui16Fall);
  246. extern void PWMDeadBandDisable(uint32_t ui32Base, uint32_t ui32Gen);
  247. extern void PWMSyncUpdate(uint32_t ui32Base, uint32_t ui32GenBits);
  248. extern void PWMSyncTimeBase(uint32_t ui32Base, uint32_t ui32GenBits);
  249. extern void PWMOutputState(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  250. bool bEnable);
  251. extern void PWMOutputInvert(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  252. bool bInvert);
  253. extern void PWMOutputFaultLevel(uint32_t ui32Base,
  254. uint32_t ui32PWMOutBits,
  255. bool bDriveHigh);
  256. extern void PWMOutputFault(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  257. bool bFaultSuppress);
  258. extern void PWMGenIntRegister(uint32_t ui32Base, uint32_t ui32Gen,
  259. void (*pfnIntHandler)(void));
  260. extern void PWMGenIntUnregister(uint32_t ui32Base, uint32_t ui32Gen);
  261. extern void PWMFaultIntRegister(uint32_t ui32Base,
  262. void (*pfnIntHandler)(void));
  263. extern void PWMFaultIntUnregister(uint32_t ui32Base);
  264. extern void PWMGenIntTrigEnable(uint32_t ui32Base, uint32_t ui32Gen,
  265. uint32_t ui32IntTrig);
  266. extern void PWMGenIntTrigDisable(uint32_t ui32Base, uint32_t ui32Gen,
  267. uint32_t ui32IntTrig);
  268. extern uint32_t PWMGenIntStatus(uint32_t ui32Base, uint32_t ui32Gen,
  269. bool bMasked);
  270. extern void PWMGenIntClear(uint32_t ui32Base, uint32_t ui32Gen,
  271. uint32_t ui32Ints);
  272. extern void PWMIntEnable(uint32_t ui32Base, uint32_t ui32GenFault);
  273. extern void PWMIntDisable(uint32_t ui32Base, uint32_t ui32GenFault);
  274. extern void PWMFaultIntClear(uint32_t ui32Base);
  275. extern uint32_t PWMIntStatus(uint32_t ui32Base, bool bMasked);
  276. extern void PWMFaultIntClearExt(uint32_t ui32Base,
  277. uint32_t ui32FaultInts);
  278. extern void PWMGenFaultConfigure(uint32_t ui32Base, uint32_t ui32Gen,
  279. uint32_t ui32MinFaultPeriod,
  280. uint32_t ui32FaultSenses);
  281. extern void PWMGenFaultTriggerSet(uint32_t ui32Base, uint32_t ui32Gen,
  282. uint32_t ui32Group,
  283. uint32_t ui32FaultTriggers);
  284. extern uint32_t PWMGenFaultTriggerGet(uint32_t ui32Base,
  285. uint32_t ui32Gen,
  286. uint32_t ui32Group);
  287. extern uint32_t PWMGenFaultStatus(uint32_t ui32Base,
  288. uint32_t ui32Gen,
  289. uint32_t ui32Group);
  290. extern void PWMGenFaultClear(uint32_t ui32Base, uint32_t ui32Gen,
  291. uint32_t ui32Group,
  292. uint32_t ui32FaultTriggers);
  293. extern void PWMClockSet(uint32_t ui32Base, uint32_t ui32Config);
  294. extern uint32_t PWMClockGet(uint32_t ui32Base);
  295. extern void PWMOutputUpdateMode(uint32_t ui32Base,
  296. uint32_t ui32PWMOutBits,
  297. uint32_t ui32Mode);
  298. //*****************************************************************************
  299. //
  300. // Mark the end of the C bindings section for C++ compilers.
  301. //
  302. //*****************************************************************************
  303. #ifdef __cplusplus
  304. }
  305. #endif
  306. #endif // __DRIVERLIB_PWM_H__