SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
drivers/hardware_api.h
Go to the documentation of this file.
1#ifndef HARDWARE_UTILS_DRIVER_H
2#define HARDWARE_UTILS_DRIVER_H
3
4#include "../common/foc_utils.h"
5#include "../common/time_utils.h"
6#include "../communication/SimpleFOCDebug.h"
7#include "../common/base_classes/BLDCDriver.h"
8
9
10// these defines determine the polarity of the PWM output. Normally, the polarity is active-high,
11// i.e. a high-level PWM output is expected to switch on the MOSFET. But should your driver design
12// require inverted polarity, you can change the defines below, or set them via your build environment
13// or board definition files.
14
15// used for 1-PWM, 2-PWM, 3-PWM, and 4-PWM modes
16#ifndef SIMPLEFOC_PWM_ACTIVE_HIGH
17#define SIMPLEFOC_PWM_ACTIVE_HIGH true
18#endif
19// used for 6-PWM mode, high-side
20#ifndef SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH
21#define SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH true
22#endif
23// used for 6-PWM mode, low-side
24#ifndef SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH
25#define SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH true
26#endif
27
28// flag returned if driver init fails
29#define SIMPLEFOC_DRIVER_INIT_FAILED ((void*)-1)
30
31// generic implementation of the hardware specific structure
32// containing all the necessary driver parameters
33// will be returned as a void pointer from the _configurexPWM functions
34// will be provided to the _writeDutyCyclexPWM() as a void pointer
40
41
42/**
43 * Configuring PWM frequency, resolution and alignment
44 * - Stepper driver - 2PWM setting
45 * - hardware specific
46 *
47 * @param pwm_frequency - frequency in hertz - if applicable
48 * @param pinA pinA pwm pin
49 *
50 * @return -1 if failed, or pointer to internal driver parameters struct if successful
51 */
52void* _configure1PWM(long pwm_frequency, const int pinA);
53
54/**
55 * Configuring PWM frequency, resolution and alignment
56 * - Stepper driver - 2PWM setting
57 * - hardware specific
58 *
59 * @param pwm_frequency - frequency in hertz - if applicable
60 * @param pinA pinA bldc driver
61 * @param pinB pinB bldc driver
62 *
63 * @return -1 if failed, or pointer to internal driver parameters struct if successful
64 */
65void* _configure2PWM(long pwm_frequency, const int pinA, const int pinB);
66
67/**
68 * Configuring PWM frequency, resolution and alignment
69 * - BLDC driver - 3PWM setting
70 * - hardware specific
71 *
72 * @param pwm_frequency - frequency in hertz - if applicable
73 * @param pinA pinA bldc driver
74 * @param pinB pinB bldc driver
75 * @param pinC pinC bldc driver
76 *
77 * @return -1 if failed, or pointer to internal driver parameters struct if successful
78 */
79void* _configure3PWM(long pwm_frequency, const int pinA, const int pinB, const int pinC);
80
81/**
82 * Configuring PWM frequency, resolution and alignment
83 * - Stepper driver - 4PWM setting
84 * - hardware specific
85 *
86 * @param pwm_frequency - frequency in hertz - if applicable
87 * @param pin1A pin1A stepper driver
88 * @param pin1B pin1B stepper driver
89 * @param pin2A pin2A stepper driver
90 * @param pin2B pin2B stepper driver
91 *
92 * @return -1 if failed, or pointer to internal driver parameters struct if successful
93 */
94void* _configure4PWM(long pwm_frequency, const int pin1A, const int pin1B, const int pin2A, const int pin2B);
95
96/**
97 * Configuring PWM frequency, resolution and alignment
98 * - BLDC driver - 6PWM setting
99 * - hardware specific
100 *
101 * @param pwm_frequency - frequency in hertz - if applicable
102 * @param dead_zone duty cycle protection zone [0, 1] - both low and high side low - if applicable
103 * @param pinA_h pinA high-side bldc driver
104 * @param pinA_l pinA low-side bldc driver
105 * @param pinB_h pinA high-side bldc driver
106 * @param pinB_l pinA low-side bldc driver
107 * @param pinC_h pinA high-side bldc driver
108 * @param pinC_l pinA low-side bldc driver
109 *
110 * @return -1 if failed, or pointer to internal driver parameters struct if successful
111 */
112void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const int pinA_l, const int pinB_h, const int pinB_l, const int pinC_h, const int pinC_l);
113
114/**
115 * Function setting the duty cycle to the pwm pin (ex. analogWrite())
116 * - Stepper driver - 2PWM setting
117 * - hardware specific
118 *
119 * @param dc_a duty cycle phase A [0, 1]
120 * @param dc_b duty cycle phase B [0, 1]
121 * @param params the driver parameters
122 */
123void _writeDutyCycle1PWM(float dc_a, void* params);
124
125/**
126 * Function setting the duty cycle to the pwm pin (ex. analogWrite())
127 * - Stepper driver - 2PWM setting
128 * - hardware specific
129 *
130 * @param dc_a duty cycle phase A [0, 1]
131 * @param dc_b duty cycle phase B [0, 1]
132 * @param params the driver parameters
133 */
134void _writeDutyCycle2PWM(float dc_a, float dc_b, void* params);
135
136/**
137 * Function setting the duty cycle to the pwm pin (ex. analogWrite())
138 * - BLDC driver - 3PWM setting
139 * - hardware specific
140 *
141 * @param dc_a duty cycle phase A [0, 1]
142 * @param dc_b duty cycle phase B [0, 1]
143 * @param dc_c duty cycle phase C [0, 1]
144 * @param params the driver parameters
145 */
146void _writeDutyCycle3PWM(float dc_a, float dc_b, float dc_c, void* params);
147
148/**
149 * Function setting the duty cycle to the pwm pin (ex. analogWrite())
150 * - Stepper driver - 4PWM setting
151 * - hardware specific
152 *
153 * @param dc_1a duty cycle phase 1A [0, 1]
154 * @param dc_1b duty cycle phase 1B [0, 1]
155 * @param dc_2a duty cycle phase 2A [0, 1]
156 * @param dc_2b duty cycle phase 2B [0, 1]
157 * @param params the driver parameters
158 */
159void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, void* params);
160
161
162/**
163 * Function setting the duty cycle to the pwm pin (ex. analogWrite())
164 * - BLDC driver - 6PWM setting
165 * - hardware specific
166 *
167 * @param dc_a duty cycle phase A [0, 1]
168 * @param dc_b duty cycle phase B [0, 1]
169 * @param dc_c duty cycle phase C [0, 1]
170 * @param phase_state pointer to PhaseState[3] array
171 * @param params the driver parameters
172 *
173 */
174void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void* params);
175
176
177#endif
PhaseState
Definition FOCDriver.h:7
const int const int const int pinC
GenericCurrentSenseParams * params
void * _configure4PWM(long pwm_frequency, const int pin1A, const int pin1B, const int pin2A, const int pin2B)
void * _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const int pinA_l, const int pinB_h, const int pinB_l, const int pinC_h, const int pinC_l)
void * _configure2PWM(long pwm_frequency, const int pinA, const int pinB)
void _writeDutyCycle2PWM(float dc_a, float dc_b, void *params)
void _writeDutyCycle1PWM(float dc_a, void *params)
void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, void *params)
void * _configure3PWM(long pwm_frequency, const int pinA, const int pinB, const int pinC)
void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void *params)
void * _configure1PWM(long pwm_frequency, const int pinA)
void _writeDutyCycle3PWM(float dc_a, float dc_b, float dc_c, void *params)
float const int const int const int pinB_h
float const int const int const int const int pinB_l
const int const int pin1B
const int const int const int pin2A
float const int const int const int const int const int pinC_h
float float float dc_2b
float float PhaseState * phase_state
float const int const int const int const int const int const int pinC_l
float const int const int pinA_l
const int const int const int const int pin2B