Skip to content

Commit 88816bf

Browse files
committed
Fix drv8908 duty cycle mapping
1 parent 0a8ab65 commit 88816bf

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

ftduino/libraries/Ftduino/Ftduino.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,24 +588,18 @@ void Ftduino::output_set(uint8_t port, uint8_t mode, uint8_t pwm) {
588588
if(driver_chip == CHIP_DRV8908)
589589
#endif
590590
{
591+
pwm = 255 * (uint16_t)pwm / 64; // map 0..64 -> 0..255
591592
uint8_t op_ctrl = (port<=3)?OP_CTRL_1:OP_CTRL_2;
592593
uint8_t op_port = port & 3; // 0..3
593594
uint8_t op_mode = (mode==0)?0:((mode==1)?2:1);
594595

595-
// expand duty cycle to 8 bits, so that 00000000 and 11111111 are reached
596-
drv8908_transfer_byte(PWM_DUTY_CTRL_1+port, (pwm<<2)|(pwm&3)); // set duty cycle
596+
drv8908_transfer_byte(PWM_DUTY_CTRL_1+port, pwm); // set duty cycle
597597

598598
// set output mode, ftduino os off=0, hi=1, low=2, drv is off,low,hi
599599
uint8_t tmp = drv8908_transfer_byte(0x40 | op_ctrl, 0); // 0x40 = read flag
600600
tmp &= ~(3 << (2*op_port));
601601
tmp |= op_mode << (2*op_port);
602602
drv8908_transfer_byte(op_ctrl, tmp);
603-
604-
// self.set(output, mode)
605-
// self.enable_pwm(output, True)
606-
// self.map_pwm(output, output) # use pwm ch 1 for O1, ch 2 for O2, ...
607-
// self.set_pwm_freq(output, DRV8908.FREQ_200HZ) # 200Hz is fine for motors and lamps
608-
// self.set_pwm_duty(output, value)
609603
}
610604
#endif
611605

0 commit comments

Comments
 (0)