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.

268 lines
6.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. ; Common definitions for EFM8BB1x/2x based ESCs
  26. ;
  27. ;**** **** **** **** ****
  28. ;*********************
  29. ; Device SiLabs EFM8BB1x/2x
  30. ;*********************
  31. IF MCU_48MHZ == 0
  32. $include (Silabs/SI_EFM8BB1_Defs.inc)
  33. ELSE
  34. $include (Silabs/SI_EFM8BB2_Defs.inc)
  35. ENDIF
  36. ;**** **** **** **** ****
  37. ; Uses internal calibrated oscillator set to 24/48Mhz
  38. ;**** **** **** **** ****
  39. ;**** **** **** **** ****
  40. ; ESC selection statements
  41. IF ESCNO == A_
  42. $include (targets/A.inc) ; Select pinout A
  43. ELSEIF ESCNO == B_
  44. $include (targets/B.inc) ; Select pinout B
  45. ELSEIF ESCNO == C_
  46. $include (targets/C.inc) ; Select pinout C
  47. ELSEIF ESCNO == D_
  48. $include (targets/D.inc) ; Select pinout D
  49. ELSEIF ESCNO == E_
  50. $include (targets/E.inc) ; Select pinout E
  51. ELSEIF ESCNO == F_
  52. $include (targets/F.inc) ; Select pinout F
  53. ELSEIF ESCNO == G_
  54. $include (targets/G.inc) ; Select pinout G
  55. ELSEIF ESCNO == H_
  56. $include (targets/H.inc) ; Select pinout H
  57. ELSEIF ESCNO == I_
  58. $include (targets/I.inc) ; Select pinout I
  59. ELSEIF ESCNO == J_
  60. $include (targets/J.inc) ; Select pinout J
  61. ELSEIF ESCNO == K_
  62. $include (targets/K.inc) ; Select pinout K
  63. ELSEIF ESCNO == L_
  64. $include (targets/L.inc) ; Select pinout L
  65. ELSEIF ESCNO == M_
  66. $include (targets/M.inc) ; Select pinout M
  67. ELSEIF ESCNO == N_
  68. $include (targets/N.inc) ; Select pinout N
  69. ELSEIF ESCNO == O_
  70. $include (targets/O.inc) ; Select pinout O
  71. ELSEIF ESCNO == P_
  72. $include (targets/P.inc) ; Select pinout P
  73. ELSEIF ESCNO == Q_
  74. $include (targets/Q.inc) ; Select pinout Q
  75. ELSEIF ESCNO == R_
  76. $include (targets/R.inc) ; Select pinout R
  77. ELSEIF ESCNO == S_
  78. $include (targets/S.inc) ; Select pinout S
  79. ELSEIF ESCNO == T_
  80. $include (targets/T.inc) ; Select pinout T
  81. ELSEIF ESCNO == U_
  82. $include (targets/U.inc) ; Select pinout U
  83. ELSEIF ESCNO == V_
  84. $include (targets/V.inc) ; Select pinout V
  85. ELSEIF ESCNO == W_
  86. $include (targets/W.inc) ; Select pinout W
  87. ENDIF
  88. ;**** **** **** **** ****
  89. ; Constant definitions
  90. ;**** **** **** **** ****
  91. ESC_LETTER EQU 40h + ESCNO
  92. IF MCU_48MHZ == 0
  93. MCU_MHZ_LETTER EQU "L"
  94. ELSE
  95. MCU_MHZ_LETTER EQU "H"
  96. ENDIF
  97. CSEG AT 1A40h
  98. IF FETON_DELAY == 0
  99. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_00# " ; ESC layout tag
  100. ELSEIF FETON_DELAY == 5
  101. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_05# "
  102. ELSEIF FETON_DELAY == 10
  103. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_10# "
  104. ELSEIF FETON_DELAY == 15
  105. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_15# "
  106. ELSEIF FETON_DELAY == 20
  107. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_20# "
  108. ELSEIF FETON_DELAY == 25
  109. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_25# "
  110. ELSEIF FETON_DELAY == 30
  111. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_30# "
  112. ELSEIF FETON_DELAY == 40
  113. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_40# "
  114. ELSEIF FETON_DELAY == 50
  115. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_50# "
  116. ELSEIF FETON_DELAY == 70
  117. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_70# "
  118. ELSEIF FETON_DELAY == 90
  119. Eep_ESC_Layout: DB "#",ESC_LETTER,"_",MCU_MHZ_LETTER,"_90# "
  120. ENDIF
  121. IF MCU_48MHZ == 0
  122. CSEG AT 1A50h
  123. Eep_ESC_MCU: DB "#BLHELI$EFM8B10#" ; Project and MCU tag (16 Bytes)
  124. ELSE
  125. CSEG AT 1A50h
  126. Eep_ESC_MCU: DB "#BLHELI$EFM8B21#" ; Project and MCU tag (16 Bytes)
  127. ENDIF
  128. Interrupt_Table_Definition MACRO
  129. CSEG AT 0 ; Code segment start
  130. jmp reset
  131. CSEG AT 03h ; Int0 interrupt
  132. jmp int0_int
  133. IF MCU_48MHZ == 1
  134. CSEG AT 0Bh ; Timer0 overflow interrupt
  135. jmp t0_int
  136. ENDIF
  137. CSEG AT 13h ; Int1 interrupt
  138. jmp int1_int
  139. CSEG AT 1Bh ; Timer1 overflow interrupt
  140. jmp t1_int
  141. CSEG AT 2Bh ; Timer2 overflow interrupt
  142. jmp t2_int
  143. CSEG AT 5Bh ; Pca interrupt
  144. jmp pca_int
  145. CSEG AT 73h ; Timer3 overflow/compare interrupt
  146. jmp t3_int
  147. ENDM
  148. Decode_DShot_2Bit MACRO dest, decode_fail
  149. movx A, @Temp1
  150. mov Temp7, A
  151. clr C
  152. subb A, Temp6 ; Subtract previous timestamp
  153. clr C
  154. subb A, Temp2
  155. jc decode_fail ; Check that bit is longer than minimum
  156. subb A, Temp2 ; Check if bit is zero or one
  157. mov A, dest ; Shift bit into data byte
  158. rlc A
  159. mov dest, A
  160. inc Temp1 ; Next bit
  161. movx A, @Temp1
  162. mov Temp6, A
  163. clr C
  164. subb A, Temp7
  165. clr C
  166. subb A, Temp2
  167. jc decode_fail
  168. subb A, Temp2
  169. mov A, dest
  170. rlc A
  171. mov dest, A
  172. inc Temp1
  173. ENDM
  174. Initialize_PCA MACRO
  175. mov PCA0CN0, #40h ; PCA enabled
  176. mov PCA0MD, #08h ; PCA clock is system clock
  177. mov PCA0PWM, #(80h + PWM_BITS_H) ; PCA ARSEL set and 8/9/10/11 bits pwm
  178. IF PWM_CENTERED == 1
  179. mov PCA0CENT, #03h ; Center aligned pwm
  180. ELSE
  181. mov PCA0CENT, #00h ; Edge aligned pwm
  182. ENDIF
  183. ENDM
  184. Enable_Power_Pwm_Module MACRO
  185. IF FETON_DELAY == 0
  186. mov PCA0_POWER_MODULE, #4Ah ; Enable comparator of module, enable match, set pwm mode
  187. ELSE
  188. mov PCA0_POWER_MODULE, #42h ; Enable comparator of module, set pwm mode
  189. ENDIF
  190. ENDM
  191. Enable_Damp_Pwm_Module MACRO
  192. IF FETON_DELAY == 0
  193. mov PCA0_DAMP_MODULE, #00h ; Disable
  194. ELSE
  195. mov PCA0_DAMP_MODULE, #42h ; Enable comparator of module, set pwm mode
  196. ENDIF
  197. ENDM
  198. Clear_COVF_Interrupt MACRO
  199. anl PCA0PWM, #0DFh
  200. ENDM
  201. Enable_COVF_Interrupt MACRO
  202. orl PCA0PWM, #40h
  203. ENDM
  204. Disable_COVF_Interrupt MACRO
  205. anl PCA0PWM, #0BFh
  206. ENDM
  207. ; CCF interrupt is only used for FETON_DELAY == 0
  208. Clear_CCF_Interrupt MACRO
  209. anl PCA0CN0, #0FEh
  210. ENDM
  211. Enable_CCF_Interrupt MACRO
  212. orl PCA0CPM0,#01h
  213. ENDM
  214. Disable_CCF_Interrupt MACRO
  215. anl PCA0CPM0,#0FEh
  216. ENDM
  217. Enable_PCA_Interrupt MACRO
  218. LOCAL pca_enabled set_pca_int_hi_pwm
  219. IF FETON_DELAY != 0
  220. Enable_COVF_Interrupt
  221. ELSE
  222. jnb Flag_LOW_PWM_POWER, set_pca_int_hi_pwm
  223. Enable_COVF_Interrupt
  224. sjmp pca_enabled
  225. set_pca_int_hi_pwm:
  226. Enable_CCF_Interrupt
  227. pca_enabled:
  228. ENDIF
  229. orl EIE1, #10h ; Enable pca interrupts
  230. ENDM
  231. Set_MCU_Clk_24MHz MACRO
  232. mov CLKSEL, #13h ; Set clock to 24MHz
  233. mov SFRPAGE, #10h
  234. mov PFE0CN, #00h ; Set flash timing for 24MHz
  235. mov SFRPAGE, #00h
  236. clr Flag_CLOCK_SET_AT_48MHZ
  237. ENDM
  238. Set_MCU_Clk_48MHz MACRO
  239. mov SFRPAGE, #10h
  240. mov PFE0CN, #30h ; Set flash timing for 48MHz
  241. mov SFRPAGE, #00h
  242. mov CLKSEL, #03h ; Set clock to 48MHz
  243. setb Flag_CLOCK_SET_AT_48MHZ
  244. ENDM