Fork from bluejay at github and modified for my custom ESC. I need to modify it because some mistake design on my ESC hardware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
5.7 KiB

  1. ;**** **** **** **** ****
  2. ;
  3. ; Bluejay digital ESC firmware for controlling brushless motors in multirotors
  4. ;
  5. ; Copyright 2020 Mathias Rasmussen
  6. ; Copyright 2011, 2012 Steffen Skaug
  7. ;
  8. ; This file is part of Bluejay.
  9. ;
  10. ; Bluejay is free software: you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation, either version 3 of the License, or
  13. ; (at your option) any later version.
  14. ;
  15. ; Bluejay is distributed in the hope that it will be useful,
  16. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ; GNU General Public License for more details.
  19. ;
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with Bluejay. If not, see <http://www.gnu.org/licenses/>.
  22. ;
  23. ;**** **** **** **** ****
  24. ;
  25. ; Hardware definition file "M".
  26. ; MA MC CC MB RC L0 X X X Cc Bc Ac Cp Bp Ap X
  27. ;
  28. ;**** **** **** **** ****
  29. TEMP_LIMIT EQU 49 ; Temperature measurement ADC value for which main motor power is limited at 80degC (low byte, assuming high byte is 1)
  30. TEMP_LIMIT_STEP EQU 9 ; Temperature measurement ADC value increment for another 10degC
  31. ;**** **** **** **** ****
  32. ; Bootloader definitions
  33. ;**** **** **** **** ****
  34. RTX_PORT EQU P0 ; Receive/Transmit port
  35. RTX_MDOUT EQU P0MDOUT ; Set to 1 for PUSHPULL
  36. RTX_MDIN EQU P0MDIN ; Set to 1 for DIGITAL
  37. RTX_SKIP EQU P0SKIP ; Set to 1 for SKIP
  38. RTX_PIN EQU 3 ; RTX pin
  39. SIGNATURE_001 EQU 0E8h ; Device signature
  40. IF MCU_48MHZ == 0
  41. SIGNATURE_002 EQU 0B1h
  42. ELSE
  43. SIGNATURE_002 EQU 0B2h
  44. ENDIF
  45. ;*********************
  46. ; PORT 0 definitions *
  47. ;*********************
  48. Mux_A EQU 7 ;i
  49. Mux_C EQU 6 ;i
  50. Comp_Com EQU 5 ;i
  51. Mux_B EQU 4 ;i
  52. Rcp_In EQU 3 ;i
  53. LED_0 EQU 2 ;i
  54. ; EQU 1 ;i
  55. ; EQU 0 ;i
  56. P0_DIGITAL EQU NOT((1 SHL Mux_A)+(1 SHL Mux_B)+(1 SHL Mux_C)+(1 SHL Comp_Com))
  57. P0_INIT EQU NOT(1 SHL LED_0)
  58. P0_PUSHPULL EQU (1 SHL LED_0)
  59. P0_SKIP EQU 0FFh
  60. Set_Pwm_Polarity MACRO
  61. mov PCA0POL, #02h ; Damping inverted, pwm noninverted
  62. ENDM
  63. IF FETON_DELAY == 0
  64. PCA0_POWER_MODULE EQU PCA0CPM0
  65. PCA0_POWER_L EQU PCA0CPL0
  66. PCA0_POWER_H EQU PCA0CPH0
  67. PCA0_DAMP_MODULE EQU PCA0CPM1
  68. PCA0_DAMP_L EQU PCA0CPL1
  69. PCA0_DAMP_H EQU PCA0CPH1
  70. ELSE
  71. PCA0_POWER_MODULE EQU PCA0CPM0
  72. PCA0_POWER_L EQU PCA0CPL0
  73. PCA0_POWER_H EQU PCA0CPH0
  74. PCA0_DAMP_MODULE EQU PCA0CPM1
  75. PCA0_DAMP_L EQU PCA0CPL1
  76. PCA0_DAMP_H EQU PCA0CPH1
  77. ENDIF
  78. ;*********************
  79. ; PORT 1 definitions *
  80. ;*********************
  81. ; EQU 7 ;i
  82. CcomFET EQU 6 ;o
  83. BcomFET EQU 5 ;o
  84. AcomFET EQU 4 ;o
  85. CpwmFET EQU 3 ;i
  86. BpwmFET EQU 2 ;o
  87. ApwmFET EQU 1 ;o
  88. ; EQU 0 ;o
  89. P1_DIGITAL EQU (1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET)+(1 SHL AcomFET)+(1 SHL BcomFET)+(1 SHL CcomFET)
  90. P1_INIT EQU 00h
  91. P1_PUSHPULL EQU (1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET)+(1 SHL AcomFET)+(1 SHL BcomFET)+(1 SHL CcomFET)
  92. P1_SKIP EQU 7Fh
  93. ApwmFET_on MACRO
  94. setb P1.ApwmFET
  95. IF FETON_DELAY == 0
  96. setb P1.AcomFET
  97. ENDIF
  98. ENDM
  99. ApwmFET_off MACRO
  100. IF FETON_DELAY != 0
  101. clr P1.ApwmFET
  102. ELSE
  103. clr P1.AcomFET
  104. ENDIF
  105. ENDM
  106. BpwmFET_on MACRO
  107. setb P1.BpwmFET
  108. IF FETON_DELAY == 0
  109. setb P1.BcomFET
  110. ENDIF
  111. ENDM
  112. BpwmFET_off MACRO
  113. IF FETON_DELAY != 0
  114. clr P1.BpwmFET
  115. ELSE
  116. clr P1.BcomFET
  117. ENDIF
  118. ENDM
  119. CpwmFET_on MACRO
  120. setb P1.CpwmFET
  121. IF FETON_DELAY == 0
  122. setb P1.CcomFET
  123. ENDIF
  124. ENDM
  125. CpwmFET_off MACRO
  126. IF FETON_DELAY != 0
  127. clr P1.CpwmFET
  128. ELSE
  129. clr P1.CcomFET
  130. ENDIF
  131. ENDM
  132. All_pwmFETs_Off MACRO
  133. IF FETON_DELAY != 0
  134. clr P1.ApwmFET
  135. clr P1.BpwmFET
  136. clr P1.CpwmFET
  137. ELSE
  138. clr P1.AcomFET
  139. clr P1.BcomFET
  140. clr P1.CcomFET
  141. ENDIF
  142. ENDM
  143. AcomFET_on MACRO
  144. IF FETON_DELAY == 0
  145. clr P1.ApwmFET
  146. ENDIF
  147. setb P1.AcomFET
  148. ENDM
  149. AcomFET_off MACRO
  150. clr P1.AcomFET
  151. ENDM
  152. BcomFET_on MACRO
  153. IF FETON_DELAY == 0
  154. clr P1.BpwmFET
  155. ENDIF
  156. setb P1.BcomFET
  157. ENDM
  158. BcomFET_off MACRO
  159. clr P1.BcomFET
  160. ENDM
  161. CcomFET_on MACRO
  162. IF FETON_DELAY == 0
  163. clr P1.CpwmFET
  164. ENDIF
  165. setb P1.CcomFET
  166. ENDM
  167. CcomFET_off MACRO
  168. clr P1.CcomFET
  169. ENDM
  170. All_comFETs_Off MACRO
  171. clr P1.AcomFET
  172. clr P1.BcomFET
  173. clr P1.CcomFET
  174. ENDM
  175. Set_Pwm_A MACRO
  176. IF FETON_DELAY == 0
  177. setb P1.AcomFET
  178. mov P1SKIP, #7Dh
  179. ELSE
  180. mov P1SKIP, #6Dh
  181. ENDIF
  182. ENDM
  183. Set_Pwm_B MACRO
  184. IF FETON_DELAY == 0
  185. setb P1.BcomFET
  186. mov P1SKIP, #7Bh
  187. ELSE
  188. mov P1SKIP, #5Bh
  189. ENDIF
  190. ENDM
  191. Set_Pwm_C MACRO
  192. IF FETON_DELAY == 0
  193. setb P1.CcomFET
  194. mov P1SKIP, #77h
  195. ELSE
  196. mov P1SKIP, #37h
  197. ENDIF
  198. ENDM
  199. Set_Pwms_Off MACRO
  200. mov P1SKIP, #7Fh
  201. ENDM
  202. Set_Comp_Phase_A MACRO
  203. mov CMP0MX, #75h ; Set comparator multiplexer to phase A
  204. ENDM
  205. Set_Comp_Phase_B MACRO
  206. mov CMP0MX, #45h ; Set comparator multiplexer to phase B
  207. ENDM
  208. Set_Comp_Phase_C MACRO
  209. mov CMP0MX, #65h ; Set comparator multiplexer to phase C
  210. ENDM
  211. Read_Comp_Out MACRO
  212. mov A, CMP0CN0 ; Read comparator output
  213. ENDM
  214. ;*********************
  215. ; PORT 2 definitions *
  216. ;*********************
  217. DebugPin EQU 0 ;o
  218. P2_PUSHPULL EQU (1 SHL DebugPin)
  219. ;**********************
  220. ; MCU specific macros *
  221. ;**********************
  222. Initialize_Xbar MACRO
  223. mov XBR2, #40h ; Xbar enabled
  224. mov XBR1, #02h ; CEX0 and CEX1 routed to pins
  225. ENDM
  226. Initialize_Comparator MACRO
  227. mov CMP0CN0, #80h ; Comparator enabled, no hysteresis
  228. mov CMP0MD, #00h ; Comparator response time 100ns
  229. ENDM
  230. Initialize_Adc MACRO
  231. mov REF0CN, #0Ch ; Set vdd (3.3V) as reference. Enable temp sensor and bias
  232. IF MCU_48MHZ == 0
  233. mov ADC0CF, #59h ; ADC clock 2MHz, PGA gain 1
  234. ELSE
  235. mov ADC0CF, #0B9h ; ADC clock 2MHz, PGA gain 1
  236. ENDIF
  237. mov ADC0MX, #10h ; Select temp sensor input
  238. mov ADC0CN0, #80h ; ADC enabled
  239. mov ADC0CN1, #01h ; Common mode buffer enabled
  240. ENDM
  241. Start_Adc MACRO
  242. mov ADC0CN0, #90h ; ADC start
  243. ENDM
  244. Read_Adc_Result MACRO
  245. mov Temp1, ADC0L
  246. mov Temp2, ADC0H
  247. ENDM
  248. Stop_Adc MACRO
  249. ENDM
  250. Set_RPM_Out MACRO
  251. ENDM
  252. Clear_RPM_Out MACRO
  253. ENDM
  254. Set_LED_0 MACRO
  255. setb P0.LED_0
  256. ENDM
  257. Clear_LED_0 MACRO
  258. clr P0.LED_0
  259. ENDM
  260. Set_LED_1 MACRO
  261. ENDM
  262. Clear_LED_1 MACRO
  263. ENDM
  264. Set_LED_2 MACRO
  265. ENDM
  266. Clear_LED_2 MACRO
  267. ENDM
  268. Set_LED_3 MACRO
  269. ENDM
  270. Clear_LED_3 MACRO
  271. ENDM