Fixed PWM calculation for Lumini p30 LED reef lamp.

This commit is contained in:
Kai Lauterbach 2023-04-25 16:40:28 +02:00
parent 0188bb763f
commit 9e998f9c92

View file

@ -36,11 +36,10 @@ IPAddress dns ( 192, 168, 0, 1);
#define SCENE_NIGHTLY 2
// 10 bit PWM
#define PWM_OFF 0 // 0V
#define PWM_MIN 640 // 15V - minimum light amount (~1%)
#define PWM_MAX 1023 // 24V - maximum light amount (100%)
#define PWM_INC 4 // 24V-15V = 9V range; 9V ≙ 1024/640 = 383 counts; 383/100% = 3,83 counts (1%) / % => round up 4 counts / % (~1%)
#define BRI_TO_PWM_FACTOR 4 // 0-255 uint8_t brightness data x4 is 0 to 1024
#define PWM_OFF 0 // 0V
#define PWM_MIN 640 // 15V - minimum light amount (~1%)
#define PWM_MAX 1023 // 24V - maximum light amount (100%)
#define BRI_TO_PWM_FACTOR 4 // 24V-15V = 9V range; 9V ≙ 1024-640 = 383 counts; 383/100% = 3,83 counts (1%) / % => round up 4 counts / % (~1%)
//********************************//
@ -104,15 +103,17 @@ void lightEngine()
{
in_transition = true;
current_bri[i] += step_level[i];
if ((step_level[i] > 0.0 && current_bri[i] > bri[i]) || (step_level[i] < 0.0 && current_bri[i] < bri[i]))
if ((step_level[i] > 0.0 && current_bri[i] > bri[i]) ||
(step_level[i] < 0.0 && current_bri[i] < bri[i]))
{
current_bri[i] = bri[i];
}
analogWrite(pins[i], (int)(current_bri[i] * 4)); // TODO warum * 4?
analogWrite(pins[i], calcPWM(current_bri[i]));
}
} else {
if (current_bri[i] != 0 )
if (current_bri[i] != 0)
{
in_transition = true;
current_bri[i] -= step_level[i];
@ -120,7 +121,8 @@ void lightEngine()
{
current_bri[i] = 0;
}
analogWrite(pins[i], (int)(current_bri[i] * 4)); // TODO warum * 4?
analogWrite(pins[i], calcPWM(current_bri[i]));
}
}
}
@ -134,6 +136,22 @@ void lightEngine()
//********************************//
uint16_t calcPWM(float tbri)
{
uint16_t tmp_pwm = PWM_OFF;
if (tbri > 0.0)
{
tmp_pwm = PWM_MIN + (int)(tbri * BRI_TO_PWM_FACTOR);
}
if (tmp_pwm > PWM_MAX)
{
tmp_pwm = PWM_MAX;
}
return tmp_pwm;
}
//********************************//
void read_eeprom_config()
{
for (uint8_t light = 0; light < LIGHTS_COUNT; light++)