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