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.

329 lines
8.5 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. ;**** **** **** **** ****
  2. ;
  3. ; BLHeli program for controlling brushless motors in helicopters and multirotors
  4. ;
  5. ; Copyright 2011, 2012 Steffen Skaug
  6. ; This program is distributed under the terms of the GNU General Public License
  7. ;
  8. ; This file is part of BLHeli.
  9. ;
  10. ; BLHeli 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. ; BLHeli 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 BLHeli. If not, see <http://www.gnu.org/licenses/>.
  22. ;
  23. ;**** **** **** **** ****
  24. ;
  25. ; Turnigy AE 45A hardware definition file
  26. ;
  27. ;**** **** **** **** ****
  28. ;*********************
  29. ; Device SiLabs F310
  30. ;*********************
  31. $include (c8051f310.inc)
  32. ;**** **** **** **** ****
  33. ; Uses internal calibrated oscillator set to 24Mhz
  34. ;**** **** **** **** ****
  35. ;**** **** **** **** ****
  36. ; Constant definitions
  37. ;**** **** **** **** ****
  38. CSEG AT 1A40h
  39. Eep_ESC_Layout: DB "#TurnigyAE45A# " ; ESC layout tag
  40. CSEG AT 1A50h
  41. Eep_ESC_MCU: DB "#BLHELI#F310# " ; Project and MCU tag (16 Bytes)
  42. ONE_S_CAPABLE EQU 0 ; Set to 1 if ESC can operate at 1S
  43. PORT3_EXIST EQU 1 ; Set to 1 if MCU has port3
  44. COMP1_USED EQU 0 ; Set to 1 if MCU has comparator 1 and it is being used
  45. DUAL_BEC_VOLTAGE EQU 1 ; Set to 1 if dual BEC voltage is supported
  46. DAMPED_MODE_ENABLE EQU 1 ; Damped mode disabled
  47. NFETON_DELAY EQU 6 ; Wait delay from pfets off to nfets on
  48. PFETON_DELAY EQU 6 ; Wait delay from nfets off to pfets on
  49. COMP_PWM_HIGH_ON_DELAY EQU 30 ; Wait delay from pwm on until comparator can be read (for high pwm frequency)
  50. COMP_PWM_HIGH_OFF_DELAY EQU 60 ; Wait delay from pwm off until comparator can be read (for high pwm frequency)
  51. COMP_PWM_LOW_ON_DELAY EQU 10 ; Wait delay from pwm on until comparator can be read (for low pwm frequency)
  52. COMP_PWM_LOW_OFF_DELAY EQU 20 ; Wait delay from pwm off until comparator can be read (for low pwm frequency)
  53. ADC_LIMIT_L EQU 85 ; Power supply measurement ADC value for which main motor power is limited (low byte)
  54. ADC_LIMIT_H EQU 0 ; Power supply measurement ADC value for which main motor power is limited (2 MSBs)
  55. TEMP_LIMIT EQU 168 ; Temperature measurement ADC value for which main motor power is limited (low byte, assuming high byte is 1)
  56. TEMP_LIMIT_STEP EQU 5 ; Temperature measurement ADC value increment for which main motor power is further limited
  57. MAIN_SPOOLUP_TIME EQU 10 ; Main motor spoolup time
  58. ;**** **** **** **** ****
  59. ; ESC specific defaults
  60. ;**** **** **** **** ****
  61. DEFAULT_PGM_MAIN_STARTUP_PWR EQU 9 ; 1=0.031 2=0.047 3=0.063 4=0.094 5=0.125 6=0.188 7=0.25 8=0.38 9=0.50 10=0.75 11=1.00 12=1.25 13=1.50
  62. DEFAULT_PGM_TAIL_STARTUP_PWR EQU 9 ; 1=0.031 2=0.047 3=0.063 4=0.094 5=0.125 6=0.188 7=0.25 8=0.38 9=0.50 10=0.75 11=1.00 12=1.25 13=1.50
  63. DEFAULT_PGM_MULTI_STARTUP_PWR EQU 9 ; 1=0.031 2=0.047 3=0.063 4=0.094 5=0.125 6=0.188 7=0.25 8=0.38 9=0.50 10=0.75 11=1.00 12=1.25 13=1.50
  64. DEFAULT_PGM_MAIN_STARTUP_METHOD EQU 2 ; 1=Stepped 2=Direct
  65. DEFAULT_PGM_TAIL_STARTUP_METHOD EQU 2 ; 1=Stepped 2=Direct
  66. DEFAULT_PGM_MULTI_STARTUP_METHOD EQU 2 ; 1=Stepped 2=Direct
  67. ;*********************
  68. ; PORT 0 definitions *
  69. ;*********************
  70. BnFET EQU 7 ;o
  71. BpFET EQU 6 ;o
  72. Rcp_In EQU 5 ;i
  73. ; EQU 4 ;i
  74. ; EQU 3 ;i
  75. ApFET EQU 2 ;o
  76. CnFET EQU 1 ;o
  77. CpFET EQU 0 ;o
  78. P0_DIGITAL EQU 0FFh
  79. P0_INIT EQU NOT((1 SHL BnFET)+(1 SHL CnFET)+(1 SHL ApFET)+(1 SHL BpFET)+(1 SHL CpFET)) AND 0FFh
  80. P0_PUSHPULL EQU (1 SHL BnFET)+(1 SHL CnFET)+(1 SHL ApFET)+(1 SHL BpFET)+(1 SHL CpFET)
  81. P0_SKIP EQU NOT(1 SHL Rcp_In)
  82. MACRO Get_Rcp_Capture_Values
  83. mov Temp1, PCA0CPL0 ; Get PCA capture values
  84. mov Temp2, PCA0CPH0
  85. ENDM
  86. MACRO Read_Rcp_Int
  87. mov A, P0
  88. jnb Flags3.PGM_RCP_PWM_POL, ($+4) ; Is pwm polarity negative?
  89. cpl A ; Yes - invert
  90. ENDM
  91. MACRO Rcp_Int_Enable
  92. orl PCA0CPM0, #01h ; Interrupt enabled
  93. ENDM
  94. MACRO Rcp_Int_Disable
  95. anl PCA0CPM0, #0FEh ; Interrupt disabled
  96. ENDM
  97. MACRO Rcp_Int_First
  98. anl PCA0CPM0, #0CFh
  99. jb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity positive?
  100. orl PCA0CPM0, #20h ; Capture rising edge
  101. jnb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity negative?
  102. orl PCA0CPM0, #10h ; Capture falling edge
  103. ENDM
  104. MACRO Rcp_Int_Second
  105. anl PCA0CPM0, #0CFh
  106. jb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity positive?
  107. orl PCA0CPM0, #10h ; Capture falling edge
  108. jnb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity negative?
  109. orl PCA0CPM0, #20h ; Capture rising edge
  110. ENDM
  111. MACRO Rcp_Clear_Int_Flag
  112. clr CCF0 ; Clear interrupt flag
  113. ENDM
  114. ;*********************
  115. ; PORT 1 definitions *
  116. ;*********************
  117. Mux_B1 EQU 7 ;i
  118. Adc_Ip EQU 6 ;i
  119. Mux_A3 EQU 5 ;i
  120. Mux_A2 EQU 4 ;i
  121. Mux_A1 EQU 3 ;i
  122. ; EQU 2 ;i
  123. Comp_Com2 EQU 1 ;i
  124. Comp_Com1 EQU 0 ;i
  125. P1_DIGITAL EQU 00h
  126. P1_INIT EQU 0FFh
  127. P1_PUSHPULL EQU 00h
  128. P1_SKIP EQU 0
  129. ;*********************
  130. ; PORT 2 definitions *
  131. ;*********************
  132. ; EQU 7 ;i
  133. ; EQU 6 ;i
  134. Mux_C3 EQU 5 ;i
  135. Mux_C2 EQU 4 ;i
  136. Mux_C1 EQU 3 ;i
  137. ; EQU 2 ;i
  138. Mux_B3 EQU 1 ;i
  139. Mux_B2 EQU 0 ;i
  140. P2_DIGITAL EQU 00h
  141. P2_INIT EQU 0FFh
  142. P2_PUSHPULL EQU 00h
  143. P2_SKIP EQU 0
  144. MACRO AnFET_on
  145. mov A, Current_Pwm_Limited
  146. jz ($+12)
  147. jb Flags3.PGM_DIR_REV, ($+5)
  148. setb P3.AnFET
  149. jnb Flags3.PGM_DIR_REV, ($+5)
  150. setb P0.CnFET
  151. ENDM
  152. MACRO AnFET_off
  153. jb Flags3.PGM_DIR_REV, ($+5)
  154. clr P3.AnFET
  155. jnb Flags3.PGM_DIR_REV, ($+5)
  156. clr P0.CnFET
  157. ENDM
  158. MACRO BnFET_on
  159. mov A, Current_Pwm_Limited
  160. jz ($+4)
  161. setb P0.BnFET
  162. ENDM
  163. MACRO BnFET_off
  164. clr P0.BnFET
  165. ENDM
  166. MACRO CnFET_on
  167. mov A, Current_Pwm_Limited
  168. jz ($+12)
  169. jb Flags3.PGM_DIR_REV, ($+5)
  170. setb P0.CnFET
  171. jnb Flags3.PGM_DIR_REV, ($+5)
  172. setb P3.AnFET
  173. ENDM
  174. MACRO CnFET_off
  175. jb Flags3.PGM_DIR_REV, ($+5)
  176. clr P0.CnFET
  177. jnb Flags3.PGM_DIR_REV, ($+5)
  178. clr P3.AnFET
  179. ENDM
  180. MACRO All_nFETs_Off
  181. clr P3.AnFET
  182. clr P0.BnFET
  183. clr P0.CnFET
  184. ENDM
  185. MACRO ApFET_on
  186. jb Flags3.PGM_DIR_REV, ($+5)
  187. setb P0.ApFET
  188. jnb Flags3.PGM_DIR_REV, ($+5)
  189. setb P0.CpFET
  190. ENDM
  191. MACRO ApFET_off
  192. jb Flags3.PGM_DIR_REV, ($+5)
  193. clr P0.ApFET
  194. jnb Flags3.PGM_DIR_REV, ($+5)
  195. clr P0.CpFET
  196. ENDM
  197. MACRO BpFET_on
  198. setb P0.BpFET
  199. ENDM
  200. MACRO BpFET_off
  201. clr P0.BpFET
  202. ENDM
  203. MACRO CpFET_on
  204. jb Flags3.PGM_DIR_REV, ($+5)
  205. setb P0.CpFET
  206. jnb Flags3.PGM_DIR_REV, ($+5)
  207. setb P0.ApFET
  208. ENDM
  209. MACRO CpFET_off
  210. jb Flags3.PGM_DIR_REV, ($+5)
  211. clr P0.CpFET
  212. jnb Flags3.PGM_DIR_REV, ($+5)
  213. clr P0.ApFET
  214. ENDM
  215. MACRO All_pFETs_Off
  216. clr P0.ApFET
  217. clr P0.BpFET
  218. clr P0.CpFET
  219. ENDM
  220. MACRO All_pFETs_On
  221. setb P0.ApFET
  222. setb P0.BpFET
  223. setb P0.CpFET
  224. ENDM
  225. MACRO Set_Comp_Phase_A
  226. jb Flags3.PGM_DIR_REV, ($+6)
  227. mov CPT0MX, #01h ; Set comparator multiplexer to phase A
  228. jnb Flags3.PGM_DIR_REV, ($+6)
  229. mov CPT0MX, #03h
  230. ENDM
  231. MACRO Set_Comp_Phase_B
  232. mov CPT0MX, #02h ; Set comparator multiplexer to phase B
  233. ENDM
  234. MACRO Set_Comp_Phase_C
  235. jb Flags3.PGM_DIR_REV, ($+6)
  236. mov CPT0MX, #03h ; Set comparator multiplexer to phase C
  237. jnb Flags3.PGM_DIR_REV, ($+6)
  238. mov CPT0MX, #01h
  239. ENDM
  240. MACRO Read_Comp_Out
  241. mov A, CPT0CN ; Read comparator output
  242. ENDM
  243. ;*********************
  244. ; PORT 3 definitions *
  245. ;*********************
  246. LED EQU 4 ;o
  247. Bec_6V EQU 3 ;o
  248. ; EQU 2 ;i
  249. AnFET EQU 1 ;o
  250. DebugPin EQU 0 ;o
  251. P3_DIGITAL EQU 0FFh
  252. P3_INIT EQU NOT((1 SHL LED)+(1 SHL Bec_6V)+(1 SHL AnFET)+(1 SHL DebugPin))
  253. P3_PUSHPULL EQU (1 SHL LED)+(1 SHL Bec_6V)+(1 SHL AnFET)+(1 SHL DebugPin)
  254. ;**********************
  255. ; MCU specific macros *
  256. ;**********************
  257. MACRO Interrupt_Table_Definition
  258. CSEG AT 0 ; Code segment start
  259. jmp reset
  260. CSEG AT 0Bh ; Timer0 interrupt
  261. jmp t0_int
  262. CSEG AT 2Bh ; Timer2 interrupt
  263. jmp t2_int
  264. CSEG AT 5Bh ; PCA interrupt
  265. jmp pca_int
  266. CSEG AT 73h ; Timer3 interrupt
  267. jmp t3_int
  268. ENDM
  269. MACRO Initialize_Xbar
  270. mov XBR1, #41h ; Xbar enabled, CEX0 routed to pin Rcp_In
  271. ENDM
  272. MACRO Initialize_Adc
  273. mov REF0CN, #0Eh ; Set vdd (3.3V) as reference. Enable temp sensor and bias
  274. mov ADC0CF, #58h ; ADC clock 2MHz
  275. mov AMX0P, #Adc_Ip ; Select positive input
  276. mov AMX0N, #1Fh ; Select negative input as ground
  277. mov ADC0CN, #80h ; ADC enabled
  278. ENDM
  279. MACRO Set_Adc_Ip_Volt
  280. mov AMX0P, #Adc_Ip ; Select positive input
  281. ENDM
  282. MACRO Set_Adc_Ip_Temp
  283. mov AMX0P, #1Eh ; Select temp sensor input
  284. ENDM
  285. MACRO Start_Adc
  286. mov ADC0CN, #90h ; ADC start
  287. ENDM
  288. MACRO Get_Adc_Status
  289. mov A, ADC0CN
  290. ENDM
  291. MACRO Read_Adc_Result
  292. mov Temp1, ADC0L
  293. mov Temp2, ADC0H
  294. ENDM
  295. MACRO Stop_Adc
  296. ENDM
  297. MACRO Set_BEC_Hi
  298. setb P3.Bec_6V
  299. ENDM
  300. MACRO Set_BEC_Lo
  301. clr P3.Bec_6V
  302. ENDM