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.

295 lines
5.8 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 "B". Equals "A", but with A and C fets swapped and pwm and com fets swapped
  26. ; X X RC X MC MB MA CC X X Ap Ac Bp Bc Cp Cc
  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 5 ; 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. ; EQU 7 ;i
  49. ; EQU 6 ;i
  50. Rcp_In EQU 5 ;i
  51. ; EQU 4 ;i
  52. Mux_C EQU 3 ;i
  53. Mux_B EQU 2 ;i
  54. Mux_A EQU 1 ;i
  55. Comp_Com 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 0FFh
  58. P0_PUSHPULL EQU 0
  59. P0_SKIP EQU 0FFh
  60. Set_Pwm_Polarity MACRO
  61. IF FETON_DELAY == 0
  62. mov PCA0POL, #00h ; Pwm noninverted
  63. ELSE
  64. mov PCA0POL, #01h ; Damping inverted, pwm noninverted
  65. ENDIF
  66. ENDM
  67. IF FETON_DELAY == 0
  68. PCA0_POWER_MODULE EQU PCA0CPM0
  69. PCA0_POWER_L EQU PCA0CPL0
  70. PCA0_POWER_H EQU PCA0CPH0
  71. PCA0_DAMP_MODULE EQU PCA0CPM1
  72. PCA0_DAMP_L EQU PCA0CPL1
  73. PCA0_DAMP_H EQU PCA0CPH1
  74. ELSE
  75. PCA0_POWER_MODULE EQU PCA0CPM1
  76. PCA0_POWER_L EQU PCA0CPL1
  77. PCA0_POWER_H EQU PCA0CPH1
  78. PCA0_DAMP_MODULE EQU PCA0CPM0
  79. PCA0_DAMP_L EQU PCA0CPL0
  80. PCA0_DAMP_H EQU PCA0CPH0
  81. ENDIF
  82. ;*********************
  83. ; PORT 1 definitions *
  84. ;*********************
  85. ; EQU 7 ;i
  86. ; EQU 6 ;i
  87. ApwmFET EQU 5 ;o
  88. AcomFET EQU 4 ;o
  89. BpwmFET EQU 3 ;o
  90. BcomFET EQU 2 ;o
  91. CpwmFET EQU 1 ;o
  92. CcomFET EQU 0 ;o
  93. P1_DIGITAL EQU (1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET)+(1 SHL AcomFET)+(1 SHL BcomFET)+(1 SHL CcomFET)
  94. P1_INIT EQU 00h
  95. P1_PUSHPULL EQU (1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET)+(1 SHL AcomFET)+(1 SHL BcomFET)+(1 SHL CcomFET)
  96. P1_SKIP EQU 3Fh
  97. ApwmFET_on MACRO
  98. setb P1.ApwmFET
  99. IF FETON_DELAY == 0
  100. setb P1.AcomFET
  101. ENDIF
  102. ENDM
  103. ApwmFET_off MACRO
  104. IF FETON_DELAY != 0
  105. clr P1.ApwmFET
  106. ELSE
  107. clr P1.AcomFET
  108. ENDIF
  109. ENDM
  110. BpwmFET_on MACRO
  111. setb P1.BpwmFET
  112. IF FETON_DELAY == 0
  113. setb P1.BcomFET
  114. ENDIF
  115. ENDM
  116. BpwmFET_off MACRO
  117. IF FETON_DELAY != 0
  118. clr P1.BpwmFET
  119. ELSE
  120. clr P1.BcomFET
  121. ENDIF
  122. ENDM
  123. CpwmFET_on MACRO
  124. setb P1.CpwmFET
  125. IF FETON_DELAY == 0
  126. setb P1.CcomFET
  127. ENDIF
  128. ENDM
  129. CpwmFET_off MACRO
  130. IF FETON_DELAY != 0
  131. clr P1.CpwmFET
  132. ELSE
  133. clr P1.CcomFET
  134. ENDIF
  135. ENDM
  136. All_pwmFETs_Off MACRO
  137. IF FETON_DELAY != 0
  138. clr P1.ApwmFET
  139. clr P1.BpwmFET
  140. clr P1.CpwmFET
  141. ELSE
  142. clr P1.AcomFET
  143. clr P1.BcomFET
  144. clr P1.CcomFET
  145. ENDIF
  146. ENDM
  147. AcomFET_on MACRO
  148. IF FETON_DELAY == 0
  149. clr P1.ApwmFET
  150. ENDIF
  151. setb P1.AcomFET
  152. ENDM
  153. AcomFET_off MACRO
  154. clr P1.AcomFET
  155. ENDM
  156. BcomFET_on MACRO
  157. IF FETON_DELAY == 0
  158. clr P1.BpwmFET
  159. ENDIF
  160. setb P1.BcomFET
  161. ENDM
  162. BcomFET_off MACRO
  163. clr P1.BcomFET
  164. ENDM
  165. CcomFET_on MACRO
  166. IF FETON_DELAY == 0
  167. clr P1.CpwmFET
  168. ENDIF
  169. setb P1.CcomFET
  170. ENDM
  171. CcomFET_off MACRO
  172. clr P1.CcomFET
  173. ENDM
  174. All_comFETs_Off MACRO
  175. clr P1.AcomFET
  176. clr P1.BcomFET
  177. clr P1.CcomFET
  178. ENDM
  179. Set_Pwm_A MACRO
  180. IF FETON_DELAY == 0
  181. setb P1.AcomFET
  182. mov P1SKIP, #1Fh
  183. ELSE
  184. mov P1SKIP, #0Fh
  185. ENDIF
  186. ENDM
  187. Set_Pwm_B MACRO
  188. IF FETON_DELAY == 0
  189. setb P1.BcomFET
  190. mov P1SKIP, #37h
  191. ELSE
  192. mov P1SKIP, #33h
  193. ENDIF
  194. ENDM
  195. Set_Pwm_C MACRO
  196. IF FETON_DELAY == 0
  197. setb P1.CcomFET
  198. mov P1SKIP, #3Dh
  199. ELSE
  200. mov P1SKIP, #3Ch
  201. ENDIF
  202. ENDM
  203. Set_Pwms_Off MACRO
  204. mov P1SKIP, #3Fh
  205. ENDM
  206. Set_Comp_Phase_A MACRO
  207. mov CMP0MX, #10h ; Set comparator multiplexer to phase A
  208. ENDM
  209. Set_Comp_Phase_B MACRO
  210. mov CMP0MX, #20h ; Set comparator multiplexer to phase B
  211. ENDM
  212. Set_Comp_Phase_C MACRO
  213. mov CMP0MX, #30h ; Set comparator multiplexer to phase C
  214. ENDM
  215. Read_Comp_Out MACRO
  216. mov A, CMP0CN0 ; Read comparator output
  217. ENDM
  218. ;*********************
  219. ; PORT 2 definitions *
  220. ;*********************
  221. DebugPin EQU 0 ;o
  222. P2_PUSHPULL EQU (1 SHL DebugPin)
  223. ;**********************
  224. ; MCU specific macros *
  225. ;**********************
  226. Initialize_Xbar MACRO
  227. mov XBR2, #40h ; Xbar enabled
  228. mov XBR1, #02h ; CEX0 and CEX1 routed to pins
  229. ENDM
  230. Initialize_Comparator MACRO
  231. mov CMP0CN0, #80h ; Comparator enabled, no hysteresis
  232. mov CMP0MD, #00h ; Comparator response time 100ns
  233. ENDM
  234. Initialize_Adc MACRO
  235. mov REF0CN, #0Ch ; Set vdd (3.3V) as reference. Enable temp sensor and bias
  236. IF MCU_48MHZ == 0
  237. mov ADC0CF, #59h ; ADC clock 2MHz, PGA gain 1
  238. ELSE
  239. mov ADC0CF, #0B9h ; ADC clock 2MHz, PGA gain 1
  240. ENDIF
  241. mov ADC0MX, #10h ; Select temp sensor input
  242. mov ADC0CN0, #80h ; ADC enabled
  243. mov ADC0CN1, #01h ; Common mode buffer enabled
  244. ENDM
  245. Start_Adc MACRO
  246. mov ADC0CN0, #90h ; ADC start
  247. ENDM
  248. Read_Adc_Result MACRO
  249. mov Temp1, ADC0L
  250. mov Temp2, ADC0H
  251. ENDM
  252. Stop_Adc MACRO
  253. ENDM
  254. Set_RPM_Out MACRO
  255. ENDM
  256. Clear_RPM_Out MACRO
  257. ENDM
  258. Set_LED_0 MACRO
  259. ENDM
  260. Clear_LED_0 MACRO
  261. ENDM
  262. Set_LED_1 MACRO
  263. ENDM
  264. Clear_LED_1 MACRO
  265. ENDM
  266. Set_LED_2 MACRO
  267. ENDM
  268. Clear_LED_2 MACRO
  269. ENDM
  270. Set_LED_3 MACRO
  271. ENDM
  272. Clear_LED_3 MACRO
  273. ENDM