@@ -97,16 +97,17 @@ ClockDivAndRange getClockDivAndRange(uint32_t pwm_frequency, uint8_t timer_chann
97
97
else {
98
98
SimpleFOCDebug::println (" DRV: PWM frequency too low" );
99
99
}
100
-
101
100
return result;
102
101
};
103
102
104
103
105
- bool configureTimerPin (RenesasHardwareDriverParams* params, uint8_t index) {
104
+ bool configureTimerPin (RenesasHardwareDriverParams* params, uint8_t index, bool active_high, bool complementary = false , bool complementary_active_high = true ) {
106
105
uint8_t pin = params->pins [index];
106
+ uint8_t pin_C;
107
107
std::array<uint16_t , 3 > pinCfgs = getPinCfgs (pin, PIN_CFG_REQ_PWM);
108
+ std::array<uint16_t , 3 > pinCfgs_C;
108
109
if (pinCfgs[0 ] == 0 ) {
109
- SIMPLEFOC_DEBUG (" DRV: no PWM on pin" );
110
+ SIMPLEFOC_DEBUG (" DRV: no PWM on pin " , pin );
110
111
return false ;
111
112
}
112
113
if (IS_PIN_AGT_PWM (pinCfgs[0 ])) {
@@ -121,24 +122,46 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index) {
121
122
return false ;
122
123
}
123
124
125
+ if (complementary) {
126
+ pin_C = params->pins [index+1 ];
127
+ pinCfgs_C = getPinCfgs (pin_C, PIN_CFG_REQ_PWM);
128
+ if (pinCfgs_C[0 ] == 0 ) {
129
+ SIMPLEFOC_DEBUG (" DRV: no PWM on pin " , pin_C);
130
+ return false ;
131
+ }
132
+ if (IS_PIN_AGT_PWM (pinCfgs_C[0 ]) || GET_CHANNEL (pinCfgs_C[0 ])!=timer_channel) {
133
+ SIMPLEFOC_DEBUG (" DRV: comp. channel different" );
134
+ return false ;
135
+ }
136
+ }
137
+ TimerPWMChannel_t pwm_output = IS_PWM_ON_A (pinCfgs[0 ]) ? CHANNEL_A : CHANNEL_B;
138
+ if (complementary) {
139
+ TimerPWMChannel_t pwm_output_C = IS_PWM_ON_A (pinCfgs_C[0 ]) ? CHANNEL_A : CHANNEL_B;
140
+ if (pwm_output != CHANNEL_A || pwm_output_C != CHANNEL_B) {
141
+ SIMPLEFOC_DEBUG (" DRV: output A/B mismatch" );
142
+ return false ;
143
+ }
144
+ }
145
+
124
146
// configure GPIO pin
125
- // pinMode(pin, OUTPUT);
126
147
fsp_err_t err = R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[pin].pin , (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_GPT1));
148
+ if ((err == FSP_SUCCESS) && complementary)
149
+ err = R_IOPORT_PinCfg (&g_ioport_ctrl, g_pin_cfg[pin_C].pin , (uint32_t ) (IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_GPT1));
127
150
if (err != FSP_SUCCESS) {
128
151
SIMPLEFOC_DEBUG (" DRV: pin config failed" );
129
152
return false ;
130
153
}
131
154
132
- TimerPWMChannel_t pwm_output = IS_PWM_ON_A (pinCfgs[0 ]) ? CHANNEL_A : CHANNEL_B;
133
-
134
155
135
156
// configure timer channel - frequency / top value
136
157
ClockDivAndRange timings = getClockDivAndRange (params->pwm_frequency , timer_channel);
137
158
#if defined(SIMPLEFOC_RENESAS_DEBUG)
138
159
SimpleFOCDebug::println (" ---PWM Config---" );
139
160
SimpleFOCDebug::println (" DRV: pwm pin: " , pin);
161
+ if (complementary)
162
+ SimpleFOCDebug::println (" DRV: compl. pin: " , pin_C);
140
163
SimpleFOCDebug::println (" DRV: pwm channel: " , timer_channel);
141
- SimpleFOCDebug::print (" DRV: pwm A/B: " ); SimpleFOCDebug::println (( pwm_output==CHANNEL_A)?" A" :" B" );
164
+ SimpleFOCDebug::print (" DRV: pwm A/B: " ); SimpleFOCDebug::println (complementary? " A+B " :(( pwm_output==CHANNEL_A)?" A" :" B" ) );
142
165
SimpleFOCDebug::println (" DRV: pwm freq: " , (int )params->pwm_frequency );
143
166
SimpleFOCDebug::println (" DRV: pwm range: " , (int )timings.range );
144
167
SimpleFOCDebug::println (" DRV: pwm clkdiv: " , timings.clk_div );
@@ -171,35 +194,45 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index) {
171
194
t->pwm_cfg .interrupt_skip_adc = GPT_INTERRUPT_SKIP_ADC_NONE;
172
195
t->pwm_cfg .gtioca_disable_setting = GPT_GTIOC_DISABLE_PROHIBITED;
173
196
t->pwm_cfg .gtiocb_disable_setting = GPT_GTIOC_DISABLE_PROHIBITED;
197
+ // configure dead-time if both outputs are used
198
+ if (complementary) {
199
+ uint32_t dt = params->dead_zone * timings.range ;
200
+ t->pwm_cfg .dead_time_count_up = dt;
201
+ t->pwm_cfg .dead_time_count_down = dt;
202
+ }
174
203
175
-
176
-
177
- // configure timer channel - polarity
204
+ // configure timer channel - outputs and polarity
178
205
t->ext_cfg .gtior_setting .gtior = 0L ;
179
- if (pwm_output == CHANNEL_A) {
180
- t->duty_pin = GPT_IO_PIN_GTIOCA;
181
- t->ext_cfg .gtioca .output_enabled = true ;
182
- t->ext_cfg .gtiocb .output_enabled = false ;
183
- t->ext_cfg .gtior_setting .gtior_b .gtioa = 0x03 | (SIMPLEFOC_PWM_ACTIVE_HIGH ? 0x00 : 0x08 );
184
- t->ext_cfg .gtior_setting .gtior_b .oadflt = SIMPLEFOC_PWM_ACTIVE_HIGH ? 0x00 : 0x01 ;
185
- t->ext_cfg .gtior_setting .gtior_b .oahld = 0x0 ;
186
- t->ext_cfg .gtior_setting .gtior_b .oadf = 0x0 ;
187
- t->ext_cfg .gtior_setting .gtior_b .nfaen = 0x0 ;
188
- }
206
+ if (!complementary) {
207
+ if (pwm_output == CHANNEL_A) {
208
+ t->duty_pin = GPT_IO_PIN_GTIOCA;
209
+ t->ext_cfg .gtioca .output_enabled = true ;
210
+ t->ext_cfg .gtiocb .output_enabled = false ;
211
+ t->ext_cfg .gtior_setting .gtior_b .gtioa = 0x03 | (active_high ? 0x00 : 0x10 );
212
+ t->ext_cfg .gtior_setting .gtior_b .oadflt = active_high ? 0x00 : 0x01 ;
213
+ // t->ext_cfg.gtior_setting.gtior_b.oahld = 0x0;
214
+ // t->ext_cfg.gtior_setting.gtior_b.oadf = 0x0;
215
+ // t->ext_cfg.gtior_setting.gtior_b.nfaen = 0x0;
216
+ }
217
+ else {
218
+ t->duty_pin = GPT_IO_PIN_GTIOCB;
219
+ t->ext_cfg .gtiocb .output_enabled = true ;
220
+ t->ext_cfg .gtioca .output_enabled = false ;
221
+ t->ext_cfg .gtior_setting .gtior_b .gtiob = 0x03 | (active_high ? 0x00 : 0x10 );
222
+ t->ext_cfg .gtior_setting .gtior_b .obdflt = active_high ? 0x00 : 0x01 ;
223
+ }
224
+ }
189
225
else {
190
- t->duty_pin = GPT_IO_PIN_GTIOCB;
191
- t->ext_cfg .gtiocb .output_enabled = true ;
192
- t->ext_cfg .gtioca .output_enabled = false ;
193
- t->ext_cfg .gtior_setting .gtior_b .gtiob = 0x03 | (SIMPLEFOC_PWM_ACTIVE_HIGH ? 0x00 : 0x08 );
194
- t->ext_cfg .gtior_setting .gtior_b .obdflt = SIMPLEFOC_PWM_ACTIVE_HIGH ? 0x00 : 0x01 ;
195
- t->ext_cfg .gtior_setting .gtior_b .obhld = 0x0 ;
196
- t->ext_cfg .gtior_setting .gtior_b .obdf = 0x0 ;
197
- t->ext_cfg .gtior_setting .gtior_b .nfben = 0x0 ;
198
- }
199
- // t->duty_pin = GPT_IO_PIN_GTIOCA_AND_GTIOCB;
200
- // TODO configure timer channel - dead-time if both outputs are used
201
- memset (&(t->ctrl ), 0 , sizeof (gpt_instance_ctrl_t ));
226
+ t->duty_pin = GPT_IO_PIN_GTIOCA_AND_GTIOCB;
227
+ t->ext_cfg .gtioca .output_enabled = true ;
228
+ t->ext_cfg .gtiocb .output_enabled = true ;
229
+ t->ext_cfg .gtior_setting .gtior_b .gtioa = 0x03 | (active_high ? 0x00 : 0x10 );
230
+ t->ext_cfg .gtior_setting .gtior_b .oadflt = active_high ? 0x00 : 0x01 ;
231
+ t->ext_cfg .gtior_setting .gtior_b .gtiob = 0x03 | (complementary_active_high ? 0x00 : 0x10 );
232
+ t->ext_cfg .gtior_setting .gtior_b .obdflt = complementary_active_high ? 0x00 : 0x01 ;
233
+ }
202
234
235
+ memset (&(t->ctrl ), 0 , sizeof (gpt_instance_ctrl_t ));
203
236
err = R_GPT_Open (&(t->ctrl ),&(t->timer_cfg ));
204
237
if ((err != FSP_ERR_ALREADY_OPEN) && (err != FSP_SUCCESS)) {
205
238
SIMPLEFOC_DEBUG (" DRV: open failed" );
@@ -210,11 +243,6 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index) {
210
243
SimpleFOCDebug::println (" DRV: timer already open" );
211
244
}
212
245
#endif
213
- // err = R_GPT_Enable(&(t->ctrl));
214
- // if (err != FSP_SUCCESS) {
215
- // SIMPLEFOC_DEBUG("DRV: enable failed");
216
- // return false;
217
- // }
218
246
err = R_GPT_PeriodSet (&(t->ctrl ), t->timer_cfg .period_counts );
219
247
if (err != FSP_SUCCESS) {
220
248
SIMPLEFOC_DEBUG (" DRV: period set failed" );
@@ -225,17 +253,21 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index) {
225
253
SIMPLEFOC_DEBUG (" DRV: pin enable failed" );
226
254
return false ;
227
255
}
256
+
257
+ channel_used[timer_channel] = true ;
228
258
params->timer_config [index] = t;
229
259
params->channels [index] = timer_channel;
230
- channel_used[timer_channel] = true ;
260
+ if (complementary) {
261
+ params->timer_config [index+1 ] = t;
262
+ params->channels [index+1 ] = timer_channel;
263
+ }
231
264
232
265
return true ;
233
266
}
234
267
235
268
269
+ // start the timer channels for the motor, synchronously
236
270
bool startTimerChannels (RenesasHardwareDriverParams* params, int num_channels) {
237
-
238
- // start the channels
239
271
uint32_t mask = 0 ;
240
272
for (int i = 0 ; i < num_channels; i++) {
241
273
RenesasTimerConfig* t = params->timer_config [i];
@@ -256,6 +288,18 @@ bool startTimerChannels(RenesasHardwareDriverParams* params, int num_channels) {
256
288
}
257
289
258
290
291
+ // check if the given pins are on the same timer channel
292
+ bool isHardware6Pwm (const int pin1, const int pin2) {
293
+ std::array<uint16_t , 3 > pinCfgs1 = getPinCfgs (pin1, PIN_CFG_REQ_PWM);
294
+ std::array<uint16_t , 3 > pinCfgs2 = getPinCfgs (pin2, PIN_CFG_REQ_PWM);
295
+ if (pinCfgs1[0 ] == 0 || pinCfgs2[0 ] == 0 )
296
+ return false ;
297
+ if (IS_PIN_AGT_PWM (pinCfgs1[0 ]) || IS_PIN_AGT_PWM (pinCfgs2[0 ]))
298
+ return false ;
299
+ uint8_t timer_channel1 = GET_CHANNEL (pinCfgs1[0 ]);
300
+ uint8_t timer_channel2 = GET_CHANNEL (pinCfgs2[0 ]);
301
+ return timer_channel1==timer_channel2;
302
+ }
259
303
260
304
261
305
@@ -264,7 +308,7 @@ void* _configure1PWM(long pwm_frequency, const int pinA) {
264
308
params->pins [0 ] = pinA;
265
309
params->pwm_frequency = (pwm_frequency==NOT_SET)?RENESAS_DEFAULT_PWM_FREQUENCY:pwm_frequency;
266
310
bool success = true ;
267
- success = configureTimerPin (params, 0 );
311
+ success = configureTimerPin (params, 0 , SIMPLEFOC_PWM_ACTIVE_HIGH );
268
312
if (success)
269
313
success = startTimerChannels (params, 1 );
270
314
if (!success)
@@ -278,11 +322,10 @@ void* _configure2PWM(long pwm_frequency,const int pinA, const int pinB) {
278
322
params->pins [0 ] = pinA; params->pins [1 ] = pinB;
279
323
params->pwm_frequency = (pwm_frequency==NOT_SET)?RENESAS_DEFAULT_PWM_FREQUENCY:pwm_frequency;
280
324
bool success = true ;
281
- success = configureTimerPin (params, 0 );
282
- if (success)
283
- success = configureTimerPin (params, 1 );
284
- if (success)
285
- success = startTimerChannels (params, 2 );
325
+ success = configureTimerPin (params, 0 , SIMPLEFOC_PWM_ACTIVE_HIGH);
326
+ success &= configureTimerPin (params, 1 , SIMPLEFOC_PWM_ACTIVE_HIGH);
327
+ if (!success)
328
+ success &= startTimerChannels (params, 2 );
286
329
if (!success)
287
330
return SIMPLEFOC_DRIVER_INIT_FAILED;
288
331
return params;
@@ -294,11 +337,9 @@ void* _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const in
294
337
params->pins [0 ] = pinA; params->pins [1 ] = pinB; params->pins [2 ] = pinC;
295
338
params->pwm_frequency = (pwm_frequency==NOT_SET)?RENESAS_DEFAULT_PWM_FREQUENCY:pwm_frequency;
296
339
bool success = true ;
297
- success = configureTimerPin (params, 0 );
298
- if (success)
299
- success = configureTimerPin (params, 1 );
300
- if (success)
301
- success = configureTimerPin (params, 2 );
340
+ success = configureTimerPin (params, 0 , SIMPLEFOC_PWM_ACTIVE_HIGH);
341
+ success &= configureTimerPin (params, 1 , SIMPLEFOC_PWM_ACTIVE_HIGH);
342
+ success &= configureTimerPin (params, 2 , SIMPLEFOC_PWM_ACTIVE_HIGH);
302
343
if (success)
303
344
success = startTimerChannels (params, 3 );
304
345
if (!success)
@@ -312,13 +353,10 @@ void* _configure4PWM(long pwm_frequency, const int pin1A, const int pin1B, const
312
353
params->pins [0 ] = pin1A; params->pins [1 ] = pin1B; params->pins [2 ] = pin2A; params->pins [3 ] = pin2B;
313
354
params->pwm_frequency = (pwm_frequency==NOT_SET)?RENESAS_DEFAULT_PWM_FREQUENCY:pwm_frequency;
314
355
bool success = true ;
315
- success = configureTimerPin (params, 0 );
316
- if (success)
317
- success = configureTimerPin (params, 1 );
318
- if (success)
319
- success = configureTimerPin (params, 2 );
320
- if (success)
321
- success = configureTimerPin (params, 3 );
356
+ success = configureTimerPin (params, 0 , SIMPLEFOC_PWM_ACTIVE_HIGH);
357
+ success &= configureTimerPin (params, 1 , SIMPLEFOC_PWM_ACTIVE_HIGH);
358
+ success &= configureTimerPin (params, 2 , SIMPLEFOC_PWM_ACTIVE_HIGH);
359
+ success &= configureTimerPin (params, 3 , SIMPLEFOC_PWM_ACTIVE_HIGH);
322
360
if (success)
323
361
success = startTimerChannels (params, 4 );
324
362
if (!success)
@@ -328,10 +366,38 @@ void* _configure4PWM(long pwm_frequency, const int pin1A, const int pin1B, const
328
366
329
367
330
368
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){
331
- GenericDriverParams* params = new GenericDriverParams {
332
- .pins = { pinA_h, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
333
- .pwm_frequency = pwm_frequency
334
- };
369
+ RenesasHardwareDriverParams* params = new RenesasHardwareDriverParams;
370
+ params->pins [0 ] = pinA_h; params->pins [1 ] = pinA_l; params->pins [2 ] = pinB_h; params->pins [3 ] = pinB_l; params->pins [4 ] = pinC_h; params->pins [5 ] = pinC_l;
371
+ params->pwm_frequency = (pwm_frequency==NOT_SET)?RENESAS_DEFAULT_PWM_FREQUENCY:pwm_frequency;
372
+ params->dead_zone = (dead_zone==NOT_SET)?RENESAS_DEFAULT_DEAD_ZONE:dead_zone;
373
+
374
+ bool success = true ;
375
+ if (isHardware6Pwm (pinA_h, pinA_l)) {
376
+ success &= configureTimerPin (params, 0 , SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH, true , !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH));
377
+ }
378
+ else {
379
+ success &= configureTimerPin (params, 0 , SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH);
380
+ success &= configureTimerPin (params, 1 , !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH)); // reverse polarity on low side gives desired active high/low behaviour
381
+ }
382
+ if (isHardware6Pwm (pinB_h, pinB_l)) {
383
+ success &= configureTimerPin (params, 2 , SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH, true , !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH));
384
+ }
385
+ else {
386
+ success &= configureTimerPin (params, 2 , SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH);
387
+ success &= configureTimerPin (params, 3 , !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH));
388
+ }
389
+ if (isHardware6Pwm (pinC_h, pinC_l)) {
390
+ success &= configureTimerPin (params, 4 , SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH, true , !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH));
391
+ }
392
+ else {
393
+ success &= configureTimerPin (params, 4 , SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH);
394
+ success &= configureTimerPin (params, 5 , !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH));
395
+ }
396
+
397
+ if (success)
398
+ success = startTimerChannels (params, 6 );
399
+ if (!success)
400
+ return SIMPLEFOC_DRIVER_INIT_FAILED;
335
401
return params;
336
402
}
337
403
@@ -364,24 +430,18 @@ void _writeDutyCycle2PWM(float dc_a, float dc_b, void* params){
364
430
void _writeDutyCycle3PWM (float dc_a, float dc_b, float dc_c, void * params){
365
431
RenesasTimerConfig* t = ((RenesasHardwareDriverParams*)params)->timer_config [0 ];
366
432
uint32_t duty_cycle_counts = (uint32_t )(dc_a * (float )(t->timer_cfg .period_counts ));
367
- // SimpleFOCDebug::println("Duty A: ", (int)duty_cycle_counts);
368
433
if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts, t->duty_pin ) != FSP_SUCCESS) {
369
434
// error
370
- Serial.println (" pwm set error A" );
371
435
}
372
436
t = ((RenesasHardwareDriverParams*)params)->timer_config [1 ];
373
437
duty_cycle_counts = (uint32_t )(dc_b * (float )(t->timer_cfg .period_counts ));
374
- // SimpleFOCDebug::println("Duty B: ", (int)duty_cycle_counts);
375
438
if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts, t->duty_pin ) != FSP_SUCCESS) {
376
439
// error
377
- Serial.println (" pwm set error B" );
378
440
}
379
441
t = ((RenesasHardwareDriverParams*)params)->timer_config [2 ];
380
442
duty_cycle_counts = (uint32_t )(dc_c * (float )(t->timer_cfg .period_counts ));
381
- // SimpleFOCDebug::println("Duty C: ", (int)duty_cycle_counts);
382
443
if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts, t->duty_pin ) != FSP_SUCCESS) {
383
444
// error
384
- Serial.println (" pwm set error C" );
385
445
}
386
446
}
387
447
@@ -410,7 +470,50 @@ void _writeDutyCycle4PWM(float dc_1a, float dc_1b, float dc_2a, float dc_2b, vo
410
470
}
411
471
412
472
473
+ // TODO phase-state
413
474
void _writeDutyCycle6PWM (float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void * params){
475
+ RenesasTimerConfig* t = ((RenesasHardwareDriverParams*)params)->timer_config [0 ];
476
+ uint32_t dt = (uint32_t )(((RenesasHardwareDriverParams*)params)->dead_zone * (float )(t->timer_cfg .period_counts ));
477
+ uint32_t duty_cycle_counts = (uint32_t )(dc_a * (float )(t->timer_cfg .period_counts ));
478
+ bool hw_deadtime = ((RenesasHardwareDriverParams*)params)->channels [0 ] == ((RenesasHardwareDriverParams*)params)->channels [1 ];
479
+ uint32_t dt_act = (duty_cycle_counts>0 && !hw_deadtime)?dt:0 ;
480
+ if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts - dt_act, t->duty_pin ) != FSP_SUCCESS) {
481
+ // error
482
+ }
483
+ if (!hw_deadtime) {
484
+ t = ((RenesasHardwareDriverParams*)params)->timer_config [1 ];
485
+ if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts + dt_act, t->duty_pin ) != FSP_SUCCESS) {
486
+ // error
487
+ }
488
+ }
489
+
490
+ t = ((RenesasHardwareDriverParams*)params)->timer_config [2 ];
491
+ duty_cycle_counts = (uint32_t )(dc_b * (float )(t->timer_cfg .period_counts ));
492
+ hw_deadtime = ((RenesasHardwareDriverParams*)params)->channels [2 ] == ((RenesasHardwareDriverParams*)params)->channels [3 ];
493
+ dt_act = (duty_cycle_counts>0 && !hw_deadtime)?dt:0 ;
494
+ if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts - dt_act, t->duty_pin ) != FSP_SUCCESS) {
495
+ // error
496
+ }
497
+ if (!hw_deadtime) {
498
+ t = ((RenesasHardwareDriverParams*)params)->timer_config [3 ];
499
+ if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts + dt_act, t->duty_pin ) != FSP_SUCCESS) {
500
+ // error
501
+ }
502
+ }
503
+
504
+ t = ((RenesasHardwareDriverParams*)params)->timer_config [4 ];
505
+ duty_cycle_counts = (uint32_t )(dc_c * (float )(t->timer_cfg .period_counts ));
506
+ hw_deadtime = ((RenesasHardwareDriverParams*)params)->channels [4 ] == ((RenesasHardwareDriverParams*)params)->channels [5 ];
507
+ dt_act = (duty_cycle_counts>0 && !hw_deadtime)?dt:0 ;
508
+ if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts, t->duty_pin ) != FSP_SUCCESS) {
509
+ // error
510
+ }
511
+ if (!hw_deadtime) {
512
+ t = ((RenesasHardwareDriverParams*)params)->timer_config [5 ];
513
+ if (R_GPT_DutyCycleSet (&(t->ctrl ), duty_cycle_counts + dt_act, t->duty_pin ) != FSP_SUCCESS) {
514
+ // error
515
+ }
516
+ }
414
517
415
518
}
416
519
0 commit comments