diff --git a/rpio.go b/rpio.go index 04314d2..388ff95 100644 --- a/rpio.go +++ b/rpio.go @@ -363,7 +363,7 @@ func SetFreq(pin Pin, freq int) { case 12, 13, 40, 41, 45, 18, 19: // pwm_clk - shared clk for both pwm chanels clkCtlReg += 12 clkDivReg += 13 - StopPwm() + StopPwm() // pwm clk busy wont go down without stopping pwm first defer StartPwm() default: return @@ -418,11 +418,11 @@ func SetDutyCycle(pin Pin, dutyLen, cycleLen uint32) { switch pin { case 12, 18, 40: // chanel pwm0 - pwmDatReg = 4 - pwmRngReg = 5 + pwmRngReg = 4 + pwmDatReg = 5 shift = 0 case 13, 19, 41, 45: // chanel pwm1 - pwmDatReg = 8 + pwmRngReg = 8 pwmDatReg = 9 shift = 8 default: @@ -430,14 +430,17 @@ func SetDutyCycle(pin Pin, dutyLen, cycleLen uint32) { } const ctlMask = 255 // ctl setting has 8 bits for each chanel + const pwen = 1 << 0 // enable pwm const msen = 1 << 7 // use M/S transition instead of pwm algorithm // reset settings - pwmMem[pwmCtlReg] = pwmMem[pwmCtlReg]&^(ctlMask<