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.

240 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. ; 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. CSEG AT 0Bh ;; Timer0 overflow interrupt
  134. jmp t0_int
  135. CSEG AT 13h ;; Int1 interrupt
  136. jmp int1_int
  137. CSEG AT 1Bh ;; Timer1 overflow interrupt
  138. jmp t1_int
  139. CSEG AT 2Bh ;; Timer2 overflow interrupt
  140. jmp t2_int
  141. CSEG AT 5Bh ;; PCA interrupt
  142. jmp pca_int
  143. CSEG AT 73h ;; Timer3 overflow/compare interrupt
  144. jmp t3_int
  145. ENDM
  146. Initialize_PCA MACRO
  147. mov PCA0CN0, #40h ;; PCA enabled
  148. mov PCA0MD, #08h ;; PCA clock is system clock
  149. mov PCA0PWM, #(80h + PWM_BITS_H) ;; Enable PCA auto-reload registers and set pwm cycle length (8-11 bits)
  150. IF PWM_CENTERED == 1
  151. mov PCA0CENT, #03h ;; Center aligned pwm
  152. ELSE
  153. mov PCA0CENT, #00h ;; Edge aligned pwm
  154. ENDIF
  155. ENDM
  156. Enable_Power_Pwm_Module MACRO
  157. IF FETON_DELAY == 0
  158. mov PCA0_POWER_MODULE, #4Ah ;; Enable comparator of module, enable match, set pwm mode
  159. ELSE
  160. mov PCA0_POWER_MODULE, #42h ;; Enable comparator of module, set pwm mode
  161. ENDIF
  162. ENDM
  163. Enable_Damp_Pwm_Module MACRO
  164. IF FETON_DELAY == 0
  165. mov PCA0_DAMP_MODULE, #00h ;; Disable
  166. ELSE
  167. mov PCA0_DAMP_MODULE, #42h ;; Enable comparator of module, set pwm mode
  168. ENDIF
  169. ENDM
  170. Clear_COVF_Interrupt MACRO
  171. anl PCA0PWM, #0DFh
  172. ENDM
  173. Enable_COVF_Interrupt MACRO
  174. orl PCA0PWM, #40h
  175. ENDM
  176. Disable_COVF_Interrupt MACRO
  177. anl PCA0PWM, #0BFh
  178. ENDM
  179. ; CCF interrupt is only used for FETON_DELAY == 0
  180. Clear_CCF_Interrupt MACRO
  181. anl PCA0CN0, #0FEh
  182. ENDM
  183. Enable_CCF_Interrupt MACRO
  184. orl PCA0CPM0,#01h
  185. ENDM
  186. Disable_CCF_Interrupt MACRO
  187. anl PCA0CPM0,#0FEh
  188. ENDM
  189. Enable_PCA_Interrupt MACRO
  190. LOCAL pca_enabled set_pca_int_hi_pwm
  191. IF FETON_DELAY != 0
  192. Enable_COVF_Interrupt
  193. ELSE
  194. jnb Flag_Low_Pwm_Power, set_pca_int_hi_pwm
  195. Enable_COVF_Interrupt
  196. sjmp pca_enabled
  197. set_pca_int_hi_pwm:
  198. Enable_CCF_Interrupt
  199. pca_enabled:
  200. ENDIF
  201. orl EIE1, #10h ;; Enable pca interrupts
  202. ENDM
  203. Set_MCU_Clk_24MHz MACRO
  204. mov CLKSEL, #13h ;; Set clock to 24MHz (Oscillator 1 divided by 2)
  205. mov SFRPAGE, #10h
  206. mov PFE0CN, #00h ;; Set flash timing for 24MHz and disable prefetch engine
  207. mov SFRPAGE, #00h
  208. clr Flag_Clock_At_48MHz
  209. ENDM
  210. Set_MCU_Clk_48MHz MACRO
  211. mov SFRPAGE, #10h
  212. mov PFE0CN, #30h ;; Set flash timing for 48MHz and enable prefetch engine
  213. mov SFRPAGE, #00h
  214. mov CLKSEL, #03h ;; Set clock to 48MHz (Oscillator 1)
  215. setb Flag_Clock_At_48MHz
  216. ENDM