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.

187 lines
5.0 KiB

  1. ;**** **** **** **** ****
  2. ;
  3. ; Bluejay digital ESC firmware for controlling brushless motors in multirotors
  4. ;
  5. ; Copyright 2020, 2021 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 (Layouts/A.inc) ; Select pinout A
  43. ELSEIF ESCNO == B_
  44. $include (Layouts/B.inc) ; Select pinout B
  45. ELSEIF ESCNO == C_
  46. $include (Layouts/C.inc) ; Select pinout C
  47. ELSEIF ESCNO == D_
  48. $include (Layouts/D.inc) ; Select pinout D
  49. ELSEIF ESCNO == E_
  50. $include (Layouts/E.inc) ; Select pinout E
  51. ELSEIF ESCNO == F_
  52. $include (Layouts/F.inc) ; Select pinout F
  53. ELSEIF ESCNO == G_
  54. $include (Layouts/G.inc) ; Select pinout G
  55. ELSEIF ESCNO == H_
  56. $include (Layouts/H.inc) ; Select pinout H
  57. ELSEIF ESCNO == I_
  58. $include (Layouts/I.inc) ; Select pinout I
  59. ELSEIF ESCNO == J_
  60. $include (Layouts/J.inc) ; Select pinout J
  61. ELSEIF ESCNO == K_
  62. $include (Layouts/K.inc) ; Select pinout K
  63. ELSEIF ESCNO == L_
  64. $include (Layouts/L.inc) ; Select pinout L
  65. ELSEIF ESCNO == M_
  66. $include (Layouts/M.inc) ; Select pinout M
  67. ELSEIF ESCNO == N_
  68. $include (Layouts/N.inc) ; Select pinout N
  69. ELSEIF ESCNO == O_
  70. $include (Layouts/O.inc) ; Select pinout O
  71. ELSEIF ESCNO == P_
  72. $include (Layouts/P.inc) ; Select pinout P
  73. ELSEIF ESCNO == Q_
  74. $include (Layouts/Q.inc) ; Select pinout Q
  75. ELSEIF ESCNO == R_
  76. $include (Layouts/R.inc) ; Select pinout R
  77. ELSEIF ESCNO == S_
  78. $include (Layouts/S.inc) ; Select pinout S
  79. ELSEIF ESCNO == T_
  80. $include (Layouts/T.inc) ; Select pinout T
  81. ELSEIF ESCNO == U_
  82. $include (Layouts/U.inc) ; Select pinout U
  83. ELSEIF ESCNO == V_
  84. $include (Layouts/V.inc) ; Select pinout V
  85. ELSEIF ESCNO == W_
  86. $include (Layouts/W.inc) ; Select pinout W
  87. ;ELSEIF ESCNO == X_
  88. ;$include (Layouts/X.inc) ; Select pinout X
  89. ;ELSEIF ESCNO == Y_
  90. ;$include (Layouts/Y.inc) ; Select pinout Y
  91. ELSEIF ESCNO == Z_
  92. $include (Layouts/Z.inc) ; Select pinout Z
  93. ENDIF
  94. SIGNATURE_001 EQU 0E8h ; Device signature
  95. IF MCU_48MHZ == 0
  96. SIGNATURE_002 EQU 0B1h
  97. ELSE
  98. SIGNATURE_002 EQU 0B2h
  99. ENDIF
  100. ;**** **** **** **** ****
  101. ; Constant definitions
  102. ;**** **** **** **** ****
  103. ESC_C EQU "A" + ESCNO - 1 ; ESC target letter
  104. IF MCU_48MHZ == 0 ; MCU letter (24Mhz=L, 48Mhz=H)
  105. MCU_C EQU "L"
  106. ELSE
  107. MCU_C EQU "H"
  108. ENDIF
  109. ENDIF
  110. ; Dead time number as chars
  111. DT_C2 EQU "0" + (DEADTIME / 100)
  112. DT_C1 EQU "0" + ((DEADTIME / 10) MOD 10)
  113. DT_C0 EQU "0" + (DEADTIME MOD 10)
  114. CSEG AT 1A40h ; ESC layout tag
  115. IF DEADTIME < 100
  116. Eep_ESC_Layout: DB "#", ESC_C, "_", MCU_C, "_", DT_C1, DT_C0, "# "
  117. ELSE
  118. Eep_ESC_Layout: DB "#", ESC_C, "_", MCU_C, "_", DT_C2, DT_C1, DT_C0, "# "
  119. ENDIF
  120. CSEG AT 1A50h ; Project and MCU tag (16 Bytes)
  121. IF MCU_48MHZ == 0
  122. Eep_ESC_MCU: DB "#BLHELI$EFM8B10#"
  123. ELSE
  124. Eep_ESC_MCU: DB "#BLHELI$EFM8B21#"
  125. ENDIF
  126. Interrupt_Table_Definition MACRO
  127. CSEG AT 0 ;; Code segment start
  128. jmp reset
  129. CSEG AT 03h ;; Int0 interrupt
  130. jmp int0_int
  131. CSEG AT 0Bh ;; Timer0 overflow interrupt
  132. jmp t0_int
  133. CSEG AT 13h ;; Int1 interrupt
  134. jmp int1_int
  135. CSEG AT 1Bh ;; Timer1 overflow interrupt
  136. jmp t1_int
  137. CSEG AT 2Bh ;; Timer2 overflow interrupt
  138. jmp t2_int
  139. CSEG AT 5Bh ;; PCA interrupt
  140. jmp pca_int
  141. CSEG AT 73h ;; Timer3 overflow/compare interrupt
  142. jmp t3_int
  143. ENDM
  144. Initialize_PCA MACRO
  145. mov PCA0CN0, #40h ;; PCA enabled
  146. mov PCA0MD, #08h ;; PCA clock is system clock
  147. mov PCA0PWM, #(80h + PWM_BITS_H) ;; Enable PCA auto-reload registers and set pwm cycle length (8-11 bits)
  148. IF PWM_CENTERED == 1
  149. mov PCA0CENT, #07h ;; Center aligned pwm
  150. ELSE
  151. mov PCA0CENT, #00h ;; Edge aligned pwm
  152. ENDIF
  153. ENDM
  154. Set_MCU_Clk_24MHz MACRO
  155. mov CLKSEL, #13h ;; Set clock to 24MHz (Oscillator 1 divided by 2)
  156. mov SFRPAGE, #10h
  157. mov PFE0CN, #00h ;; Set flash timing for 24MHz and disable prefetch engine
  158. mov SFRPAGE, #00h
  159. clr Flag_Clock_At_48MHz
  160. ENDM
  161. Set_MCU_Clk_48MHz MACRO
  162. mov SFRPAGE, #10h
  163. mov PFE0CN, #30h ;; Set flash timing for 48MHz and enable prefetch engine
  164. mov SFRPAGE, #00h
  165. mov CLKSEL, #03h ;; Set clock to 48MHz (Oscillator 1)
  166. setb Flag_Clock_At_48MHz
  167. ENDM