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.

242 lines
6.3 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. Initialize_PCA MACRO
  149. mov PCA0CN0, #40h ; PCA enabled
  150. mov PCA0MD, #08h ; PCA clock is system clock
  151. mov PCA0PWM, #(80h + PWM_BITS_H) ; PCA ARSEL set and 8/9/10/11 bits pwm
  152. IF PWM_CENTERED == 1
  153. mov PCA0CENT, #03h ; Center aligned pwm
  154. ELSE
  155. mov PCA0CENT, #00h ; Edge aligned pwm
  156. ENDIF
  157. ENDM
  158. Enable_Power_Pwm_Module MACRO
  159. IF FETON_DELAY == 0
  160. mov PCA0_POWER_MODULE, #4Ah ; Enable comparator of module, enable match, set pwm mode
  161. ELSE
  162. mov PCA0_POWER_MODULE, #42h ; Enable comparator of module, set pwm mode
  163. ENDIF
  164. ENDM
  165. Enable_Damp_Pwm_Module MACRO
  166. IF FETON_DELAY == 0
  167. mov PCA0_DAMP_MODULE, #00h ; Disable
  168. ELSE
  169. mov PCA0_DAMP_MODULE, #42h ; Enable comparator of module, set pwm mode
  170. ENDIF
  171. ENDM
  172. Clear_COVF_Interrupt MACRO
  173. anl PCA0PWM, #0DFh
  174. ENDM
  175. Enable_COVF_Interrupt MACRO
  176. orl PCA0PWM, #40h
  177. ENDM
  178. Disable_COVF_Interrupt MACRO
  179. anl PCA0PWM, #0BFh
  180. ENDM
  181. ; CCF interrupt is only used for FETON_DELAY == 0
  182. Clear_CCF_Interrupt MACRO
  183. anl PCA0CN0, #0FEh
  184. ENDM
  185. Enable_CCF_Interrupt MACRO
  186. orl PCA0CPM0,#01h
  187. ENDM
  188. Disable_CCF_Interrupt MACRO
  189. anl PCA0CPM0,#0FEh
  190. ENDM
  191. Enable_PCA_Interrupt MACRO
  192. LOCAL pca_enabled set_pca_int_hi_pwm
  193. IF FETON_DELAY != 0
  194. Enable_COVF_Interrupt
  195. ELSE
  196. jnb Flag_LOW_PWM_POWER, set_pca_int_hi_pwm
  197. Enable_COVF_Interrupt
  198. sjmp pca_enabled
  199. set_pca_int_hi_pwm:
  200. Enable_CCF_Interrupt
  201. pca_enabled:
  202. ENDIF
  203. orl EIE1, #10h ; Enable pca interrupts
  204. ENDM
  205. Set_MCU_Clk_24MHz MACRO
  206. mov CLKSEL, #13h ; Set clock to 24MHz
  207. mov SFRPAGE, #10h
  208. mov PFE0CN, #00h ; Set flash timing for 24MHz and disable prefetch engine
  209. mov SFRPAGE, #00h
  210. clr Flag_CLOCK_SET_AT_48MHZ
  211. ENDM
  212. Set_MCU_Clk_48MHz MACRO
  213. mov SFRPAGE, #10h
  214. mov PFE0CN, #30h ; Set flash timing for 48MHz and enable prefetch engine
  215. mov SFRPAGE, #00h
  216. mov CLKSEL, #03h ; Set clock to 48MHz
  217. setb Flag_CLOCK_SET_AT_48MHZ
  218. ENDM