@@ -238,6 +238,41 @@ void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, in
238
238
}
239
239
}
240
240
241
+ // configuring high frequency pwm timer
242
+ // https://hackaday.io/project/169905-esp-32-bldc-robot-actuator-controller/log/184464-mcpwm-with-deadband
243
+ void _configureTimerFrequency6PWM (long pwm_frequency, mcpwm_dev_t * mcpwm_num, mcpwm_unit_t mcpwm_unit){
244
+
245
+ mcpwm_config_t pwm_config;
246
+ pwm_config.frequency = 4000 ; // frequency = 20000Hz
247
+ pwm_config.cmpr_a = 50.0 ; // duty cycle of PWMxA = 50.0%
248
+ pwm_config.cmpr_b = 50.0 ; // duty cycle of PWMxB = 50.0%
249
+ pwm_config.counter_mode = MCPWM_UP_COUNTER; // Up-down counter (triangle wave)
250
+ pwm_config.duty_mode = MCPWM_DUTY_MODE_0; // Active HIGH
251
+ mcpwm_init (MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config); // Configure PWM0A & PWM0B with above settings
252
+ mcpwm_init (MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config); // Configure PWM0A & PWM0B with above settings
253
+ mcpwm_init (MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config); // Configure PWM0A & PWM0B with above settings
254
+
255
+ mcpwm_deadtime_enable (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 40 , 40 );
256
+ mcpwm_deadtime_enable (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 40 , 40 );
257
+ mcpwm_deadtime_enable (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 40 , 40 );
258
+
259
+ mcpwm_sync_enable (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_SYNC_INT0, 0 );
260
+ mcpwm_sync_enable (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_SELECT_SYNC_INT0, 0 );
261
+ mcpwm_sync_enable (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_SELECT_SYNC_INT0, 0 );
262
+
263
+ MCPWM0.timer [0 ].sync .out_sel = 1 ;
264
+ delayMicroseconds (1000 );
265
+ MCPWM0.timer [0 ].sync .out_sel = 0 ;
266
+
267
+ mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, 50 );
268
+ mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, 50 );
269
+ mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_A, 50 );
270
+ mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_B, 50 );
271
+ mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_OPR_A, 50 );
272
+ mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_OPR_B, 50 );
273
+ }
274
+
275
+
241
276
// Configuring PWM frequency, resolution and alignment
242
277
// - BLDC driver - 6PWM setting
243
278
// - hardware specific
@@ -294,40 +329,6 @@ int _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const
294
329
}
295
330
296
331
297
- // configuring high frequency pwm timer
298
- // https://hackaday.io/project/169905-esp-32-bldc-robot-actuator-controller
299
- void _configureTimerFrequency6PWM (long pwm_frequency, mcpwm_dev_t * mcpwm_num, mcpwm_unit_t mcpwm_unit){
300
-
301
- mcpwm_config_t pwm_config;
302
-
303
- pwm_config.frequency = 4000 ; // frequency = 20000Hz
304
- pwm_config.cmpr_a = 50.0 ; // duty cycle of PWMxA = 50.0%
305
- pwm_config.cmpr_b = 50.0 ; // duty cycle of PWMxB = 50.0%
306
- pwm_config.counter_mode = MCPWM_UP_COUNTER; // MCPWM_UP_DOWN_COUNTER; // Up-down counter (triangle wave)
307
- pwm_config.duty_mode = MCPWM_DUTY_MODE_0; // Active HIGH
308
- mcpwm_init (MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config); // Configure PWM0A & PWM0B with above settings
309
- mcpwm_init (MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config); // Configure PWM0A & PWM0B with above settings
310
- mcpwm_init (MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config); // Configure PWM0A & PWM0B with above settings
311
- mcpwm_deadtime_enable (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 40 , 40 );
312
- mcpwm_deadtime_enable (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 40 , 40 );
313
- mcpwm_deadtime_enable (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, 40 , 40 );
314
-
315
- mcpwm_sync_enable (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_SYNC_INT0, 0 );
316
- mcpwm_sync_enable (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_SELECT_SYNC_INT0, 0 );
317
- mcpwm_sync_enable (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_SELECT_SYNC_INT0, 0 );
318
-
319
- MCPWM0.timer [0 ].sync .out_sel = 1 ;
320
- delayMicroseconds (1000 );
321
- MCPWM0.timer [0 ].sync .out_sel = 0 ;
322
- mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, 50 );
323
- mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, 50 );
324
- mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_A, 50 );
325
- mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_1, MCPWM_OPR_B, 50 );
326
- mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_OPR_A, 50 );
327
- mcpwm_set_duty (MCPWM_UNIT_0, MCPWM_TIMER_2, MCPWM_OPR_B, 50 );
328
- }
329
-
330
-
331
332
// Function setting the duty cycle to the pwm pin (ex. analogWrite())
332
333
// - BLDC driver - 6PWM setting
333
334
// - hardware specific
0 commit comments