-
Notifications
You must be signed in to change notification settings - Fork 0
/
rct50a.inc
201 lines (184 loc) · 4.05 KB
/
rct50a.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
;***********************************************************
;* RCTimer 50A with all FETs on PORTD *
;* Same sense and FET pins as TowerPro "type 1" boards, *
;* but with different FET pin ordering *
;* Original fuses are lfuse:0xbf hfuse:0xc1 *
;***********************************************************
;*********************
; PORT D definitions *
;*********************
.equ ApFET = 7 ;o
.equ c_comp = 6 ;i common comparator input (AIN0)
.equ AnFET = 5 ;o
.equ BnFET = 4 ;o
.equ BpFET = 3 ;o
.equ rcp_in = 2 ;i r/c pulse input
.equ CpFET = 1 ;o
.equ CnFET = 0 ;o
.equ INIT_PD = 0
.equ DIR_PD = (1<<ApFET)+(1<<BpFET)+(1<<CpFET)+(1<<AnFET)+(1<<BnFET)+(1<<CnFET)
.equ USE_ICP = 0
.equ T1ICP = 0
.equ ApFET_port = PORTD
.equ BpFET_port = PORTD
.equ CpFET_port = PORTD
.equ AnFET_port = PORTD
.equ BnFET_port = PORTD
.equ CnFET_port = PORTD
.MACRO rjmp_ext_int0
rjmp ext_int0
.ENDMACRO
.MACRO rjmp_icp1_int
nop
.ENDMACRO
.MACRO rcp_int_enable
ldi @0, (1<<INT0) ; enable ext0int
out GICR, @0
.ENDMACRO
.MACRO rcp_int_rising_edge
ldi @0, (1<<ISC01)+(1<<ISC00)
out MCUCR, @0 ; set next int0 to rising edge
.ENDMACRO
.MACRO rcp_int_falling_edge
ldi @0, (1<<ISC01)
out MCUCR, @0 ; set next int0 to falling edge
.ENDMACRO
.MACRO ApFET_on
sbi PORTD, ApFET
.ENDMACRO
.MACRO ApFET_off
cbi PORTD, ApFET
.ENDMACRO
.MACRO BpFET_on
sbi PORTD, BpFET
.ENDMACRO
.MACRO BpFET_off
cbi PORTD, BpFET
.ENDMACRO
.MACRO CpFET_on
sbi PORTD, CpFET
.ENDMACRO
.MACRO CpFET_off
cbi PORTD, CpFET
.ENDMACRO
.MACRO AnFET_on
sbi PORTD, AnFET
.ENDMACRO
.MACRO AnFET_off
cbi PORTD, AnFET
.ENDMACRO
.MACRO BnFET_on
sbi PORTD, BnFET
.ENDMACRO
.MACRO BnFET_off
cbi PORTD, BnFET
.ENDMACRO
.MACRO CnFET_on
sbi PORTD, CnFET
.ENDMACRO
.MACRO CnFET_off
cbi PORTD, CnFET
.ENDMACRO
.MACRO ApFET_on_reg
sbr @0, 1<<ApFET
.ENDMACRO
.MACRO ApFET_off_reg
cbr @0, 1<<ApFET
.ENDMACRO
.MACRO BpFET_on_reg
sbr @0, 1<<BpFET
.ENDMACRO
.MACRO BpFET_off_reg
cbr @0, 1<<BpFET
.ENDMACRO
.MACRO CpFET_on_reg
sbr @0, 1<<CpFET
.ENDMACRO
.MACRO CpFET_off_reg
cbr @0, 1<<CpFET
.ENDMACRO
.MACRO AnFET_on_reg
sbr @0, 1<<AnFET
.ENDMACRO
.MACRO AnFET_off_reg
cbr @0, 1<<AnFET
.ENDMACRO
.MACRO BnFET_on_reg
sbr @0, 1<<BnFET
.ENDMACRO
.MACRO BnFET_off_reg
cbr @0, 1<<BnFET
.ENDMACRO
.MACRO CnFET_on_reg
sbr @0, 1<<CnFET
.ENDMACRO
.MACRO CnFET_off_reg
cbr @0, 1<<CnFET
.ENDMACRO
.MACRO nFET_brake
in @0, PORTD
sbr @0, (1<<AnFET)+(1<<BnFET)+(1<<CnFET)
out PORTD, @0
.ENDMACRO
.MACRO all_nFETs_off
in @0, PORTD
cbr @0, (1<<AnFET)+(1<<BnFET)+(1<<CnFET)
out PORTD, @0
.ENDMACRO
.MACRO all_pFETs_off
in @0, PORTD
cbr @0, (1<<ApFET)+(1<<BpFET)+(1<<CpFET)
out PORTD, @0
.ENDMACRO
;*********************
; PORT C definitions *
;*********************
.equ mux_vbat = 7 ; ADC7 voltage input (47k from Vbat, 2.0k to gnd, 14.7V in -> .598V at ADC7)
;.equ = 6 ; ADC6
;.equ = 5 ; ADC5
.equ mux_c = 4 ; ADC4 phase input
.equ mux_b = 3 ; ADC3 phase input
.equ mux_a = 2 ; ADC2 phase input
;.equ = 1 ; ADC1
;.equ = 0 ; ADC0
.equ INIT_PC = 0
.equ DIR_PC = 0
.MACRO comp_init
in @0, SFIOR
sbr @0, (1<<ACME) ; set Analog Comparator Multiplexer Enable
out SFIOR, @0
cbi ADCSRA, ADEN ; disable ADC
.ENDMACRO
.MACRO set_comp_phase_a
ldi @0, mux_a ; set comparator multiplexer to phase A
out ADMUX, @0
.ENDMACRO
.MACRO set_comp_phase_b
ldi @0, mux_b ; set comparator multiplexer to phase B
out ADMUX, @0
.ENDMACRO
.MACRO set_comp_phase_c
ldi @0, mux_c ; set comparator multiplexer to phase C
out ADMUX, @0
.ENDMACRO
;*********************
; PORT B definitions *
;*********************
;.equ = 7
;.equ = 6
;.equ = 5 (sck stk200 interface)
;.equ = 4 (miso stk200 interface)
;.equ = 3 (mosi stk200 interface)
;.equ = 2
;.equ = 1
;.equ = 0
.equ INIT_PB = 0
.equ DIR_PB = 0
.MACRO RED_on
.ENDMACRO
.MACRO RED_off
.ENDMACRO
.MACRO GRN_on
.ENDMACRO
.MACRO GRN_off
.ENDMACRO