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.

255 lines
6.4 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 "W". This is for tristate input style FET driver chips
  26. ; RC MC MB X CC MA X X X Ap Bp Cp X X X 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 7 ; 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. Rcp_In EQU 7 ;i
  49. Mux_C EQU 6 ;i
  50. Mux_B EQU 5 ;i
  51. ; EQU 4 ;i
  52. Comp_Com EQU 3 ;i
  53. Mux_A 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 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. ApwmFET EQU 6 ;o
  87. BpwmFET EQU 5 ;o
  88. CpwmFET EQU 4 ;o
  89. ; EQU 3 ;i
  90. ; EQU 2 ;i
  91. ; EQU 1 ;i
  92. ; EQU 0 ;i
  93. ; pwm outputs start as analog in -> floating
  94. ; this ensures all mosfet drivers start with floating outputs
  95. P1_DIGITAL EQU NOT((1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET))
  96. P1_INIT EQU 00h
  97. P1_PUSHPULL EQU ((1 SHL ApwmFET)+(1 SHL BpwmFET)+(1 SHL CpwmFET))
  98. ;
  99. P1_SKIP EQU 0FFh
  100. ApwmFET_on MACRO
  101. setb P1.ApwmFET ; set pin to high
  102. orl P1MDIN, #(1 SHL ApwmFET) ; enable pin driver
  103. ENDM
  104. ApwmFET_off MACRO
  105. anl P1MDIN, #(NOT(1 SHL ApwmFET)) ; analog in -> pullup, driver and digital in is disable = floating
  106. ENDM
  107. BpwmFET_on MACRO
  108. setb P1.BpwmFET ; set pin to high
  109. orl P1MDIN, #(1 SHL BpwmFET) ; enable pin driver
  110. ENDM
  111. BpwmFET_off MACRO
  112. anl P1MDIN, #(NOT(1 SHL BpwmFET)) ; analog in -> pullup, driver and digital in is disable = floating
  113. ENDM
  114. CpwmFET_on MACRO
  115. setb P1.CpwmFET ; set pin to high
  116. orl P1MDIN, #(1 SHL CpwmFET) ; enable pin driver
  117. ENDM
  118. CpwmFET_off MACRO
  119. anl P1MDIN, #(NOT(1 SHL CpwmFET)) ; analog in -> pullup, driver and digital in is disable = floating
  120. ENDM
  121. All_pwmFETs_Off MACRO
  122. anl P1MDIN, #(NOT((1 SHL ApwmFET) + (1 SHL BpwmFET) + (1 SHL CpwmFET))) ; analog in -> pullup, driver and digital in is disable = floating
  123. ENDM
  124. AcomFET_on MACRO
  125. clr P1.ApwmFET ; set pin to low
  126. orl P1MDIN, #(1 SHL ApwmFET) ; enable pin driver
  127. ENDM
  128. AcomFET_off MACRO
  129. anl P1MDIN, #(NOT(1 SHL ApwmFET)) ; analog in -> pullup, driver and digital in is disable = floating
  130. ENDM
  131. BcomFET_on MACRO
  132. clr P1.BpwmFET ; set pin to low
  133. orl P1MDIN, #(1 SHL BpwmFET) ; enable pin driver
  134. ENDM
  135. BcomFET_off MACRO
  136. anl P1MDIN, #(NOT(1 SHL BpwmFET)) ; analog in -> pullup, driver and digital in is disable = floating
  137. ENDM
  138. CcomFET_on MACRO
  139. clr P1.CpwmFET ; set pin to low
  140. orl P1MDIN, #(1 SHL CpwmFET) ; enable pin driver
  141. ENDM
  142. CcomFET_off MACRO
  143. anl P1MDIN, #(NOT(1 SHL CpwmFET)) ; analog in -> pullup, driver and digital in is disable = floating
  144. ENDM
  145. All_comFETs_Off MACRO
  146. anl P1MDIN, #(NOT((1 SHL ApwmFET) + (1 SHL BpwmFET) + (1 SHL CpwmFET))) ; analog in -> pullup, driver and digital in is disable = floating
  147. ENDM
  148. Set_Pwm_A MACRO
  149. mov P1SKIP, #(NOT(1 SHL ApwmFET));
  150. orl P1MDIN, #(1 SHL ApwmFET) ; enable pin driver
  151. ENDM
  152. Set_Pwm_B MACRO
  153. mov P1SKIP, #(NOT(1 SHL BpwmFET));
  154. orl P1MDIN, #(1 SHL BpwmFET) ; enable pin driver
  155. ENDM
  156. Set_Pwm_C MACRO
  157. mov P1SKIP, #(NOT(1 SHL CpwmFET));
  158. orl P1MDIN, #(1 SHL CpwmFET) ; enable pin driver
  159. ENDM
  160. Set_Pwms_Off MACRO
  161. mov P1SKIP, #P1_SKIP;
  162. ENDM
  163. Set_Comp_Phase_A MACRO
  164. mov CMP0MX, #((Mux_A) SHL 4)+((Comp_Com) SHL 0);
  165. ENDM
  166. Set_Comp_Phase_B MACRO
  167. mov CMP0MX, #((Mux_B) SHL 4)+((Comp_Com) SHL 0);
  168. ENDM
  169. Set_Comp_Phase_C MACRO
  170. mov CMP0MX, #((Mux_C) SHL 4)+((Comp_Com) SHL 0);
  171. ENDM
  172. Read_Comp_Out MACRO
  173. mov A, CMP0CN0 ; Read comparator output
  174. ENDM
  175. ;*********************
  176. ; PORT 2 definitions *
  177. ;*********************
  178. DebugPin EQU 0 ;o
  179. P2_PUSHPULL EQU (1 SHL DebugPin)
  180. ;**********************
  181. ; MCU specific macros *
  182. ;**********************
  183. Initialize_Xbar MACRO
  184. mov XBR2, #40h ; Xbar enabled
  185. mov XBR1, #02h ; CEX0 and CEX1 routed to pins
  186. ENDM
  187. Initialize_Comparator MACRO
  188. mov CMP0CN0, #80h ; Comparator enabled, no hysteresis
  189. mov CMP0MD, #00h ; Comparator response time 100ns
  190. ENDM
  191. Initialize_Adc MACRO
  192. mov REF0CN, #0Ch ; Set vdd (3.3V) as reference. Enable temp sensor and bias
  193. IF MCU_48MHZ == 0
  194. mov ADC0CF, #59h ; ADC clock 2MHz, PGA gain 1
  195. ELSE
  196. mov ADC0CF, #0B9h ; ADC clock 2MHz, PGA gain 1
  197. ENDIF
  198. mov ADC0MX, #10h ; Select temp sensor input
  199. mov ADC0CN0, #80h ; ADC enabled
  200. mov ADC0CN1, #01h ; Common mode buffer enabled
  201. ENDM
  202. Start_Adc MACRO
  203. mov ADC0CN0, #90h ; ADC start
  204. ENDM
  205. Read_Adc_Result MACRO
  206. mov Temp1, ADC0L
  207. mov Temp2, ADC0H
  208. ENDM
  209. Stop_Adc MACRO
  210. ENDM
  211. Set_RPM_Out MACRO
  212. ENDM
  213. Clear_RPM_Out MACRO
  214. ENDM
  215. Set_LED_0 MACRO
  216. ENDM
  217. Clear_LED_0 MACRO
  218. ENDM
  219. Set_LED_1 MACRO
  220. ENDM
  221. Clear_LED_1 MACRO
  222. ENDM
  223. Set_LED_2 MACRO
  224. ENDM
  225. Clear_LED_2 MACRO
  226. ENDM
  227. Set_LED_3 MACRO
  228. ENDM
  229. Clear_LED_3 MACRO
  230. ENDM