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.

301 lines
5.9 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 "V"
  26. ; Cc X RC X MC CC MB MA X Ap Ac Bp X X Bc Cp
  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. CcomFET EQU 7 ;o
  49. ; EQU 6 ;i
  50. Rcp_In EQU 5 ;i
  51. ; EQU 4 ;i
  52. Mux_C EQU 3 ;i
  53. Comp_Com EQU 2 ;i
  54. Mux_B EQU 1 ;i
  55. Mux_A 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 CcomFET)
  58. P0_PUSHPULL EQU (1 SHL CcomFET)
  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. ApwmFET EQU 6 ;i
  87. AcomFET EQU 5 ;i
  88. BpwmFET EQU 4 ;o
  89. ; EQU 3 ;o
  90. ; EQU 2 ;o
  91. BcomFET EQU 1 ;o
  92. CpwmFET EQU 0 ;o
  93. P1_DIGITAL EQU (1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET)+(1 SHL AcomFET)+(1 SHL BcomFET)
  94. P1_INIT EQU 00h
  95. P1_PUSHPULL EQU (1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET)+(1 SHL AcomFET)+(1 SHL BcomFET)
  96. P1_SKIP EQU 7Fh
  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 P0.CcomFET
  127. ENDIF
  128. ENDM
  129. CpwmFET_off MACRO
  130. IF FETON_DELAY != 0
  131. clr P1.CpwmFET
  132. ELSE
  133. clr P0.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 P0.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 P0.CcomFET
  170. ENDM
  171. CcomFET_off MACRO
  172. clr P0.CcomFET
  173. ENDM
  174. All_comFETs_Off MACRO
  175. clr P1.AcomFET
  176. clr P1.BcomFET
  177. clr P0.CcomFET
  178. ENDM
  179. Set_Pwm_A MACRO
  180. IF FETON_DELAY == 0
  181. setb P1.AcomFET
  182. mov P0SKIP, #0FFh
  183. mov P1SKIP, #3Fh
  184. ELSE
  185. mov P0SKIP, #0FFh
  186. mov P1SKIP, #1Fh
  187. ENDIF
  188. ENDM
  189. Set_Pwm_B MACRO
  190. IF FETON_DELAY == 0
  191. setb P1.BcomFET
  192. mov P0SKIP, #0FFh
  193. mov P1SKIP, #6Fh
  194. ELSE
  195. mov P0SKIP, #0FFh
  196. mov P1SKIP, #6Dh
  197. endif
  198. ENDM
  199. Set_Pwm_C MACRO
  200. IF FETON_DELAY == 0
  201. setb P0.CcomFET
  202. mov P0SKIP, #0FFh
  203. mov P1SKIP, #7Fh
  204. ELSE
  205. mov P0SKIP, #7Fh
  206. mov P1SKIP, #7Eh
  207. endif
  208. ENDM
  209. Set_Pwms_Off MACRO
  210. mov P0SKIP, #0FFh
  211. mov P1SKIP, #7Fh
  212. ENDM
  213. Set_Comp_Phase_A MACRO
  214. mov CMP0MX, #02h ; Set comparator multiplexer to phase A
  215. ENDM
  216. Set_Comp_Phase_B MACRO
  217. mov CMP0MX, #12h ; Set comparator multiplexer to phase B
  218. ENDM
  219. Set_Comp_Phase_C MACRO
  220. mov CMP0MX, #32h ; Set comparator multiplexer to phase C
  221. ENDM
  222. Read_Comp_Out MACRO
  223. mov A, CMP0CN0 ; Read comparator output
  224. ENDM
  225. ;*********************
  226. ; PORT 2 definitions *
  227. ;*********************
  228. DebugPin EQU 0 ;o
  229. P2_PUSHPULL EQU (1 SHL DebugPin)
  230. ;**********************
  231. ; MCU specific macros *
  232. ;**********************
  233. Initialize_Xbar MACRO
  234. mov XBR2, #40h ; Xbar enabled
  235. mov XBR1, #02h ; CEX0 and CEX1 routed to pins
  236. ENDM
  237. Initialize_Comparator MACRO
  238. mov CMP0CN0, #80h ; Comparator enabled, no hysteresis
  239. mov CMP0MD, #00h ; Comparator response time 100ns
  240. ENDM
  241. Initialize_Adc MACRO
  242. mov REF0CN, #0Ch ; Set vdd (3.3V) as reference. Enable temp sensor and bias
  243. IF MCU_48MHZ == 0
  244. mov ADC0CF, #59h ; ADC clock 2MHz, PGA gain 1
  245. ELSE
  246. mov ADC0CF, #0B9h ; ADC clock 2MHz, PGA gain 1
  247. ENDIF
  248. mov ADC0MX, #10h ; Select temp sensor input
  249. mov ADC0CN0, #80h ; ADC enabled
  250. mov ADC0CN1, #01h ; Common mode buffer enabled
  251. ENDM
  252. Start_Adc MACRO
  253. mov ADC0CN0, #90h ; ADC start
  254. ENDM
  255. Read_Adc_Result MACRO
  256. mov Temp1, ADC0L
  257. mov Temp2, ADC0H
  258. ENDM
  259. Stop_Adc MACRO
  260. ENDM
  261. Set_RPM_Out MACRO
  262. ENDM
  263. Clear_RPM_Out MACRO
  264. ENDM
  265. Set_LED_0 MACRO
  266. ENDM
  267. Clear_LED_0 MACRO
  268. ENDM
  269. Set_LED_1 MACRO
  270. ENDM
  271. Clear_LED_1 MACRO
  272. ENDM
  273. Set_LED_2 MACRO
  274. ENDM
  275. Clear_LED_2 MACRO
  276. ENDM
  277. Set_LED_3 MACRO
  278. ENDM
  279. Clear_LED_3 MACRO
  280. ENDM