DSP2803x_EPwm.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. //###########################################################################
  2. //
  3. // FILE: DSP2803x_EPwm.c
  4. //
  5. // TITLE: DSP2803x EPwm Initialization & Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  9. // $Release Date: May 8, 2015 $
  10. // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  11. // http://www.ti.com/ ALL RIGHTS RESERVED $
  12. //###########################################################################
  13. #include "DSP2803x_Device.h" // DSP2803x Headerfile Include File
  14. #include "DSP2803x_Examples.h" // DSP2803x Examples Include File
  15. //---------------------------------------------------------------------------
  16. // InitEPwm:
  17. //---------------------------------------------------------------------------
  18. // This function initializes the EPwm(s) to a known state.
  19. //
  20. void InitEPwm(void)
  21. {
  22. // Initialize EPwm1/2/3/4/5/6/7
  23. //tbd...
  24. }
  25. //---------------------------------------------------------------------------
  26. // Example: InitEPwmGpio:
  27. //---------------------------------------------------------------------------
  28. // This function initializes GPIO pins to function as EPwm pins
  29. //
  30. // Each GPIO pin can be configured as a GPIO pin or up to 3 different
  31. // peripheral functional pins. By default all pins come up as GPIO
  32. // inputs after reset.
  33. //
  34. void InitEPwmGpio(void)
  35. {
  36. InitEPwm1Gpio();
  37. InitEPwm2Gpio();
  38. InitEPwm3Gpio();
  39. #if DSP28_EPWM4
  40. InitEPwm4Gpio();
  41. #endif // endif DSP28_EPWM4
  42. #if DSP28_EPWM5
  43. InitEPwm5Gpio();
  44. #endif // endif DSP28_EPWM5
  45. #if DSP28_EPWM6
  46. InitEPwm6Gpio();
  47. #endif // endif DSP28_EPWM6
  48. #if DSP28_EPWM7
  49. InitEPwm7Gpio();
  50. #endif // endif DSP28_EPWM7
  51. }
  52. void InitEPwm1Gpio(void)
  53. {
  54. EALLOW;
  55. /* Disable internal pull-up for the selected output pins
  56. for reduced power consumption */
  57. // Pull-ups can be enabled or disabled by the user.
  58. // Comment out other unwanted lines.
  59. GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1; // Disable pull-up on GPIO0 (EPWM1A)
  60. GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1; // Disable pull-up on GPIO1 (EPWM1B)
  61. /* Configure EPWM-1 pins using GPIO regs*/
  62. // This specifies which of the possible GPIO pins will be EPWM1 functional pins.
  63. // Comment out other unwanted lines.
  64. GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Configure GPIO0 as EPWM1A
  65. GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Configure GPIO1 as EPWM1B
  66. EDIS;
  67. }
  68. void InitEPwm2Gpio(void)
  69. {
  70. EALLOW;
  71. /* Disable internal pull-up for the selected output pins
  72. for reduced power consumption */
  73. // Pull-ups can be enabled or disabled by the user.
  74. // This will enable the pullups for the specified pins.
  75. // Comment out other unwanted lines.
  76. GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1; // Disable pull-up on GPIO2 (EPWM2A)
  77. GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1; // Disable pull-up on GPIO3 (EPWM2B)
  78. /* Configure EPwm-2 pins using GPIO regs*/
  79. // This specifies which of the possible GPIO pins will be EPWM2 functional pins.
  80. // Comment out other unwanted lines.
  81. GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // Configure GPIO2 as EPWM2A
  82. GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1; // Configure GPIO3 as EPWM2B
  83. EDIS;
  84. }
  85. void InitEPwm3Gpio(void)
  86. {
  87. EALLOW;
  88. /* Disable internal pull-up for the selected output pins
  89. for reduced power consumption */
  90. // Pull-ups can be enabled or disabled by the user.
  91. // This will enable the pullups for the specified pins.
  92. // Comment out other unwanted lines.
  93. GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1; // Disable pull-up on GPIO4 (EPWM3A)
  94. GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1; // Disable pull-up on GPIO5 (EPWM3B)
  95. /* Configure EPwm-3 pins using GPIO regs*/
  96. // This specifies which of the possible GPIO pins will be EPWM3 functional pins.
  97. // Comment out other unwanted lines.
  98. GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1; // Configure GPIO4 as EPWM3A
  99. GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1; // Configure GPIO5 as EPWM3B
  100. EDIS;
  101. }
  102. #if DSP28_EPWM4
  103. void InitEPwm4Gpio(void)
  104. {
  105. EALLOW;
  106. /* Disable internal pull-up for the selected output pins
  107. for reduced power consumption */
  108. // Pull-ups can be enabled or disabled by the user.
  109. // This will enable the pullups for the specified pins.
  110. // Comment out other unwanted lines.
  111. GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1; // Disable pull-up on GPIO6 (EPWM4A)
  112. GpioCtrlRegs.GPAPUD.bit.GPIO7 = 1; // Disable pull-up on GPIO7 (EPWM4B)
  113. /* Configure EPWM-4 pins using GPIO regs*/
  114. // This specifies which of the possible GPIO pins will be EPWM4 functional pins.
  115. // Comment out other unwanted lines.
  116. GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 1; // Configure GPIO6 as EPWM4A
  117. GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 1; // Configure GPIO7 as EPWM4B
  118. EDIS;
  119. }
  120. #endif // endif DSP28_EPWM4
  121. #if DSP28_EPWM5
  122. void InitEPwm5Gpio(void)
  123. {
  124. EALLOW;
  125. /* Disable internal pull-up for the selected output pins
  126. for reduced power consumption */
  127. // Pull-ups can be enabled or disabled by the user.
  128. // This will enable the pullups for the specified pins.
  129. // Comment out other unwanted lines.
  130. GpioCtrlRegs.GPAPUD.bit.GPIO8 = 1; // Disable pull-up on GPIO8 (EPWM5A)
  131. GpioCtrlRegs.GPAPUD.bit.GPIO9 = 1; // Disable pull-up on GPIO9 (EPWM5B)
  132. /* Configure EPWM-5 pins using GPIO regs*/
  133. // This specifies which of the possible GPIO pins will be EPWM5 functional pins.
  134. // Comment out other unwanted lines.
  135. GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 1; // Configure GPIO8 as EPWM5A
  136. GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 1; // Configure GPIO9 as EPWM5B
  137. EDIS;
  138. }
  139. #endif // endif DSP28_EPWM5
  140. #if DSP28_EPWM6
  141. void InitEPwm6Gpio(void)
  142. {
  143. EALLOW;
  144. /* Disable internal pull-up for the selected output pins
  145. for reduced power consumption */
  146. // Pull-ups can be enabled or disabled by the user.
  147. // This will enable the pullups for the specified pins.
  148. // Comment out other unwanted lines.
  149. GpioCtrlRegs.GPAPUD.bit.GPIO10 = 1; // Disable pull-up on GPIO10 (EPWM6A)
  150. GpioCtrlRegs.GPAPUD.bit.GPIO11 = 1; // Disable pull-up on GPIO11 (EPWM6B)
  151. /* Configure EPWM-6 pins using GPIO regs*/
  152. // This specifies which of the possible GPIO pins will be EPWM6 functional pins.
  153. // Comment out other unwanted lines.
  154. GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 1; // Configure GPIO10 as EPWM6A
  155. GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 1; // Configure GPIO11 as EPWM6B
  156. EDIS;
  157. }
  158. #endif // endif DSP28_EPWM6
  159. #if DSP28_EPWM7
  160. void InitEPwm7Gpio(void)
  161. {
  162. EALLOW;
  163. /* Disable internal pull-up for the selected output pins
  164. for reduced power consumption */
  165. // Pull-ups can be enabled or disabled by the user.
  166. // This will enable the pullups for the specified pins.
  167. // Comment out other unwanted lines.
  168. GpioCtrlRegs.GPBPUD.bit.GPIO40 = 1; // Disable pull-up on GPIO40 (EPWM7A)
  169. GpioCtrlRegs.GPBPUD.bit.GPIO41 = 1; // Disable pull-up on GPIO41 (EPWM7B)
  170. /* Configure EPWM-7 pins using GPIO regs*/
  171. // This specifies which of the possible GPIO pins will be EPWM7 functional pins.
  172. // Comment out other unwanted lines.
  173. GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 1; // Configure GPIO40 as EPWM7A
  174. GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 1; // Configure GPIO41 as EPWM7B
  175. EDIS;
  176. }
  177. #endif // endif DSP28_EPWM7
  178. //---------------------------------------------------------------------------
  179. // Example: InitEPwmSyncGpio:
  180. //---------------------------------------------------------------------------
  181. // This function initializes GPIO pins to function as EPwm Synch pins
  182. //
  183. void InitEPwmSyncGpio(void)
  184. {
  185. // EALLOW;
  186. /* Configure EPWMSYNCI */
  187. /* Enable internal pull-up for the selected pins */
  188. // Pull-ups can be enabled or disabled by the user.
  189. // This will enable the pullups for the specified pins.
  190. // Comment out other unwanted lines.
  191. // GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0; // Enable pull-up on GPIO6 (EPWMSYNCI)
  192. GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pull-up on GPIO32 (EPWMSYNCI)
  193. /* Set qualification for selected pins to asynch only */
  194. // This will select synch to SYSCLKOUT for the selected pins.
  195. // Comment out other unwanted lines.
  196. // GpioCtrlRegs.GPAQSEL1.bit.GPIO6 = 0; // Synch to SYSCLKOUT GPIO6 (EPWMSYNCI)
  197. GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 0; // Synch to SYSCLKOUT GPIO32 (EPWMSYNCI)
  198. /* Configure EPwmSync pins using GPIO regs*/
  199. // This specifies which of the possible GPIO pins will be EPwmSync functional pins.
  200. // Comment out other unwanted lines.
  201. // GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 2; // Configures GPIO6 for EPWMSYNCI operation
  202. GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 2; // Configures GPIO32 for EPWMSYNCI operation.
  203. /* Configure EPWMSYNC0 */
  204. /* Disable internal pull-up for the selected output pins
  205. for reduced power consumption */
  206. // Pull-ups can be enabled or disabled by the user.
  207. // Comment out other unwanted lines.
  208. // GpioCtrlRegs.GPAPUD.bit.GPIO6 = 1; // Disable pull-up on GPIO6 (EPWMSYNCO)
  209. GpioCtrlRegs.GPBPUD.bit.GPIO33 = 1; // Disable pull-up on GPIO33 (EPWMSYNCO)
  210. // GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 3; // Configures GPIO6 for EPWMSYNCO
  211. GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 2; // Configures GPIO33 for EPWMSYNCO
  212. }
  213. //---------------------------------------------------------------------------
  214. // Example: InitTzGpio:
  215. //---------------------------------------------------------------------------
  216. // This function initializes GPIO pins to function as Trip Zone (TZ) pins
  217. //
  218. // Each GPIO pin can be configured as a GPIO pin or up to 3 different
  219. // peripheral functional pins. By default all pins come up as GPIO
  220. // inputs after reset.
  221. //
  222. void InitTzGpio(void)
  223. {
  224. EALLOW;
  225. /* Enable internal pull-up for the selected pins */
  226. // Pull-ups can be enabled or disabled by the user.
  227. // This will enable the pullups for the specified pins.
  228. // Comment out other unwanted lines.
  229. GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0; // Enable pull-up on GPIO12 (TZ1)
  230. // GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0; // Enable pull-up on GPIO15 (TZ1)
  231. GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0; // Enable pull-up on GPIO13 (TZ2)
  232. // GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; // Enable pull-up on GPIO16 (TZ2)
  233. // GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0; // Enable pull-up on GPIO28 (TZ2)
  234. GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0; // Enable pull-up on GPIO14 (TZ3)
  235. // GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up on GPIO17 (TZ3)
  236. // GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0; // Enable pull-up on GPIO29 (TZ3)
  237. /* Set qualification for selected pins to asynch only */
  238. // Inputs are synchronized to SYSCLKOUT by default.
  239. // This will select asynch (no qualification) for the selected pins.
  240. // Comment out other unwanted lines.
  241. GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3; // Asynch input GPIO12 (TZ1)
  242. // GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3; // Asynch input GPIO15 (TZ1)
  243. GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3; // Asynch input GPIO13 (TZ2)
  244. // GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (TZ2)
  245. // GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3; // Asynch input GPIO28 (TZ2)
  246. GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3; // Asynch input GPIO14 (TZ3)
  247. // GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (TZ3)
  248. // GpioCtrlRegs.GPAQSEL2.bit.GPIO29 = 3; // Asynch input GPIO29 (TZ3)
  249. /* Configure TZ pins using GPIO regs*/
  250. // This specifies which of the possible GPIO pins will be TZ functional pins.
  251. // Comment out other unwanted lines.
  252. GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 1; // Configure GPIO12 as TZ1
  253. // GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 1; // Configure GPIO15 as TZ1
  254. GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 1; // Configure GPIO13 as TZ2
  255. // GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 3; // Configure GPIO16 as TZ2
  256. // GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 3; // Configure GPIO28 as TZ2
  257. GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 1; // Configure GPIO14 as TZ3
  258. // GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 3; // Configure GPIO17 as TZ3
  259. // GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 3; // Configure GPIO29 as TZ3
  260. EDIS;
  261. }
  262. //===========================================================================
  263. // End of file.
  264. //===========================================================================