ESP32 PWM Dimmer for meanwell increase not linear

Greating everyone, i've built a remote dimmer using an octocoupler and an esp32 + esphome firmware to drive the intensity of LED through the meanwell driver, so far so good, but i've tried on 2 different lights/drivers and the increase is not linear and does not match the dimmer sold with it, i mean 40% on my potentiometer produce as much light as 86% using the esp as dimmer.. (lux output measured using the same phone for all measurements)

What could it be ? could it be the software that need some configuration tweaks or something else, circuit below for information :

PS: meanwell driver is a HLG-480-48-B and HLG-120-48B

Any helps will be greatly appreciated, thanks upfront

Your potentiometer seems to be logarithmic instead of linear. Test it's resistance using a DVM.
Paul

Reading the data sheet for HLG-480-48-B I feel it's wrong to use PWM. The data sheet shows a resistor between Dim- and Dim+.

@Railroader
if you look at the datasheet, there's 3 method to dim the driver : https://www.meanwell.fr/content/files/pdfs/productPdfs/MW/HLG-480H/HLG-480H-spec.pdf

10v PWM signal (page 5)
Additive resistance
and
additive 0-10 VDC

BTW : I was advised by Wawa on how to build the circuit.

The stock potentiometer that is sold with the driver ? from the datasheet it should be linear it's using the additive resistance method which as a linear curve on the datasheet if im not mistaken

Okey. I didn't read all it looks like. You are right.
PC817 is a friend of mina as well. Nothing strange with it.
Know that the human eye sensitivity is logarithmic. I wonder what principle Your measuring device uses.
Never the less, the hunt for the reason continues.

I don't know about my devices principle, i just use my phone's lux sensor, but i use the same to compare both dimmer, so i should not matter, 40% = 5000 lux where i put my phone, but when i switch to the esp@40% i only get 900lux and need to rise up to 86% to get to 5000 lux, if this is of any helps :slight_smile:

Okey.
Try to step aside the technical aspect. What is the human feeling looking at the behaviour of the project?

1 Like

@Railroader not sure i understand your question but im using the esp to dimmer the intensity of the driver used to power an LED light (480w quantum board) the purpose is to automate the rise of the intensity over a user defined period of time, fade instead of going 0-100% when turning on, stuff like that :slight_smile: all connected to home assistant using esphome as firmware for the esp32.

You are correct that LED brightness is not linear to its voltage\current.
There is a very old but excellent discussion here: Logarithmic scaling for LED dimming?
and here is my version(no delay) of @Grumpy_Mike 's solution in post # 12.

/*
  Change brightness of LED linearly to Human eye
  32 step brightness using 8 bit PWM of Arduino
  brightness step 24 should be twice bright than step 12 to your eye.

  Code was provided in reply #12 by Grumpy Mike: http://forum.arduino.cc\index.php?topic=147818.0
*/


#include <avr/pgmspace.h>
#define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness lookup table function

/*
  5 bit CIE Lightness to 8 bit PWM conversion
  L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
  L* = 903.3(Y/Yn), Y/Yn <= 0.008856
*/

const uint8_t CIEL8[] PROGMEM = {
  0,    1,    2,    3,    4,    5,    7,    9,    12,
  15,    18,    22,    27,    32,    38,    44,    51,    58,
  67,    76,    86,    96,    108,    120,    134,    148,    163,
  180,    197,    216,    235,    255
};

int brightness = 0;             // initial brightness of LED
int fadeAmount = 1;
int led1Pin = 9;

unsigned long startTime = 0;    // timing variables
const long interval = 100;


void setup()  {  
  pinMode(led1Pin, OUTPUT);     // declare pin 9 to be an output:
}

void loop()  {
  unsigned long currentTime = millis();
  if (currentTime - startTime >= interval)
  {
    startTime += interval;                         // increment timing sequence
    analogWrite(led1Pin, CIELPWM(brightness));     // set the brightness of pin 9:, 0-31, 5 bit steps of brightness
    brightness += fadeAmount;                      // change the brightness for next time through the loop:
    if (brightness == 0 || brightness == 31)       // reverse the direction of the fading at the ends of the fade:
    {
      fadeAmount = -fadeAmount ;
    }
  }
}
1 Like

Thanks alot, i also asked the developpers of esphome on github and his reply was to use gamma_correct with a value he calculated using the data point i gave him :
"40% on the pot = 5000 lux but 40% with esphome = 900 lux and i need to rise up to 86% to get the 5000x i get from 40% with the pot."
his formula is : log(0.86/0.4) / log(5000/900) ≈ 0.44

I have tried and it's almost perfectly linear, i would need to recompute the value using precise measurement, the numbers i provided were pulled out of my memories and rounded up for ease of writing)

So if anyone is using the monochromatic/ledc component from esphome to drive a meanwell and having non linear curve issue. try applying his formula.

Take a percentage (example : 40%), measure what you get from the pot (5000 lux), and from the esp (900 lux), then match the esp to the pot (86%) and note the value then calculate
Log(0.86/0.4)- log(5000/900) ≈ gamme_correction to apply for linear dimming :slight_smile: