Skip to content

Commit 8010c3d

Browse files
author
Richard Unger
committed
clean up polarity
1 parent 57be301 commit 8010c3d

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/drivers/hardware_specific/renesas/renesas.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ bool configureTimerPin(RenesasHardwareDriverParams* params, uint8_t index, bool
226226
t->duty_pin = GPT_IO_PIN_GTIOCA_AND_GTIOCB;
227227
t->ext_cfg.gtioca.output_enabled = true;
228228
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;
229+
t->ext_cfg.gtior_setting.gtior_b.gtioa = 0x03 | (!complementary_active_high ? 0x00 : 0x10);
230+
t->ext_cfg.gtior_setting.gtior_b.oadflt = !complementary_active_high ? 0x00 : 0x01;
231+
t->ext_cfg.gtior_setting.gtior_b.gtiob = 0x03 | (active_high ? 0x00 : 0x10);
232+
t->ext_cfg.gtior_setting.gtior_b.obdflt = active_high ? 0x00 : 0x01;
233233
}
234234

235235
memset(&(t->ctrl), 0, sizeof(gpt_instance_ctrl_t));
@@ -372,26 +372,25 @@ void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, cons
372372
params->dead_zone = (dead_zone==NOT_SET)?RENESAS_DEFAULT_DEAD_ZONE:dead_zone;
373373

374374
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-
}
375+
if (isHardware6Pwm(pinA_h, pinA_l))
376+
success &= configureTimerPin(params, 0, SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH, true, SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH);
378377
else {
379378
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));
379+
success &= configureTimerPin(params, 1, !SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH); // reverse polarity on low side gives desired active high/low behaviour
384380
}
381+
382+
if (isHardware6Pwm(pinB_h, pinB_l))
383+
success &= configureTimerPin(params, 2, SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH, true, SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH);
385384
else {
386385
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));
386+
success &= configureTimerPin(params, 3, !SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH);
391387
}
388+
389+
if (isHardware6Pwm(pinC_h, pinC_l))
390+
success &= configureTimerPin(params, 4, SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH, true, SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH);
392391
else {
393392
success &= configureTimerPin(params, 4, SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH);
394-
success &= configureTimerPin(params, 5, !(SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH));
393+
success &= configureTimerPin(params, 5, !SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH);
395394
}
396395

397396
if (success)

0 commit comments

Comments
 (0)