Motor Evaluation Kit NEVC-MCTRL-100-t01-1.0.0
Firmware for NEVB-MCTRL-100-01 for trapezoidal control of BLDC motors using Hall-effect sensors
Loading...
Searching...
No Matches
fault.cpp File Reference

Fault LED source file. More...

#include "fault.h"
Include dependency graph for fault.cpp:

Go to the source code of this file.

Functions

void EnableOverCurrentLED (void)
 Enables the over current fault LED.
 
void EnableMotorStoppedLED (void)
 Enables the motor stopped fault LED.
 
void EnableReverseRotationLED (void)
 Enables the reverse rotation fault LED.
 
void EnableU3 (void)
 Enables the user function 3 LED.
 
void EnableU2 (void)
 Enables the user function 2 LED.
 
void EnableU1 (void)
 Enables the user function 1 LED.
 
void EnableNoHallConnectionsLED (void)
 Enables the no hall connection fault LED.
 
void DisableFaultLEDs (void)
 Disables all LEDs.
 
void SweepLEDsBlocking (void)
 Sweeps through all LEDs individually with a delay.
 
void faultSequentialStateMachine (volatile faultflags_t *faultFlags, volatile motorflags_t *motorFlags)
 Sequential State Machine for Handling Fault Flags.
 

Detailed Description

Fault LED source file.

This file contains all functions necessary for managing and displaying faults through the LED multiplexer.

Author
Nexperia: http://www.nexperia.com
Support Page
For additional support, visit: https://www.nexperia.com/support
Author
Aanas Sayed
Date
2024/03/08


Definition in file fault.cpp.

Function Documentation

◆ DisableFaultLEDs()

void DisableFaultLEDs ( void )

Disables all LEDs.

Sets: FAULT_BIT3 = 0 FAULT_BIT2 = 0 FAULT_BIT1 = 0

Definition at line 132 of file fault.cpp.

133{
134 PORTB &= ~((1 << FAULT_PIN_3) | (1 << FAULT_PIN_2));
135 PORTD &= ~(1 << FAULT_PIN_1);
136}
#define FAULT_PIN_2
Fault Pin 2.
Definition main.h:637
#define FAULT_PIN_3
Fault Pin 3.
Definition main.h:639
#define FAULT_PIN_1
Fault Pin 1.
Definition main.h:635
Here is the caller graph for this function:

◆ EnableMotorStoppedLED()

void EnableMotorStoppedLED ( void )

Enables the motor stopped fault LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 0 FAULT_BIT2 = 1 FAULT_BIT1 = 0

Definition at line 46 of file fault.cpp.

47{
48 PORTB &= ~(1 << FAULT_PIN_3);
49 PORTB |= (1 << FAULT_PIN_2);
50 PORTD &= ~(1 << FAULT_PIN_1);
51}
Here is the caller graph for this function:

◆ EnableNoHallConnectionsLED()

void EnableNoHallConnectionsLED ( void )

Enables the no hall connection fault LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 1 FAULT_BIT2 = 1 FAULT_BIT1 = 1

Definition at line 120 of file fault.cpp.

121{
122 PORTB |= (1 << FAULT_PIN_3) | (1 << FAULT_PIN_2);
123 PORTD |= (1 << FAULT_PIN_1);
124}
Here is the caller graph for this function:

◆ EnableOverCurrentLED()

void EnableOverCurrentLED ( void )

Enables the over current fault LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 0 FAULT_BIT2 = 0 FAULT_BIT1 = 1

Definition at line 32 of file fault.cpp.

33{
34 PORTB &= ~((1 << FAULT_PIN_3) | (1 << FAULT_PIN_2));
35 PORTD |= (1 << FAULT_PIN_1);
36}
Here is the caller graph for this function:

◆ EnableReverseRotationLED()

void EnableReverseRotationLED ( void )

Enables the reverse rotation fault LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 0 FAULT_BIT2 = 1 FAULT_BIT1 = 1

Definition at line 61 of file fault.cpp.

62{
63 PORTB &= ~(1 << FAULT_PIN_3);
64 PORTB |= (1 << FAULT_PIN_2);
65 PORTD |= (1 << FAULT_PIN_1);
66}
Here is the caller graph for this function:

◆ EnableU1()

void EnableU1 ( void )

Enables the user function 1 LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 1 FAULT_BIT2 = 1 FAULT_BIT1 = 0

Definition at line 106 of file fault.cpp.

107{
108 PORTB |= (1 << FAULT_PIN_3) | (1 << FAULT_PIN_2);
109 PORTD &= ~(1 << FAULT_PIN_1);
110}
Here is the caller graph for this function:

◆ EnableU2()

void EnableU2 ( void )

Enables the user function 2 LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 1 FAULT_BIT2 = 0 FAULT_BIT1 = 1

Definition at line 91 of file fault.cpp.

92{
93 PORTB |= (1 << FAULT_PIN_3);
94 PORTB &= ~(1 << FAULT_PIN_2);
95 PORTD |= (1 << FAULT_PIN_1);
96}
Here is the caller graph for this function:

◆ EnableU3()

void EnableU3 ( void )

Enables the user function 3 LED.

Note
As this feeds to a multiplexer, other LEDs are disabled.

Sets: FAULT_BIT3 = 1 FAULT_BIT2 = 0 FAULT_BIT1 = 0

Definition at line 76 of file fault.cpp.

77{
78 PORTB |= (1 << FAULT_PIN_3);
79 PORTB &= ~(1 << FAULT_PIN_2);
80 PORTD &= ~(1 << FAULT_PIN_1);
81}
Here is the caller graph for this function:

◆ faultSequentialStateMachine()

void faultSequentialStateMachine ( volatile faultflags_t * faultFlags,
volatile motorflags_t * motorFlags )

Sequential State Machine for Handling Fault Flags.

This function implements a sequential state machine for handling fault flags and controlling corresponding LEDs or indicators. It sequentially checks the various fault flags and enables/disables LEDs or indicators based on the current fault flag conditions.

Parameters
faultFlagsA pointer to the volatile faultflags_t structure containing the fault flags to be checked.
motorFlagsA pointer to the volatile motorflags_t structure containing motor control flags (e.g., motor enable status).

Definition at line 181 of file fault.cpp.

182{
183 static uint8_t state = 1;
184
185 switch (state)
186 {
187 case 1:
189 {
191 }
192 else
193 {
195 }
196 state = 2;
197 break;
198 case 2:
200 {
202 }
203 else
204 {
206 }
207 state = 3;
208 break;
209 case 3:
211 {
213 }
214 else
215 {
217 }
218 state = 4;
219 break;
220 case 4:
222 {
224 }
225 else
226 {
228 }
229 state = 5;
230 break;
231 case 5:
232 if (faultFlags->userFlag1 == TRUE)
233 {
234 EnableU1();
235 }
236 else
237 {
239 }
240 state = 6;
241 break;
242 case 6:
243 if (faultFlags->userFlag2 == TRUE)
244 {
245 EnableU2();
246 }
247 else
248 {
250 }
251 state = 7;
252 break;
253 case 7:
254 if (faultFlags->userFlag3 == TRUE)
255 {
256 EnableU3();
257 }
258 else
259 {
261 }
262 state = 8;
263 break;
264 default:
265 // No active fault flags; disable all LEDs or indicators.
267 state = 1;
268 }
269}
void EnableU2(void)
Enables the user function 2 LED.
Definition fault.cpp:91
void EnableU3(void)
Enables the user function 3 LED.
Definition fault.cpp:76
void EnableU1(void)
Enables the user function 1 LED.
Definition fault.cpp:106
void DisableFaultLEDs(void)
Disables all LEDs.
Definition fault.cpp:132
void EnableOverCurrentLED(void)
Enables the over current fault LED.
Definition fault.cpp:32
void EnableNoHallConnectionsLED(void)
Enables the no hall connection fault LED.
Definition fault.cpp:120
void EnableMotorStoppedLED(void)
Enables the motor stopped fault LED.
Definition fault.cpp:46
void EnableReverseRotationLED(void)
Enables the reverse rotation fault LED.
Definition fault.cpp:61
#define TRUE
TRUE constant value, defined to be compatible with comparisons.
Definition main.h:537
#define FALSE
FALSE constant value.
Definition main.h:535
volatile motorflags_t motorFlags
Motor control flags placed in I/O space for fast access.
Definition main.ino:76
volatile faultflags_t faultFlags
Fault flags placed in I/O space for fast access.
Definition main.ino:84
uint8_t userFlag2
Is user flag 2 set?
Definition main.h:1013
uint8_t motorStopped
Is motor stopped?
Definition main.h:1005
uint8_t userFlag3
Is user flag 3 set?
Definition main.h:1015
uint8_t noHallConnections
Is there no hall connections?
Definition main.h:1009
uint8_t overCurrent
Has it tripped the over current limit?
Definition main.h:1007
uint8_t reverseDirection
Is motor spinning in an unexpected direction?
Definition main.h:1003
uint8_t userFlag1
Is user flag 1 set?
Definition main.h:1011
uint8_t enable
Is the motor enabled?
Definition main.h:985
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SweepLEDsBlocking()

void SweepLEDsBlocking ( void )

Sweeps through all LEDs individually with a delay.

Note
This is a blocking function. Do not use while motor is operational.

Definition at line 144 of file fault.cpp.

145{
146 EnableU3();
147 _delay_ms(100);
148
149 EnableU2();
150 _delay_ms(100);
151
152 EnableU1();
153 _delay_ms(100);
154
156 _delay_ms(100);
157
159 _delay_ms(100);
160
162 _delay_ms(100);
163
165 _delay_ms(100);
166}
Here is the call graph for this function:
Here is the caller graph for this function: