-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbs_nfet.inc
212 lines (186 loc) · 3.9 KB
/
bs_nfet.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
;***************************************************************
;* For HK Blue Series with only n-Channel FETs *
;* Fuses should be set to -U lfuse:w:0x3f:m -U hfuse:w:0xd7:m *
;* or similar (even intrc will work now) *
;* 09/2011 *
;* https://github.com/sim-/tgy *
;***************************************************************
.equ F_CPU , 16000000
.equ USE_INT0 , 1
.equ USE_I2C , 0 ; We could, but FETs are on the I2C ports
.equ USE_UART , 0
.equ USE_ICP , 0
;*********************
; PORT D definitions *
;*********************
;.equ , 7
;.equ , 6
.equ AnFET , 5
.equ ApFET , 4
;.equ , 3
.equ rcp_in , 2
.equ INIT_PD , (1<<ApFET)
.equ DIR_PD , (1<<AnFET)+(1<<ApFET)
.equ AnFET_port , PORTD
.equ ApFET_port , PORTD
.MACRO rcp_int_enable r0:req
ldi \r0, (1<<INT0) ; enable ext0int
out GICR, \r0
.ENDM
.MACRO rcp_int_disable r0
out GICR, ZH ; disable ext0int
.ENDM
.MACRO rcp_int_rising_edge r0:req
ldi \r0, (1<<ISC01)+(1<<ISC00)
out MCUCR, \r0 ; set next int0 to rising edge
.ENDM
.MACRO rcp_int_falling_edge r0:req
ldi \r0, (1<<ISC01)
out MCUCR, \r0 ; set next int0 to falling edge
.ENDM
.MACRO AnFET_on
sbi PORTD, AnFET
.ENDM
.MACRO AnFET_off
cbi PORTD, AnFET
.ENDM
.MACRO ApFET_on
cbi PORTD, ApFET
.ENDM
.MACRO ApFET_off
sbi PORTD, ApFET
.ENDM
.MACRO AnFET_on_reg r0:req
sbr \r0, 1<<AnFET
.ENDM
.MACRO AnFET_off_reg r0:req
cbr \r0, 1<<AnFET
.ENDM
.MACRO ApFET_on_reg r0:req
cbr \r0, 1<<ApFET
.ENDM
.MACRO ApFET_off_reg r0:req
sbr \r0, 1<<ApFET
.ENDM
;*********************
; PORT C definitions *
;*********************
.equ mux_b , 7 ; ADC7
.equ mux_a , 6 ; ADC6
.equ BpFET , 5
.equ BnFET , 4
.equ CpFET , 3
;.equ accu_adc , 2 ; ADC2 -> not used
;.equ AnREF , 1 ; ADC1 -> not used
.equ mux_c , 0 ; ADC0
.equ INIT_PC , (1<<BpFET)+(1<<CpFET)
.equ DIR_PC , (1<<BnFET)+(1<<BpFET)+(1<<CpFET)
.equ BpFET_port , PORTC
.equ BnFET_port , PORTC
.equ CpFET_port , PORTC
.MACRO BnFET_on
sbi PORTC, BnFET
.ENDM
.MACRO BnFET_off
cbi PORTC, BnFET
.ENDM
.MACRO BpFET_on
cbi PORTC, BpFET
.ENDM
.MACRO BpFET_off
sbi PORTC, BpFET
.ENDM
.MACRO CpFET_on
cbi PORTC, CpFET
.ENDM
.MACRO CpFET_off
sbi PORTC, CpFET
.ENDM
.MACRO BnFET_on_reg r0:req
sbr \r0, 1<<BnFET
.ENDM
.MACRO BnFET_off_reg r0:req
cbr \r0, 1<<BnFET
.ENDM
.MACRO BpFET_on_reg r0:req
cbr \r0, 1<<BpFET
.ENDM
.MACRO BpFET_off_reg r0:req
sbr \r0, 1<<BpFET
.ENDM
.MACRO CpFET_on_reg r0:req
cbr \r0, 1<<CpFET
.ENDM
.MACRO CpFET_off_reg r0:req
sbr \r0, 1<<CpFET
.ENDM
.MACRO comp_init r0:req
in \r0, SFIOR
sbr \r0, 1<<ACME ; switch to comparator multiplexed
out SFIOR, \r0
cbi ADCSRA, ADEN ; disable ADC
.ENDM
.MACRO set_comp_phase_a r0:req
ldi \r0, mux_a ; set comparator multiplexer to phase A
out ADMUX, \r0
.ENDM
.MACRO set_comp_phase_b r0:req
ldi \r0, mux_b ; set comparator multiplexer to phase B
out ADMUX, \r0
.ENDM
.MACRO set_comp_phase_c r0:req
ldi \r0, mux_c ; set comparator multiplexer to phase C
out ADMUX, \r0
.ENDM
;*********************
; PORT B definitions *
;*********************
;.equ , 7
;.equ , 6
.equ T5 , 5 ; (sck stk200 interface)
.equ T4 , 4 ; (miso stk200 interface)
.equ T3 , 3 ; (mosi stk200 interface)
.equ GND_PIN , 2 ; Seems to be grounded on this board
;.equ , 1
.equ CnFET , 0
.equ INIT_PB , 0
.equ DIR_PB , (1<<CnFET) | (1<<T3) | (1<<T4) | (1<<T5)
.equ CnFET_port , PORTB
.MACRO CnFET_on
sbi PORTB, CnFET
.ENDM
.MACRO CnFET_off
cbi PORTB, CnFET
.ENDM
.MACRO CnFET_on_reg r0:req
sbr \r0, 1<<CnFET
.ENDM
.MACRO CnFET_off_reg r0:req
cbr \r0, 1<<CnFET
.ENDM
;********************
; Some other Macros *
;********************
.MACRO nFET_brake r0
AnFET_on
BnFET_on
CnFET_on
.ENDM
.MACRO all_nFETs_off r0
AnFET_off
BnFET_off
CnFET_off
.ENDM
.MACRO all_pFETs_off r0
ApFET_off
BpFET_off
CpFET_off
.ENDM
.MACRO RED_on
.ENDM
.MACRO RED_off
.ENDM
.MACRO GRN_on
.ENDM
.MACRO GRN_off
.ENDM