From 33499beb32820511c5752575f32c46ecfabc9cad Mon Sep 17 00:00:00 2001 From: Dominik Bartsch Date: Fri, 25 Jun 2021 15:41:34 +0200 Subject: [PATCH] zero duty cycle fix --- include/pwm.h | 7 ++++--- src/pwm.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/pwm.h b/include/pwm.h index 846adec..19c957e 100644 --- a/include/pwm.h +++ b/include/pwm.h @@ -5,12 +5,13 @@ #define SENSOR1 15 #define SENSOR2 12 +#define INT_TIME 20 // interrupt intervall [ms] class Treppe { private: uint8_t stairs; - uint16_t time_per_stair = 300; // dimmtime per stair [ms] - uint16_t idle_brightness = 200; - uint16_t active_brightness = 2048; + uint16_t time_per_stair = 200; // dimmtime per stair [ms] + uint16_t idle_brightness = 0; + uint16_t active_brightness = 1048; uint8_t direction = 0; uint8_t switch_direction = 0; diff --git a/src/pwm.cpp b/src/pwm.cpp index 4b911f3..13c7397 100644 --- a/src/pwm.cpp +++ b/src/pwm.cpp @@ -20,12 +20,10 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){ pwmController.setChannelPWM(led, (uint16_t)startval); lastled = led; current_pwm = startval; - stepsize = 20*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval + stepsize = INT_TIME*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval return 1; } - if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize) return 0; - // todo: duty cycle zero! if(startval > stopval){ current_pwm -= stepsize; } @@ -34,6 +32,10 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){ } Serial.println((uint16_t)current_pwm); pwmController.setChannelPWM(led, (uint16_t)current_pwm); + if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){ + if(stopval == 0) pwmController.setChannelPWM(led, 0); + return 0; + } return 1; }