-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.h
85 lines (71 loc) · 2.15 KB
/
main.h
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
/*******************************************************************************
* File: hardware.h
* Author: Vladimir Pasashnikov, [email protected]
*
* Created on 31 August 2017
******************************************************************************/
#include "hardware.h"
#include "status_led_state_machine.h"
#include "pid_controller.h"
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Controller states. This FSM implemented as a switch block in the main loop.
* it seems that's more practical, as we don't need to mess around function pointers.
*/
typedef enum
{
CTRL_STATE_IDLE,
CTRL_STATE_UPDATE_PID,
CTRL_STATE_STEPPING,
CTRL_STATE_HOLD,
CTRL_STATE_FAULT,
CTRL_STATE_FAULT_W1,
CTRL_STATE_FAULT_W2,
CTRL_STATES_COUNT
} ControllerState;
typedef struct {
/* Step mode
* step_size = 0 -> Full Step
* step_size = 1 -> 1/2 Step
* step_size = 2 -> 1/4 Step
* step_size = 3 -> 1/8 Step
* step_size = 4 -> 1/16 Step
* step_size = 5 -> 1/32 Step
* step_size = 6 -> 1/64 Step
* step_size = 7 -> 1/128 Step
* step_size = 8 -> 1/256 Step
*/
int step_size;
/* used to increment micro-stepping counter stepCount
* step_increment = 256 -> Full Step
* step_increment = 128 -> 1/2 Step
* step_increment = 64 -> 1/4 Step
* step_increment = 32 -> 1/8 Step
* step_increment = 16 -> 1/16 Step
* step_increment = 8 -> 1/32 Step
* step_increment = 8 -> 1/32 Step
* step_increment = 4 -> 1/64 Step
* step_increment = 2 -> 1/128 Step
* step_increment = 1 -> 1/256 Step
*/
int step_increment;
volatile int step_count; //micro-step counter
} StepperState;
extern ControllerState controller_state;
extern StepperState stepper_state;
extern PidControllerParameters pid_parameters;
extern WindingState winding1;
extern PidControllerState winding1_pid_state;
extern WindingState winding2;
extern PidControllerState winding2_pid_state;
void MainControlLoop ();
void UpdateStepperState ();
void ClosedLoopADCInterruptRoutine ();
#ifdef __cplusplus
}
#endif
#endif /* MAIN_H */