Motor Driver Evaluation Kit
NEVB-MTR1-t01-1.1.0
Firmware for NEVB-MTR1-KIT1 for trapezoidal control of BLDC motors using Hall-effect sensors
Loading...
Searching...
No Matches
fault.cpp
Go to the documentation of this file.
1
/* This file has been prepared for Doxygen automatic documentation generation.*/
21
22
// Include fault header
23
#include "
fault.h
"
24
32
void
EnableOverCurrentLED
(
void
)
33
{
34
PORTB &= ~((1 <<
FAULT_PIN_3
) | (1 <<
FAULT_PIN_2
));
35
PORTD |= (1 <<
FAULT_PIN_1
);
36
}
37
46
void
EnableMotorStoppedLED
(
void
)
47
{
48
PORTB &= ~(1 <<
FAULT_PIN_3
);
49
PORTB |= (1 <<
FAULT_PIN_2
);
50
PORTD &= ~(1 <<
FAULT_PIN_1
);
51
}
52
61
void
EnableReverseRotationLED
(
void
)
62
{
63
PORTB &= ~(1 <<
FAULT_PIN_3
);
64
PORTB |= (1 <<
FAULT_PIN_2
);
65
PORTD |= (1 <<
FAULT_PIN_1
);
66
}
67
76
void
EnableU3
(
void
)
77
{
78
PORTB |= (1 <<
FAULT_PIN_3
);
79
PORTB &= ~(1 <<
FAULT_PIN_2
);
80
PORTD &= ~(1 <<
FAULT_PIN_1
);
81
}
82
91
void
EnableU2
(
void
)
92
{
93
PORTB |= (1 <<
FAULT_PIN_3
);
94
PORTB &= ~(1 <<
FAULT_PIN_2
);
95
PORTD |= (1 <<
FAULT_PIN_1
);
96
}
97
106
void
EnableU1
(
void
)
107
{
108
PORTB |= (1 <<
FAULT_PIN_3
) | (1 <<
FAULT_PIN_2
);
109
PORTD &= ~(1 <<
FAULT_PIN_1
);
110
}
111
120
void
EnableNoHallConnectionsLED
(
void
)
121
{
122
PORTB |= (1 <<
FAULT_PIN_3
) | (1 <<
FAULT_PIN_2
);
123
PORTD |= (1 <<
FAULT_PIN_1
);
124
}
125
132
void
DisableFaultLEDs
(
void
)
133
{
134
PORTB &= ~((1 <<
FAULT_PIN_3
) | (1 <<
FAULT_PIN_2
));
135
PORTD &= ~(1 <<
FAULT_PIN_1
);
136
}
137
144
void
SweepLEDsBlocking
(
void
)
145
{
146
EnableU3
();
147
_delay_ms(100);
148
149
EnableU2
();
150
_delay_ms(100);
151
152
EnableU1
();
153
_delay_ms(100);
154
155
EnableNoHallConnectionsLED
();
156
_delay_ms(100);
157
158
EnableOverCurrentLED
();
159
_delay_ms(100);
160
161
EnableMotorStoppedLED
();
162
_delay_ms(100);
163
164
EnableReverseRotationLED
();
165
_delay_ms(100);
166
}
167
182
void
faultSequentialStateMachine
(
volatile
faultflags_t
*
faultFlags
,
volatile
motorflags_t
*
motorFlags
)
183
{
184
static
uint8_t state = 1;
185
186
switch
(state)
187
{
188
case
1:
189
if
(
faultFlags
->motorStopped ==
TRUE
&&
motorFlags
->enable ==
TRUE
)
190
{
191
EnableMotorStoppedLED
();
192
}
193
else
194
{
195
DisableFaultLEDs
();
196
}
197
state = 2;
198
break
;
199
case
2:
200
if
(
faultFlags
->reverseDirection ==
TRUE
&&
faultFlags
->motorStopped ==
FALSE
)
201
{
202
EnableReverseRotationLED
();
203
}
204
else
205
{
206
DisableFaultLEDs
();
207
}
208
state = 3;
209
break
;
210
case
3:
211
if
(
faultFlags
->noHallConnections ==
TRUE
)
212
{
213
EnableNoHallConnectionsLED
();
214
}
215
else
216
{
217
DisableFaultLEDs
();
218
}
219
state = 4;
220
break
;
221
case
4:
222
if
(
faultFlags
->overCurrent ==
TRUE
)
223
{
224
EnableOverCurrentLED
();
225
}
226
else
227
{
228
DisableFaultLEDs
();
229
}
230
state = 5;
231
break
;
232
case
5:
233
if
(
faultFlags
->userFlag1 ==
TRUE
)
234
{
235
EnableU1
();
236
}
237
else
238
{
239
DisableFaultLEDs
();
240
}
241
state = 6;
242
break
;
243
case
6:
244
if
(
faultFlags
->userFlag2 ==
TRUE
)
245
{
246
EnableU2
();
247
}
248
else
249
{
250
DisableFaultLEDs
();
251
}
252
state = 7;
253
break
;
254
case
7:
255
if
(
faultFlags
->userFlag3 ==
TRUE
)
256
{
257
EnableU3
();
258
}
259
else
260
{
261
DisableFaultLEDs
();
262
}
263
state = 8;
264
break
;
265
default
:
266
// No active fault flags; disable all LEDs or indicators.
267
DisableFaultLEDs
();
268
state = 1;
269
}
270
}
EnableU2
void EnableU2(void)
Enables the user function 2 LED.
Definition
fault.cpp:91
EnableU3
void EnableU3(void)
Enables the user function 3 LED.
Definition
fault.cpp:76
EnableU1
void EnableU1(void)
Enables the user function 1 LED.
Definition
fault.cpp:106
DisableFaultLEDs
void DisableFaultLEDs(void)
Disables all LEDs.
Definition
fault.cpp:132
EnableOverCurrentLED
void EnableOverCurrentLED(void)
Enables the over current fault LED.
Definition
fault.cpp:32
SweepLEDsBlocking
void SweepLEDsBlocking(void)
Sweeps through all LEDs individually with a delay.
Definition
fault.cpp:144
EnableNoHallConnectionsLED
void EnableNoHallConnectionsLED(void)
Enables the no hall connection fault LED.
Definition
fault.cpp:120
EnableMotorStoppedLED
void EnableMotorStoppedLED(void)
Enables the motor stopped fault LED.
Definition
fault.cpp:46
faultSequentialStateMachine
void faultSequentialStateMachine(volatile faultflags_t *faultFlags, volatile motorflags_t *motorFlags)
Sequential State Machine for Handling Fault Flags.
Definition
fault.cpp:182
EnableReverseRotationLED
void EnableReverseRotationLED(void)
Enables the reverse rotation fault LED.
Definition
fault.cpp:61
fault.h
Fault LED header file.
FAULT_PIN_2
#define FAULT_PIN_2
Fault Pin 2.
Definition
config.h:771
motorflags_t
struct motorflags motorflags_t
Collection of all motor control flags.
TRUE
#define TRUE
TRUE constant value, defined to be compatible with comparisons.
Definition
config.h:661
FALSE
#define FALSE
FALSE constant value.
Definition
config.h:659
FAULT_PIN_3
#define FAULT_PIN_3
Fault Pin 3.
Definition
config.h:773
faultflags_t
struct faultflags faultflags_t
Collection of all fault flags.
FAULT_PIN_1
#define FAULT_PIN_1
Fault Pin 1.
Definition
config.h:769
motorFlags
volatile motorflags_t motorFlags
Motor control flags placed in I/O space for fast access.
Definition
main.ino:50
faultFlags
volatile faultflags_t faultFlags
Fault flags placed in I/O space for fast access.
Definition
main.ino:60
fault.cpp
Generated by
1.13.2