File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ void analogWriteDAC(PinName pin, int val) {
3434 if (dac == NULL ) {
3535 dac = new mbed::AnalogOut (pin);
3636 }
37- float percent = (float )val/(float )(1 << write_resolution);
37+ float percent = (float )val/(float )(( 1 << write_resolution)- 1 );
3838 if (percent > 1 .0f ) {
3939 percent = 1 .0f ;
4040 }
@@ -50,7 +50,7 @@ void analogWrite(PinName pin, int val)
5050 } else {
5151 mbed::PwmOut* pwm = new mbed::PwmOut (pin);
5252 pwm->period_ms (2 ); // 500Hz
53- float percent = (float )val/(float )(1 << write_resolution);
53+ float percent = (float )val/(float )(( 1 << write_resolution)- 1 );
5454 pwm->write (percent);
5555 }
5656}
@@ -66,7 +66,7 @@ void analogWrite(pin_size_t pin, int val)
6666 return ;
6767 }
6868#endif
69- float percent = (float )val/(float )(1 << write_resolution);
69+ float percent = (float )val/(float )(( 1 << write_resolution)- 1 );
7070 mbed::PwmOut* pwm = digitalPinToPwm (pin);
7171 if (pwm == NULL ) {
7272 pwm = new mbed::PwmOut (digitalPinToPinName (pin));
You can’t perform that action at this time.
0 commit comments