@@ -28,64 +28,79 @@ void _pinHighFrequency(const int pin){
28
28
// function setting the high pwm frequency to the supplied pins
29
29
// - Stepper motor - 2PWM setting
30
30
// - hardware speciffic
31
- void _configure2PWM (long pwm_frequency,const int pinA, const int pinB) {
31
+ void * _configure2PWM (long pwm_frequency,const int pinA, const int pinB) {
32
32
// High PWM frequency
33
33
// - always max 32kHz
34
34
_pinHighFrequency (pinA);
35
35
_pinHighFrequency (pinB);
36
+ GenericDriverParams* params = new GenericDriverParams {
37
+ .pins = { pinA, pinB },
38
+ .pwm_frequency = pwm_frequency
39
+ };
40
+ return params;
36
41
}
37
42
38
43
// function setting the high pwm frequency to the supplied pins
39
44
// - BLDC motor - 3PWM setting
40
45
// - hardware speciffic
41
- void _configure3PWM (long pwm_frequency,const int pinA, const int pinB, const int pinC) {
46
+ void * _configure3PWM (long pwm_frequency,const int pinA, const int pinB, const int pinC) {
42
47
// High PWM frequency
43
48
// - always max 32kHz
44
49
_pinHighFrequency (pinA);
45
50
_pinHighFrequency (pinB);
46
51
_pinHighFrequency (pinC);
52
+ GenericDriverParams* params = new GenericDriverParams {
53
+ .pins = { pinA, pinB, pinC },
54
+ .pwm_frequency = pwm_frequency
55
+ };
56
+ return params;
47
57
}
48
58
49
59
// function setting the pwm duty cycle to the hardware
50
60
// - Stepper motor - 2PWM setting
51
61
// - hardware speciffic
52
- void _writeDutyCycle2PWM (float dc_a, float dc_b, int pinA, int pinB ){
62
+ void _writeDutyCycle2PWM (float dc_a, float dc_b, void * params ){
53
63
// transform duty cycle from [0,1] to [0,255]
54
- analogWrite (pinA , 255 .0f *dc_a);
55
- analogWrite (pinB , 255 .0f *dc_b);
64
+ analogWrite (((GenericDriverParams*)params)-> pins [ 0 ] , 255 .0f *dc_a);
65
+ analogWrite (((GenericDriverParams*)params)-> pins [ 1 ] , 255 .0f *dc_b);
56
66
}
57
67
58
68
// function setting the pwm duty cycle to the hardware
59
69
// - BLDC motor - 3PWM setting
60
70
// - hardware speciffic
61
- void _writeDutyCycle3PWM (float dc_a, float dc_b, float dc_c, int pinA, int pinB, int pinC ){
71
+ void _writeDutyCycle3PWM (float dc_a, float dc_b, float dc_c, void * params ){
62
72
// transform duty cycle from [0,1] to [0,255]
63
- analogWrite (pinA , 255 .0f *dc_a);
64
- analogWrite (pinB , 255 .0f *dc_b);
65
- analogWrite (pinC , 255 .0f *dc_c);
73
+ analogWrite (((GenericDriverParams*)params)-> pins [ 0 ] , 255 .0f *dc_a);
74
+ analogWrite (((GenericDriverParams*)params)-> pins [ 1 ] , 255 .0f *dc_b);
75
+ analogWrite (((GenericDriverParams*)params)-> pins [ 2 ] , 255 .0f *dc_c);
66
76
}
67
77
68
78
// function setting the high pwm frequency to the supplied pins
69
79
// - Stepper motor - 4PWM setting
70
80
// - hardware speciffic
71
- void _configure4PWM (long pwm_frequency,const int pin1A, const int pin1B, const int pin2A, const int pin2B) {
81
+ void * _configure4PWM (long pwm_frequency,const int pin1A, const int pin1B, const int pin2A, const int pin2B) {
72
82
// High PWM frequency
73
83
// - always max 32kHz
74
84
_pinHighFrequency (pin1A);
75
85
_pinHighFrequency (pin1B);
76
86
_pinHighFrequency (pin2A);
77
87
_pinHighFrequency (pin2B);
88
+ GenericDriverParams* params = new GenericDriverParams {
89
+ .pins = { pin1A, pin2A, pin2A, pin2B },
90
+ .pwm_frequency = pwm_frequency
91
+ };
92
+ return params;
78
93
}
79
94
80
95
// function setting the pwm duty cycle to the hardware
81
96
// - Stepper motor - 4PWM setting
82
97
// - hardware speciffic
83
- void _writeDutyCycle4PWM (float dc_1a, float dc_1b, float dc_2a, float dc_2b, int pin1A, int pin1B, int pin2A, int pin2B) {
98
+ void _writeDutyCycle4PWM (float dc_1a, float dc_1b, float dc_2a, float dc_2b, void * params) {
84
99
// transform duty cycle from [0,1] to [0,255]
85
- analogWrite (pin1A , 255 .0f *dc_1a);
86
- analogWrite (pin1B , 255 .0f *dc_1b);
87
- analogWrite (pin2A , 255 .0f *dc_2a);
88
- analogWrite (pin2B , 255 .0f *dc_2b);
100
+ analogWrite (((GenericDriverParams*)params)-> pins [ 0 ] , 255 .0f *dc_1a);
101
+ analogWrite (((GenericDriverParams*)params)-> pins [ 1 ] , 255 .0f *dc_1b);
102
+ analogWrite (((GenericDriverParams*)params)-> pins [ 2 ] , 255 .0f *dc_2a);
103
+ analogWrite (((GenericDriverParams*)params)-> pins [ 3 ] , 255 .0f *dc_2b);
89
104
}
90
105
91
106
@@ -122,14 +137,20 @@ int _configureComplementaryPair(int pinH, int pinL) {
122
137
// - BLDC driver - 6PWM setting
123
138
// - hardware specific
124
139
// supports Arudino/ATmega328
125
- int _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) {
140
+ 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) {
126
141
// High PWM frequency
127
142
// - always max 32kHz
128
143
int ret_flag = 0 ;
129
144
ret_flag += _configureComplementaryPair (pinA_h, pinA_l);
130
145
ret_flag += _configureComplementaryPair (pinB_h, pinB_l);
131
146
ret_flag += _configureComplementaryPair (pinC_h, pinC_l);
132
- return ret_flag; // returns -1 if not well configured
147
+ if (ret_flag!=0 ) return SIMPLEFOC_DRIVER_INIT_FAILED;
148
+ GenericDriverParams* params = new GenericDriverParams {
149
+ .pins = { pinA_h,, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
150
+ .pwm_frequency = pwm_frequency
151
+ .dead_zone = dead_zone
152
+ };
153
+ return params;
133
154
}
134
155
135
156
// function setting the
@@ -149,10 +170,10 @@ void _setPwmPair(int pinH, int pinL, float val, int dead_time)
149
170
// - BLDC driver - 6PWM setting
150
171
// - hardware specific
151
172
// supports Arudino/ATmega328
152
- void _writeDutyCycle6PWM (float dc_a, float dc_b, float dc_c, float dead_zone, int pinA_h, int pinA_l, int pinB_h, int pinB_l, int pinC_h, int pinC_l ){
153
- _setPwmPair (pinA_h, pinA_l , dc_a*255.0 , dead_zone*255.0 );
154
- _setPwmPair (pinB_h, pinB_l , dc_b*255.0 , dead_zone*255.0 );
155
- _setPwmPair (pinC_h, pinC_l , dc_c*255.0 , dead_zone*255.0 );
173
+ void _writeDutyCycle6PWM (float dc_a, float dc_b, float dc_c, void * params ){
174
+ _setPwmPair (((GenericDriverParams*)params)-> pins [ 0 ], ((GenericDriverParams*)params)-> pins [ 1 ] , dc_a*255.0 , ((GenericDriverParams*)params)-> dead_zone *255.0 );
175
+ _setPwmPair (((GenericDriverParams*)params)-> pins [ 2 ], ((GenericDriverParams*)params)-> pins [ 3 ] , dc_b*255.0 , ((GenericDriverParams*)params)-> dead_zone *255.0 );
176
+ _setPwmPair (((GenericDriverParams*)params)-> pins [ 4 ], ((GenericDriverParams*)params)-> pins [ 5 ] , dc_c*255.0 , ((GenericDriverParams*)params)-> dead_zone *255.0 );
156
177
}
157
178
158
179
#endif
0 commit comments