Page 1 of 2 12 LastLast
Results 1 to 35 of 36

Thread: PWM controlled LCR-0202 test with temperature indication

  1. #1
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0

    PWM controlled LCR-0202 test with temperature indication

    Hi everybody,

    I'm doing some tests on some cheap LDRs called LCR-0202 (they can be found on various cheap music equipments), that I want to share.
    The purpose is to find a correlation between the PWM used to control them (supplied with 5V), and their resistance.

    The needed material is:
    - an Arduino (I'm using a Mega 2560, but every Arduino can be used, from Nano to Uno to Due, etc...);
    - a DHT22 temperature and humidity sensor;
    - a PCA9685 16 channel 12 bit PWM controller;
    - up to 16 LCR-0202 to be tested (the limit is the number of PWM outputs of the PCA9685 and the number of analog inputs of the Arduino);
    - one LED to have a visual feedback of the actual PWM;
    - a 20x4 LCD screen (can be a 16x2 too, it just needs to be redrawn).

    In the attached photos you'll see the values of four LCR-0202s shown on screen:
    Second line shows the actual PWM command (the lower the value, the lower the current through the led, so the higher the resistance of the LDR), and the actual ambient temperature.
    Third and fourth lines show the actual value in Ohms of the four LDRs.

    This is the code:

    Code:
    #include <Wire.h>
    
    //to manage the LCR-0202s
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
    
    //just to show results
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 20, 4);
    
    //to read ambient temperature
    #include <SimpleDHT.h>
    int pinDHT22 = 2;
    SimpleDHT22 dht22;
    float temperature = 0;
    float humidity = 0;
    
    //just an array of 2^n
    int pwm_values[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4095};
    
    //analog readings in voltage dividers
    float a_read1 = 0;
    float a_read2 = 0;
    float a_read3 = 0;
    float a_read4 = 0;
    
    //LCR-0202 initial resistance values 
    float LCR1_ohm = 0;
    float LCR2_ohm = 0;
    float LCR3_ohm = 0;
    float LCR4_ohm = 0;
    
    //define "leak" resistors in voltage dividers
    float bottomR1_ohm = 1000;
    float bottomR2_ohm = 1000;
    float bottomR3_ohm = 1000;
    float bottomR4_ohm = 1000;
    
    void setup() {
      //PWM startup
      pwm.begin();
      pwm.setPWMFreq(500); //to avoid wavering of the light
    
      //LCD startup
      lcd.init();
      lcd.backlight();
      lcd.clear();
    }
    
    void loop() {
      for (int i = 0; i < 13; i++) {
        for (int led_num = 0; led_num < 6; led_num++) {
          pwm.setPWM(led_num, 0, (4095 - pwm_values[i]));
    
        }
        show_values(i);
      }
    }
    
    void show_values(int i) {
      lcd.clear();
      lcd.print("Robi's LCR-0202 Test");
    
      lcd.setCursor(0, 1);
      lcd.print("PWM ");
      lcd.print(pwm_values[i]);
    
      lcd.setCursor(10, 1);
      dht22.read2(pinDHT22, &temperature, &humidity, NULL);
      lcd.print("Temp ");
      lcd.print(temperature);
    
      lcd.setCursor(0, 2);
      a_read1 = analogRead(0);
      LCR1_ohm = ((1023 * bottomR1_ohm) / a_read1) - bottomR1_ohm;
      lcd.print(LCR1_ohm);
    
      lcd.setCursor(10, 2);
      a_read2 = analogRead(1);
      LCR2_ohm = ((1023 * bottomR2_ohm) / a_read2) - bottomR2_ohm;
      lcd.print(LCR2_ohm);
    
      lcd.setCursor(0, 3);
      a_read3 = analogRead(2);
      LCR3_ohm = ((1023 * bottomR3_ohm) / a_read3) - bottomR3_ohm;
      lcd.print(LCR3_ohm);
    
      lcd.setCursor(10, 3);
      a_read4 = analogRead(3);
      LCR4_ohm = ((1023 * bottomR4_ohm) / a_read4) - bottomR4_ohm;
      lcd.print(LCR4_ohm);
    
      delay(2000);
    }

    0 Not allowed! Not allowed!

  2. #2
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Click image for larger version. 

Name:	LCR-0202 PWM0016.jpeg 
Views:	35 
Size:	96.6 KB 
ID:	46291

    Click image for larger version. 

Name:	LCR-0202 PWM0004.jpeg 
Views:	30 
Size:	91.0 KB 
ID:	46292

    Click image for larger version. 

Name:	LCR-0202 PWM0001.jpeg 
Views:	26 
Size:	93.9 KB 
ID:	46293

    0 Not allowed! Not allowed!

  3. #3
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Click image for larger version. 

Name:	LCR-0202 PWM2048.jpeg 
Views:	21 
Size:	94.0 KB 
ID:	46294

    Click image for larger version. 

Name:	LCR-0202 PWM1024.jpeg 
Views:	19 
Size:	95.1 KB 
ID:	46295

    Click image for larger version. 

Name:	LCR-0202 PWM0128.jpeg 
Views:	25 
Size:	97.5 KB 
ID:	46296

    0 Not allowed! Not allowed!

  4. #4
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Last one, with the lowest resistance.

    Has anyone done some similar tests on those LDRs?

    Click image for larger version. 

Name:	LCR-0202 PWM4095.jpeg 
Views:	27 
Size:	93.4 KB 
ID:	46297

    0 Not allowed! Not allowed!

  5. #5
    Member
    Join Date
    Apr 2015
    Posts
    94
    Thumbs Up/Down
    Received: 1/0
    Given: 0/0
    Cool tests.

    Now, do you feed the input LED directly from 5V ? That means driving the LED with maximum GPIO current available, right?
    I understand the mean-LED-current is directly proportional to Duty Cycle and mean-LED-current to output resistance is given in datasheet - how do your findings match that?

    Honestly I am very surrised by huge spread at low duty/low mean LED current.
    Did you find anything interesting in humidity and temperature dependency?

    0 Not allowed! Not allowed!

  6. #6

  7. #7
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Exactly, and the PWM frequency is set to 500 Hz just because at 50 Hz you can see some "lumen ripple", so I just go one order of magnitude higher.

    The board has some internal 220 Ohm resistors to save the GPIOs, so the maximum current is around 14 mA.
    Just to note, the GPIOs have 10 mA capability as sources and 25 mA as sinks. I've used the latter configuration.

    Looking at page 3 of the datasheet, the shown resistance is higher than what I've seen, but as you can see there are very different values on the four samples.
    What's not as expected is on the lowest PWM side, because I cannot go above 100 kOhm.
    I've noticed that the driver keeps the led slightly on even at zero, probably due to the fact that the library is intended for servos and not for leds.

    No modifications related to humidity (not even tested, the package is perfectly sealed, while I expect a strong dependency on temperature, but I still have to do tests. I have an oven with the "levitation" option, and I will do some further tests with it.

    Of course all the data will be then transmitted through the serial port into the pc, to simplify the download and analysis of the data.

    0 Not allowed! Not allowed!

  8. #8
    Member
    Join Date
    Apr 2015
    Posts
    94
    Thumbs Up/Down
    Received: 1/0
    Given: 0/0
    Quote Originally Posted by Roberto View Post
    What's not as expected is on the lowest PWM side, because I cannot go above 100 kOhm.
    I've noticed that the driver keeps the led slightly on even at zero, probably due to the fact that the library is intended for servos and not for leds.
    I see you use the delay of 2s while the datasheet mentions the dark resistance is achieved after 10s - that might be a factor.
    Another one might be pull-up at ADC - no kidding, some micros will keep the pull-up in adc mode unless set otherwise.

    Just disconnect the input to see if the real dark resistance is getting measured properly.

    Otherwise you're still just at 10bits adc resolution, with effectively no more than 9 bits to be trusted - if you're lucky. Expect no precision above 10k measurement or adjust the lower resistor in divider.



    Edit:

    Another issue: you set the PWM and start the measuring and displaying pretty much immediately, thus giving not time to settle the resistance.
    I suggest you add another delay after setting the PWM value and before the reading and displaying function:

    Code:
    void loop() {
      for (int i = 0; i < 13; i++) {
        for (int led_num = 0; led_num < 6; led_num++) {
          pwm.setPWM(led_num, 0, (4095 - pwm_values[i]));
    
        }
        delay(10000);
        show_values(i);
      }
    }

    0 Not allowed! Not allowed!
    Last edited by darkfenriz; 12-28-2017 at 05:01 PM.

  9. #9
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Thanks darkfenriz,

    I came out with the fact that there's never a complete switch off of the leds (at least I've never succeded into, looking at the feedback leds), so one option is to "mix" two channels on one LDR with an higher series resistor, to have virtually 24 bit of resolution. I tried some solutions found on the net, but none of them really works.

    Good idea the delay before the reading. I've moved the 2 seconds delay out of the show_values to before the call of the subroutine, to help the LDRs stabilize their values.

    As for the 10 seconds delay, it's not needed. I've tested with 10k resistor in series with one LDR and in 2 seconds it switches to infinity (see plots below). The point is that with multiple readings over the time, the resistance is more constant now. I've also increased the PWM frequency, to further dampen any influence on "ripple" on the lumen of the led, so on resistance.

    Here the values I've obtained:
    - first column the PWM value
    - second column the temperature in C
    - third column the resistance of the LDR with 10k in series on the led side;
    - other columns the resistance of other LDRs with only the "onboard" 220 Ohm resistance.

    Code:
    PWM Temp R1_Ohm R2_Ohm R3_Ohm R4_Ohm
    
    0  23.50  inf  92000.00  62937.50  28228.57
    1  23.50  inf  25921.05  23357.14  13208.33
    2  23.50  inf  14044.12  12824.32  8472.22
    4  23.50  inf  10000.00  9128.71  5314.81
    8  23.50  inf  6255.32  4500.00  3428.57
    16  23.50  inf  3758.14  3467.25  2491.47
    32  23.50  inf  2552.08  2343.14  1330.30
    64  23.50  101300.00  1340.96  1325.00  1037.85
    128  23.50  33100.00  1195.28  1126.82  520.06
    256  23.50  14984.37  908.58  386.18  430.77
    512  23.50  6930.23  444.92  497.80  393.73
    1024  23.50  4328.12  461.43  474.06  212.09
    2048  23.50  2788.89  223.68  174.51  139.20
    4095  23.50  1650.26  161.18  152.03  124.18
    
    0  23.50  inf  84250.00  72071.43  30968.75
    1  23.50  inf  27416.67  20312.50  12460.53
    2  23.50  inf  16947.37  12640.00  8385.32
    4  23.50  inf  9882.98  8932.04  5912.16
    8  23.50  inf  6255.32  5730.26  3409.48
    16  23.50  inf  3059.52  2965.12  2289.39
    32  23.50  inf  2090.63  2000.00  1532.18
    64  23.50  101300.00  1459.13  1407.06  1075.05
    128  23.50  32000.00  1096.31  1054.22  797.89
    256  23.50  14984.37  569.02  524.59  484.76
    512  23.50  7317.07  557.08  576.27  438.82
    1024  23.50  4559.78  538.35  203.53  216.41
    2048  23.50  2456.08  217.86  280.35  231.05
    4095  23.50  1650.26  161.18  152.03  124.18
    
    0  23.50  inf  84250.00  67200.00  30000.00
    1  23.50  inf  25230.77  22790.70  13208.33
    2  23.50  inf  14984.37  13614.29  8742.86
    4  23.50  inf  8472.22  7895.65  5515.92
    8  23.50  inf  4982.46  4812.50  3526.55
    16  23.50  inf  2919.54  2860.38  2247.62
    32  23.50  inf  2653.57  1699.21  1429.93
    64  23.50  112666.67  1519.70  1441.53  1100.62
    128  23.50  32000.00  1131.25  1083.50  810.62
    256  23.50  14984.37  952.29  480.46  457.27
    512  23.50  6992.19  474.06  515.56  403.29
    1024  23.50  4412.70  497.80  278.75  171.82
    2048  23.50  2444.44  237.00  283.56  229.57
    4095  23.50  1643.41  161.18  153.33  124.18
    
    0  23.50  inf  84250.00  72071.43  30968.75
    1  23.50  inf  25230.77  22250.00  13013.70
    2  23.50  inf  15500.00  13826.09  8742.86
    4  23.50  inf  9029.41  8300.00  5686.27
    8  23.50  inf  5557.69  5162.65  3671.23
    16  23.50  inf  3486.84  3244.81  2376.24
    32  23.50  inf  2432.89  2268.37  1671.02
    64  23.50  112666.67  1538.46  1471.01  1109.28
    128  23.50  29088.24  846.57  901.49  733.90
    256  23.50  15238.10  877.06  480.46  463.52
    512  23.50  7250.00  529.15  554.71  424.79
    1024  23.50  4529.73  342.52  195.09  231.05
    2048  23.50  2679.86  186.77  166.48  178.57
    4095  23.50  1643.41  159.86  153.33  124.18
    And here the updated code:

    Code:
    #include <Wire.h>
    
    //to manage the LCR-0202s
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
    
    //just to show results
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 20, 4);
    
    //to read ambient temperature
    #include <SimpleDHT.h>
    int pinDHT22 = 2;
    SimpleDHT22 dht22;
    float temperature = 0;
    float humidity = 0;
    
    //just an array of 2^n
    int pwm_values[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4095};
    
    //analog readings in voltage dividers
    float a_read1 = 0;
    float a_read2 = 0;
    float a_read3 = 0;
    float a_read4 = 0;
    
    //LCR-0202 initial resistance values
    float LCR1_ohm = 0;
    float LCR2_ohm = 0;
    float LCR3_ohm = 0;
    float LCR4_ohm = 0;
    
    //define "leak" resistors in voltage dividers
    float bottomR1_ohm = 1000;
    float bottomR2_ohm = 1000;
    float bottomR3_ohm = 1000;
    float bottomR4_ohm = 1000;
    
    void setup() {
      //PWM startup
      pwm.begin();
      pwm.setPWMFreq(1500); //to avoid wavering of the light
    
      //LCD startup
      lcd.init();
      lcd.backlight();
      lcd.clear();
    
      // Serial startup
      Serial.begin(9600);
    }
    
    void loop() {
      for (int i = 0; i < 14; i++) {
        for (int led_num = 0; led_num < 6; led_num++) {
          pwm.setPWM(led_num, 0, (4095 - pwm_values[i]));
        }
        delay(2000);
        show_values(i);
      }
    }
    
    void show_values(int i) {
      lcd.clear();
      lcd.print("Robi's LCR-0202 Test");
    
      lcd.setCursor(0, 1);
      lcd.print("PWM ");
      lcd.print(pwm_values[i]);
      Serial.print(pwm_values[i]);
      Serial.print("  ");
    
      lcd.setCursor(10, 1);
      dht22.read2(pinDHT22, &temperature, &humidity, NULL);
      lcd.print("Temp ");
      lcd.print(temperature);
      Serial.print(temperature);
      Serial.print("  ");
    
      lcd.setCursor(0, 2);
      a_read1 = analogRead(0);
      LCR1_ohm = ((1023 * bottomR1_ohm) / a_read1) - bottomR1_ohm;
      lcd.print(LCR1_ohm);
      Serial.print(LCR1_ohm);
      Serial.print("  ");
    
      lcd.setCursor(10, 2);
      a_read2 = analogRead(1);
      LCR2_ohm = ((1023 * bottomR2_ohm) / a_read2) - bottomR2_ohm;
      lcd.print(LCR2_ohm);
      Serial.print(LCR2_ohm);
      Serial.print("  ");
    
      lcd.setCursor(0, 3);
      a_read3 = analogRead(2);
      LCR3_ohm = ((1023 * bottomR3_ohm) / a_read3) - bottomR3_ohm;
      lcd.print(LCR3_ohm);
      Serial.print(LCR3_ohm);
      Serial.print("  ");
    
      lcd.setCursor(10, 3);
      a_read4 = analogRead(3);
      LCR4_ohm = ((1023 * bottomR4_ohm) / a_read4) - bottomR4_ohm;
      lcd.print(LCR4_ohm);
      Serial.println(LCR4_ohm);
    }

    0 Not allowed! Not allowed!

  10. #10
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Same values, expressed in 10 bit format:

    Code:
    0  23.10  0.00  12.00  15.00  33.00
    1  23.00  3.00  39.00  45.00  76.00
    2  23.00  13.00  64.00  72.00  111.00
    4  23.00  32.00  102.00  111.00  156.00
    8  23.10  64.00  161.00  174.00  227.00
    16  23.10  101.00  261.00  273.00  324.00
    32  23.00  177.00  314.00  333.00  403.00
    64  23.10  273.00  423.00  442.00  509.00
    128  23.10  374.00  519.00  517.00  581.00
    256  23.10  455.00  569.00  571.00  642.00
    512  23.00  525.00  600.00  816.00  784.00
    1024  23.00  619.00  672.00  824.00  863.00
    2048  23.00  773.00  856.00  802.00  834.00
    4095  23.00  809.00  881.00  888.00  911.00
    
    0  23.00  0.00  13.00  13.00  33.00
    1  23.00  2.00  42.00  48.00  71.00
    2  23.00  13.00  61.00  69.00  107.00
    4  23.00  29.00  92.00  103.00  150.00
    8  23.00  61.00  151.00  164.00  220.00
    16  23.00  102.00  204.00  221.00  331.00
    32  23.00  187.00  336.00  351.00  412.00
    64  23.00  279.00  445.00  456.00  516.00
    128  23.00  329.00  449.00  565.00  640.00
    256  23.00  519.00  621.00  606.00  664.00
    512  23.00  539.00  617.00  620.00  824.00
    1024  23.00  636.00  687.00  711.00  867.00
    2048  23.00  777.00  827.00  787.00  827.00
    4095  23.00  809.00  881.00  888.00  911.00
    
    0  23.00  0.00  13.00  16.00  35.00
    1  23.00  3.00  38.00  43.00  74.00
    2  23.00  13.00  59.00  67.00  106.00
    4  23.00  32.00  90.00  102.00  148.00
    8  23.00  60.00  149.00  163.00  219.00
    16  23.00  103.00  208.00  225.00  292.00
    32  23.00  188.00  342.00  354.00  418.00
    64  22.90  258.00  397.00  416.00  491.00
    128  22.90  344.00  473.00  494.00  573.00
    256  22.90  506.00  645.00  622.00  672.00
    512  22.90  527.00  598.00  794.00  779.00
    1024  22.90  593.00  833.00  815.00  822.00
    2048  22.90  773.00  853.00  801.00  834.00
    4095  22.90  810.00  882.00  888.00  911.00
    
    0  22.90  0.00  13.00  17.00  33.00
    1  22.90  4.00  39.00  45.00  77.00
    2  22.90  13.00  61.00  70.00  108.00
    4  22.90  33.00  91.00  101.00  149.00
    8  22.90  65.00  168.00  180.00  232.00
    16  22.90  113.00  234.00  250.00  311.00
    32  22.90  183.00  327.00  343.00  409.00
    64  22.90  259.00  402.00  419.00  492.00
    128  22.90  365.00  509.00  527.00  585.00
    256  22.90  427.00  533.00  736.00  715.00
    512  22.90  527.00  600.00  810.00  794.00
    1024  22.90  683.00  843.00  775.00  810.00
    2048  22.90  699.00  796.00  867.00  897.00
    4095  22.90  810.00  881.00  888.00  911.00
    
    0  22.90  0.00  12.00  15.00  34.00
    1  22.90  4.00  37.00  43.00  74.00
    2  22.90  13.00  62.00  71.00  109.00
    4  22.90  31.00  98.00  108.00  154.00
    8  22.90  60.00  149.00  163.00  218.00
    16  22.90  102.00  202.00  276.00  325.00
    32  22.90  166.00  289.00  308.00  382.00
    64  22.90  242.00  369.00  392.00  485.00
    128  22.90  333.00  456.00  475.00  607.00
    256  22.90  423.00  531.00  735.00  716.00
    512  22.90  563.00  646.00  641.00  708.00
    1024  22.90  691.00  802.00  752.00  791.00
    2048  22.80  698.00  808.00  871.00  898.00
    4095  22.80  809.00  881.00  888.00  910.00
    Note that the first bit on the LDR with 2 channels and additional resistors, is always between 2 and 4 on a basis of 1024 values, so we are talkling of a difference of 4.88 mV each bit, so around 9 mVpp in total. It could even be noise catched from the system as everything is floating without any shielding.

    0 Not allowed! Not allowed!

  11. #11
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    Very reminiscent of the now largely obsolete Vactrols, although some stocks are still around.

    Anyway, I would not be surprised if there were a very large part to part tolerance. It's not mentioned in the datasheet and that can be a red flag.

    Can I ask what ultimate objective is here? There might be other approaches that could be considered.

    0 Not allowed! Not allowed!
    Last edited by nickb; 12-28-2017 at 10:21 PM.
    Experience is something you get, just after you really needed it.

  12. #12
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Yes nickb, that's exaclty the purpose: have some substitutes of the old VTL5C1s as variable resistors.
    Common digital pots are limited to some tens of voltages, while these can be also used as pots for tube amps' tonestacks.

    I know the double LDR configuration (IIRC the Mesa Triaxis used them in that way) with the OPAMP, but it's not the way I would like to go.

    I've found a solution to get an high resolution at low values and high values as well without wasting a second PWM output:
    I add a 10k resistor in series with the led of the LCR (this gives me high resolution at high resistance values), and then I use a single output of the arduino to saturate a fet (or transistor, or whatever) in parallel with the 10k resistor to increase the resolution at lowest resistance values and decrease the minimum resistance as well. Basically we can imagine it as a "virtual" 13th bit, but it's way more: we can have 12 bit more of resolution where we need them (from 100 MOhm to 10 MOhm , from 10 MOhm to 1 MOhm, etc...) and then focus the "real" 12 bit on the lowest part of the resistance (where is more needed if we want to simulate log pots).

    If it's not clear I can draw a schematic.

    0 Not allowed! Not allowed!

  13. #13
    Member
    Join Date
    Apr 2015
    Posts
    94
    Thumbs Up/Down
    Received: 1/0
    Given: 0/0
    Good creative thinking.

    Alternative approach is directly pwm-chopping the audio signal using analog switches. My favourite DG201B from Vishay is good up to 44Vpp and will switch fast enough to be PWM-ed with adequate resolution.
    I guess hybrid approach to a standard tone stack would be possible too, i.e. bass and mid using DG201B switches and treble using LED->LDR opto. Just a thought.

    P.S. A 70Vpp switches are available too: http://www.farnell.com/datasheets/20...224.1514498727

    0 Not allowed! Not allowed!

  14. #14
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    Quote Originally Posted by Roberto View Post
    I've found a solution to get an high resolution at low values and high values as well without wasting a second PWM output:
    I add a 10k resistor in series with the led of the LCR (this gives me high resolution at high resistance values), and then I use a single output of the arduino to saturate a fet (or transistor, or whatever) in parallel with the 10k resistor to increase the resolution at lowest resistance values and decrease the minimum resistance as well. Basically we can imagine it as a "virtual" 13th bit, but it's way more: we can have 12 bit more of resolution where we need them (from 100 MOhm to 10 MOhm , from 10 MOhm to 1 MOhm, etc...) and then focus the "real" 12 bit on the lowest part of the resistance (where is more needed if we want to simulate log pots).

    If it's not clear I can draw a schematic.
    Sort of a one bit exponent block floating point.

    You didn't really say what the real reason is so I'll have to guess. You want to use them as linear devices and that implies you want some kind digital control, probably because you want to to store and recall settings in some fashion. Am I on the right lines here?

    Yes, digipots are low voltage, but aside from a questionable desire to never put the signal thru anything other than a tube, what is so terribly wrong with attenuating and amplifying if necessary to make their use possible? These LCR devices are quite expensive and single sourced. You wouldn't need to have many before it make more sense cost wise to do it with opamps and digipots, or, dare I even say it, a DSP? And that's assuming you can overcome the tolerance issues. There's a reason Vactrols died out.

    0 Not allowed! Not allowed!
    Experience is something you get, just after you really needed it.

  15. #15
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Thank you darkfenriz, also for the tip for the DG201Bs.

    I will try these LDRs and revert the results. Next step is to feed a PID on the PWM with an array of values, in order to get the right PWM (and the 2n3904 bit) value when the error between the target and the obtained resistance is below a fixed threshold.

    0 Not allowed! Not allowed!

  16. #16
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    These are dirty cheap: something like 40 to 60 cents each.

    This, plus the fact that I can use them everywhere from low voltage devices to (main interest) high voltage devices, plus the fact that I can assign values through a microcontroller (to change them on the fly, like CC controllers, or as presets), are the reasons why I've spent some time on them.

    0 Not allowed! Not allowed!

  17. #17
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    Quote Originally Posted by Roberto View Post
    These are dirty cheap: something like 40 to 60 cents each.

    This, plus the fact that I can use them everywhere from low voltage devices to (main interest) high voltage devices, plus the fact that I can assign values through a microcontroller (to change them on the fly, like CC controllers, or as presets), are the reasons why I've spent some time on them.
    On eBay here in the UK they were coming up at over $11 for one, hence my comment. I do see on the US site the lowest I see is $0.85, quite an improvement and definitely leads to a different conclusion. What is your source for 0.40 to 0.60 each?

    0 Not allowed! Not allowed!
    Experience is something you get, just after you really needed it.

  18. #18
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    At the moment they are sold at 85 cent/each, as you say: https://www.ebay.com/itm/291774645055
    When I bought 10 of them time ago, they were around 50 cent/each.
    For sure they can be sold really cheap for bigger quantities, but I don't think this is the kind of part that can focus attention of alot of people around.

    0 Not allowed! Not allowed!

  19. #19
    Senior Member SoulFetish's Avatar
    Join Date
    Jan 2016
    Location
    Massachusetts
    Posts
    683
    Thumbs Up/Down
    Received: 28/0
    Given: 17/0
    Quote Originally Posted by nickb View Post
    Sort of a one bit exponent block floating point.

    You didn't really say what the real reason is so I'll have to guess. You want to use them as linear devices and that implies you want some kind digital control, probably because you want to to store and recall settings in some fashion. Am I on the right lines here?
    If this is the application (and it sounds like it is), then I love this idea!
    I briefly flirted with the idea of using a microcontroller as a multi-waveform LFO generator for experimenting with time/phase based effects. But, I wondered if a quad LM1458 oscillator or an XR2202 my buddy gave me would have been the better approach. But since I would have been using LDRs in the RC network, I wish I had thought of this. I think there could be a lot of potential here.
    Plus, I've been looking for a good arduino project to get into. There is so much utility with the platform, that I'd be fool not to take advantage of it.

    0 Not allowed! Not allowed!
    If I have a 50% chance of guessing the right answer, I guess wrong 80% of the time.

  20. #20
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Quote Originally Posted by SoulFetish View Post
    But since I would have been using LDRs in the RC network, I wish I had thought of this. I think there could be a lot of potential here.
    Plus, I've been looking for a good arduino project to get into. There is so much utility with the platform, that I'd be fool not to take advantage of it.
    Thanks SoulFetish, yes, it's my "winter holydays project" and as I've written before, that's the purpose. I'll change the title of the thread in order to keep it clearer for everyone.

    I've increased the value from 10k to 33k, as it fits better the range I want to work with, and the bypass with the 2N3904 ( https://www.sparkfun.com/datasheets/...nts/2N3904.pdf ) works perfectly. I'm looking to control from 2M to 5k with the 33k in series, and from 5k to 100 Ohm without it.

    To have a better control of the effective resistance of the LDR, two voltage dividers are made with 100k resistors (I consider reliable the values that are within one order of magnitude from the fixed resistor) and two with 1k resistors. This way I can cover the values between 1M down to 100 Ohm.

    Even more, I prefer not to use the first bits of the PWM range, just because if I find the right value with the PWM inbetween 0001 and 0002, I cannot modify it, while if it's inbetween 0016 and 0032 I've 16 values inbetween to find the right one. Hypothetically to stay in the 5%, and at least to stay in the 10% of tolerance.

    I will try the suggestion to increase the stabilisation time to 10 seconds, but with 2 seconds I can stay within 10%. Not bad.

    0 Not allowed! Not allowed!

  21. #21
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    This is the new software to check the 33k bypass:

    Code:
    #include <Wire.h>
    
    //to manage the LCR-0202s
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
    
    //just to show results
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 20, 4);
    
    //to read ambient temperature
    #include <SimpleDHT.h>
    int pinDHT22 = 2;
    SimpleDHT22 dht22;
    float temperature = 0;
    float humidity = 0;
    
    //just an array of 2^n
    int pwm_values[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4095};
    
    //analog readings in voltage dividers
    float a_read1 = 0;
    float a_read2 = 0;
    float a_read3 = 0;
    float a_read4 = 0;
    
    //LCR-0202 initial resistance values
    float LCR1_ohm = 0;
    float LCR2_ohm = 0;
    float LCR3_ohm = 0;
    float LCR4_ohm = 0;
    
    //define "leak" resistors in voltage dividers
    float bottomR1_ohm = 100000;
    float bottomR2_ohm = 100000;
    float bottomR3_ohm = 1000;
    float bottomR4_ohm = 1000;
    
    void setup() {
      //PWM startup
      pwm.begin();
      pwm.setPWMFreq(1500); //to avoid wavering of the light
    
      //LCD startup
      lcd.init();
      lcd.backlight();
      lcd.clear();
    
      // Serial startup
      Serial.begin(9600);
    }
    
    void loop() {
      for (int b = 0; b < 2; b++) {
        for (int i = 0; i < 14; i++) {
          for (int led_num = 0; led_num < 5; led_num++) {
            pwm.setPWM(led_num, 0, (4095 - pwm_values[i]));
          }
          delay(5000);
          show_values(i, b);
        }
        for (int led_num = 8; led_num < 13; led_num++) {
          pwm.setPWM(led_num, 0, (4095 * b));
        }
      }
    }
    
    void show_values(int i, int b) {
      lcd.clear();
      lcd.print("Robi's LCR-0202 Test");
    
      lcd.setCursor(0, 1);
      lcd.print("bit");
      lcd.print(b);
      Serial.print(b);
      Serial.print("  ");
    
      lcd.setCursor(6, 1);
      lcd.print("PWM");
      lcd.print(pwm_values[i]);
      Serial.print(pwm_values[i]);
      Serial.print("  ");
    
      lcd.setCursor(14, 1);
      dht22.read2(pinDHT22, &temperature, &humidity, NULL);
      lcd.print("T");
      lcd.print(temperature);
      Serial.print(temperature);
      Serial.print("  ");
    
      lcd.setCursor(0, 2);
      a_read1 = analogRead(0);
      LCR1_ohm = ((1023 / a_read1) - 1) * bottomR1_ohm;
      lcd.print(LCR1_ohm);
      Serial.print(a_read1);
      Serial.print("  ");
    
      lcd.setCursor(0, 3);
      a_read2 = analogRead(1);
      LCR2_ohm = ((1023 / a_read2) - 1) * bottomR2_ohm;
      lcd.print(LCR2_ohm);
      Serial.print(a_read2);
      Serial.print("  ");
    
      lcd.setCursor(10, 2);
      a_read3 = analogRead(2);
      LCR3_ohm = ((1023 / a_read3) - 1) * bottomR3_ohm;
      lcd.print(LCR3_ohm);
      Serial.print(a_read3);
      Serial.print("  ");
    
      lcd.setCursor(10, 3);
      a_read4 = analogRead(3);
      LCR4_ohm = ((1023 / a_read4) - 1) * bottomR4_ohm; //((1023 * bottomR4_ohm) / a_read4) - bottomR4_ohm;
      lcd.print(LCR4_ohm);
      Serial.println(a_read4);
    }

    0 Not allowed! Not allowed!

  22. #22
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    So, these are the results from the first test with the bypassable 33k resistor:

    - 1st column is the 2n3904's bit: 0 = bypassed 33k; 1= unbypassed 33k
    - 2nd column is the PWM value (0 = 0% led on; 4095 = 100% led on)
    - 3rd is the temperature in Celsius degrees
    - 4th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 100 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 1 MOhm and 10 kOhm)
    - 5th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 100 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 1 MOhm and 10 kOhm)
    - 6th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 1 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 10 kOhm and 100 Ohm)
    - 7th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 1 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 10 kOhm and 100 Ohm)

    As you will notice, I've added a comma between each value, in order to import the data in excel as csv file (or txt file).
    If anyone wants to partecipate...

    Code:
    0, 0, 23.60, inf, inf, inf, inf,
    0, 1, 23.60, inf, inf, inf, inf,
    0, 2, 23.70, inf, inf, inf, inf,
    0, 4, 23.70, 25475000.00, 12687500.00, inf, inf,
    0, 8, 23.60, 5015000.00, 2908823.50, inf, inf,
    0, 16, 23.60, 1523809.37, 988297.87, inf, inf,
    0, 32, 23.60, 582000.00, 411499.96, inf, 510500.00,
    0, 64, 23.60, 249146.75, 188983.06, 254750.00, 126875.00,
    0, 128, 23.60, 115368.42, 91214.96, 77692.31, 50150.00,
    0, 256, 23.60, 56422.02, 46561.60, 36888.89, 25230.77,
    0, 512, 23.60, 27875.00, 24301.34, 19058.82, 13826.09,
    0, 1024, 23.60, 13793.10, 11803.28, 9882.98, 7818.97,
    0, 2048, 23.60, 6562.50, 5681.81, 5686.27, 4683.33,
    0, 4095, 23.60, 3229.06, 2710.84, 3587.44, 2980.54,
    1, 0, 23.60, inf, inf, inf, inf,
    1, 1, 23.60, inf, inf, inf, inf,
    1, 2, 23.60, inf, inf, inf, inf,
    1, 4, 23.60, inf, 14514285.00, inf, inf,
    1, 8, 23.60, 6719999.50, 3200000.00, inf, inf,
    1, 16, 23.60, 1694736.87, 1075862.00, inf, inf,
    1, 32, 23.60, 600684.93, 427319.56, inf, 510500.00,
    1, 64, 23.60, 246779.65, 187359.54, 254750.00, 112666.67,
    1, 128, 23.60, 112240.67, 89444.45, 77692.31, 50150.00,
    1, 256, 23.60, 55000.00, 45726.49, 35535.71, 25230.77,
    1, 512, 23.60, 26140.57, 22076.37, 18673.08, 14268.66,
    1, 1024, 23.60, 13289.03, 11316.65, 9546.39, 7669.49,
    1, 2048, 23.60, 6896.56, 6120.34, 6055.17, 4812.50,
    1, 4095, 23.60, 3229.06, 2710.84, 3566.96, 2965.12,
    0, 0, 23.60, inf, inf, inf, inf,
    0, 1, 23.60, 20352.94, 19369.90, 19058.82, 13208.33,
    0, 2, 23.50, 11437.91, 10954.45, 11629.63, 8300.00,
    0, 4, 23.50, 6340.96, 6230.53, 7317.07, 5557.69,
    0, 8, 23.50, 3752.53, 3857.86, 5162.65, 3966.02,
    0, 16, 23.50, 1488.09, 1488.09, 3280.33, 2640.57,
    0, 32, 23.50, 195.88, 195.88, 2177.02, 1742.63,
    0, 64, 23.50, 0.00, 0.00, 1513.51, 1209.50,
    0, 128, 23.50, 0.00, 0.00, 1122.41, 877.06,
    0, 256, 23.50, 0.00, 0.00, 823.53, 639.42,
    0, 512, 23.50, 0.00, 0.00, 623.81, 469.83,
    0, 1024, 23.50, 0.00, 0.00, 354.97, 277.15,
    0, 2048, 23.50, 0.00, 0.00, 196.49, 170.48,
    0, 4095, 23.50, 0.00, 0.00, 174.51, 143.02,
    1, 0, 23.50, inf, inf, inf, inf,
    1, 1, 23.50, inf, inf, inf, inf,
    1, 2, 23.50, inf, inf, inf, inf,
    1, 4, 23.50, 102200000.00, 20360000.00, inf, inf,
    1, 8, 23.50, 7207142.50, 3688889.00, inf, inf,
    1, 16, 23.40, 1794444.50, 1147561.00, inf, inf,
    1, 32, 23.40, 620422.56, 444148.93, inf, 510500.00,
    1, 64, 23.40, 260211.28, 196521.73, 254750.00, 126875.00,
    1, 128, 23.40, 114016.75, 90502.80, 84250.00, 52842.10,
    1, 256, 23.40, 56422.02, 46561.60, 36888.89, 25921.05,
    1, 512, 23.40, 28356.34, 24301.34, 18673.08, 13826.09,
    1, 1024, 23.40, 13163.72, 11803.28, 10366.67, 8216.22,
    1, 2048, 23.40, 7008.37, 6120.34, 5912.16, 4747.19,
    1, 4095, 23.40, 3229.06, 2814.07, 3608.11, 2980.54,
    0, 0, 23.40, inf, inf, inf, inf,
    0, 1, 23.40, 20494.70, 19091.96, 19058.82, 13208.33,
    0, 2, 23.40, 11195.65, 10714.28, 11325.30, 8216.22,
    0, 4, 23.30, 5900.62, 5791.10, 8216.22, 6006.85,
    0, 8, 23.30, 4175.15, 4387.76, 5686.27, 4246.15,
    0, 16, 23.30, 1994.01, 2095.81, 3736.11, 2875.00,
    0, 32, 23.30, 97.85, 97.85, 2227.13, 1795.08,
    0, 64, 23.30, 0.00, 0.00, 1685.04, 1298.88,
    0, 128, 23.30, 0.00, 0.00, 1268.29, 959.77,
    0, 256, 23.30, 0.00, 0.00, 933.84, 699.34,
    0, 512, 23.30, 0.00, 0.00, 330.30, 286.79,
    0, 1024, 23.30, 0.00, 0.00, 318.30, 255.21,
    0, 2048, 23.30, 0.00, 0.00, 277.15, 212.09,
    0, 4095, 23.30, 0.00, 0.00, 174.51, 143.02,
    1, 0, 23.30, inf, inf, inf, inf,
    1, 1, 23.30, inf, inf, inf, inf,
    1, 2, 23.30, inf, inf, inf, inf,
    1, 4, 23.30, 51050000.00, 12687500.00, inf, inf,
    1, 8, 23.20, 6719999.50, 3688889.00, inf, inf,
    1, 16, 23.20, 1794444.50, 1147561.00, inf, inf,
    1, 32, 23.20, 625531.93, 444148.93, inf, 510500.00,
    1, 64, 23.30, 251546.39, 188169.00, 254750.00, 126875.00,
    1, 128, 23.20, 118589.74, 95229.01, 84250.00, 52842.10,
    1, 256, 23.30, 55235.21, 45726.49, 35535.71, 25230.77,
    1, 512, 23.20, 28035.05, 23700.12, 18673.08, 13826.09,
    1, 1024, 23.20, 14429.53, 12541.26, 10494.38, 8053.10,
    1, 2048, 23.20, 6784.96, 5900.62, 5774.83, 4683.33,
    1, 4095, 23.30, 3333.33, 2814.07, 3608.11, 2996.09,
    0, 0, 23.20, inf, inf, inf, inf,
    0, 1, 23.20, 21352.32, 19929.66, 20312.50, 13614.29,
    0, 2, 23.20, 11559.44, 11195.65, 11787.50, 8385.32,
    0, 4, 23.20, 6896.56, 6784.96, 7895.65, 5820.00,
    0, 8, 23.20, 3963.41, 4069.17, 5433.96, 4140.70,
    0, 16, 23.20, 2095.81, 2197.80, 3825.47, 2934.62,
    0, 32, 23.10, 0.00, 0.00, 2053.73, 1699.21,
    0, 64, 23.10, 0.00, 0.00, 1623.08, 1263.27,
    0, 128, 23.10, 0.00, 0.00, 912.15, 769.90,
    0, 256, 23.10, 0.00, 0.00, 725.13, 578.70,
    0, 512, 23.10, 0.00, 0.00, 581.14, 440.85,
    0, 1024, 23.10, 0.00, 0.00, 434.78, 318.30,
    0, 2048, 23.10, 0.00, 0.00, 266.09, 196.49,
    0, 4095, 23.10, 0.00, 0.00, 174.51, 144.30,
    1, 0, 23.10, inf, inf, inf, inf,
    1, 1, 23.10, inf, inf, inf, inf,
    1, 2, 23.10, inf, inf, inf, inf,
    1, 4, 23.10, 51050000.00, 16950000.00, inf, inf,
    1, 8, 23.10, 6293750.00, 3688889.00, inf, inf,
    1, 16, 23.10, 1760000.00, 1162963.00, inf, inf,
    1, 32, 23.10, 615384.62, 435602.09, inf, 340000.00,
    1, 64, 23.10, 260211.28, 196521.73, 254750.00, 126875.00,
    1, 128, 23.10, 119527.89, 94486.69, 84250.00, 52842.10,
    1, 256, 23.10, 56901.83, 46982.75, 36888.89, 25921.05,
    1, 512, 23.10, 27875.00, 24756.10, 19460.00, 14044.12,
    1, 1024, 23.10, 13289.03, 12048.20, 10625.00, 8216.22,
    1, 2048, 23.10, 6896.56, 6120.34, 5912.16, 4812.50,
    1, 4095, 23.10, 3229.06, 2814.07, 3628.96, 2996.09,
    0, 0, 23.10, inf, inf, inf, inf,
    0, 1, 23.10, 21496.44, 20352.94, 20312.50, 13826.09,
    0, 2, 23.10, 11074.92, 10714.28, 11178.57, 8133.93,
    0, 4, 23.10, 5900.62, 7120.42, 8216.22, 6006.85,
    0, 8, 23.10, 4175.15, 4281.34, 5557.69, 4192.89,
    0, 16, 23.10, 1791.05, 1791.05, 3506.61, 2747.25,
    0, 32, 23.10, 195.88, 195.88, 2206.90, 1787.47,
    0, 64, 23.10, 0.00, 0.00, 1772.36, 1357.14,
    0, 128, 23.10, 0.00, 0.00, 1158.23, 883.98,
    0, 256, 23.10, 0.00, 0.00, 897.96, 674.30,
    0, 512, 23.10, 0.00, 0.00, 536.04, 412.98,
    0, 1024, 23.10, 0.00, 0.00, 438.82, 323.42,
    0, 2048, 23.10, 0.00, 0.00, 354.97, 252.14,
    0, 4095, 23.10, 0.00, 0.00, 174.51, 143.02,
    1, 0, 23.10, inf, inf, inf, inf,
    1, 1, 23.10, inf, inf, inf, inf,
    1, 2, 23.10, inf, inf, inf, inf,
    1, 4, 23.10, 102200000.00, 16950000.00, inf, inf,
    1, 8, 23.10, 5917647.00, 3553571.25, inf, inf,
    1, 16, 23.10, 1760000.00, 1147561.00, inf, inf,
    1, 32, 23.10, 605517.25, 447058.81, inf, 510500.00,
    1, 64, 23.10, 257692.31, 195664.73, 254750.00, 126875.00,
    1, 128, 23.10, 118589.74, 93750.00, 84250.00, 52842.10,
    1, 256, 23.10, 53834.58, 45106.39, 38346.15, 26648.65,
    1, 512, 23.10, 26923.07, 22514.98, 18673.08, 14268.66,
    1, 1024, 23.10, 14046.82, 12171.05, 10241.76, 7895.65,
    1, 2048, 23.10, 7232.70, 6340.96, 6153.85, 4879.31,
    1, 4095, 23.10, 3229.06, 2710.84, 3608.11, 2996.09,
    0, 0, 23.10, inf, inf, inf, inf,
    0, 1, 23.10, 21496.44, 20352.94, 20312.50, 13826.09,
    0, 2, 23.10, 11316.65, 10834.24, 11629.63, 8385.32,
    0, 4, 23.10, 7008.37, 6896.56, 7973.68, 5912.16,
    0, 8, 23.10, 3752.53, 3752.53, 5162.65, 3990.24,
    0, 16, 23.10, 1892.44, 1892.44, 3650.00, 2817.16,
    0, 32, 23.10, 589.97, 589.97, 2576.92, 1973.84,
    0, 64, 23.10, 0.00, 0.00, 1757.41, 1351.72,
    0, 128, 23.10, 0.00, 0.00, 739.80, 742.76,
    0, 256, 23.10, 0.00, 0.00, 933.84, 702.16,
    0, 512, 23.10, 0.00, 0.00, 690.91, 506.63,
    0, 1024, 23.10, 0.00, 0.00, 275.56, 253.68,
    0, 2048, 23.10, 0.00, 0.00, 294.94, 217.86,
    0, 4095, 23.00, 0.00, 0.00, 174.51, 144.30,
    1, 0, 23.00, inf, inf, inf, inf,
    1, 1, 23.00, inf, inf, inf, inf,
    1, 2, 23.00, inf, inf, inf, inf,
    1, 4, 23.00, 34000000.00, 16950000.00, inf, inf,
    1, 8, 23.00, 6293750.00, 3427586.25, inf, inf,
    1, 16, 23.00, 1760000.00, 1147561.00, inf, inf,
    1, 32, 23.00, 635971.18, 447058.81, inf, 510500.00,
    1, 64, 23.00, 257692.31, 197383.71, 254750.00, 126875.00,
    1, 128, 23.00, 117659.57, 94117.64, 84250.00, 52842.10,
    1, 256, 23.00, 57627.12, 47832.37, 38346.15, 25921.05,
    1, 512, 23.00, 27875.00, 23550.73, 18301.89, 13614.29,
    1, 1024, 23.00, 13540.51, 12294.19, 10895.35, 8216.22,
    1, 2048, 23.00, 6896.56, 5900.62, 5865.77, 4715.08,
    1, 4095, 23.00, 3333.33, 2814.07, 3628.96, 2996.09,
    0, 0, 23.00, inf, inf, inf, inf,
    0, 1, 23.00, 20070.42, 18953.49, 21239.13, 14044.12,
    0, 2, 23.00, 10594.59, 11803.28, 12285.71, 8650.94,
    0, 4, 23.00, 6340.96, 6340.96, 7317.07, 5600.00,
    0, 8, 23.00, 3542.51, 3437.82, 4879.31, 3848.34,
    0, 16, 23.00, 1791.05, 1791.05, 3526.55, 2761.03,
    0, 32, 23.00, 491.15, 491.15, 2410.00, 1881.69,
    0, 64, 23.00, 0.00, 0.00, 1742.63, 1340.96,
    0, 128, 23.00, 0.00, 0.00, 990.27, 813.83,
    0, 256, 23.00, 0.00, 0.00, 631.58, 511.08,
    0, 512, 23.00, 0.00, 0.00, 588.51, 442.88,
    0, 1024, 23.00, 0.00, 0.00, 467.72, 337.25,
    0, 2048, 23.00, 0.00, 0.00, 203.53, 178.57,
    0, 4095, 23.00, 0.00, 0.00, 174.51, 144.30,
    1, 0, 23.00, inf, inf, inf, inf,
    1, 1, 23.00, inf, inf, inf, inf,
    1, 2, 23.00, inf, inf, inf, inf,
    1, 4, 23.00, inf, 25475000.00, inf, inf,
    1, 8, 23.00, 6719999.50, 3553571.25, inf, inf,
    1, 16, 23.00, 1760000.00, 1117857.12, inf, inf,
    1, 32, 23.00, 620422.56, 444148.93, inf, 510500.00,
    1, 64, 22.90, 252758.62, 196521.73, 254750.00, 126875.00,
    1, 128, 22.90, 115822.79, 92293.25, 77692.31, 50150.00,
    1, 256, 22.90, 55707.76, 46142.85, 35535.71, 25230.77,
    1, 512, 22.90, 28195.49, 24000.00, 18673.08, 13826.09,
    1, 1024, 22.90, 13540.51, 11681.22, 10000.00, 8216.22,
    1, 2048, 22.90, 6896.56, 6010.37, 5912.16, 4747.19,
    1, 4095, 22.90, 3333.33, 2814.07, 3628.96, 2996.09,
    0, 0, 22.90, inf, inf, inf, inf,
    0, 1, 22.90, 21640.91, 20636.80, 20765.96, 13826.09,
    0, 2, 22.90, 11681.22, 11316.65, 11787.50, 8385.32,
    0, 4, 22.90, 6896.56, 6784.96, 7818.97, 5820.00,
    0, 8, 22.90, 4069.17, 4175.15, 5515.92, 4166.67,
    0, 16, 23.00, 2197.80, 2300.00, 3871.43, 2949.81,
    0, 32, 23.00, 195.88, 195.88, 2157.41, 1757.41,
    0, 64, 22.90, 0.00, 0.00, 1609.69, 1258.28,
    0, 128, 22.90, 0.00, 0.00, 919.32, 772.96,
    0, 256, 22.90, 0.00, 0.00, 623.81, 517.80,
    0, 512, 22.90, 0.00, 0.00, 529.15, 411.03,
    0, 1024, 22.90, 0.00, 0.00, 459.34, 333.77,
    0, 2048, 22.90, 0.00, 0.00, 204.95, 179.93,
    0, 4095, 22.90, 0.00, 0.00, 174.51, 144.30,
    1, 0, 22.90, inf, inf, inf, inf,
    1, 1, 22.90, inf, inf, inf, inf,
    1, 2, 22.90, inf, inf, inf, inf,
    1, 4, 22.90, 11266666.00, 20360000.00, inf, inf,
    1, 8, 22.90, 6719999.50, 2908823.50, inf, inf,
    1, 16, 22.90, 1794444.50, 1132530.12, inf, inf,
    1, 32, 22.90, 620422.56, 444148.93, inf, 510500.00,
    1, 64, 22.90, 252758.62, 191452.98, 254750.00, 126875.00,
    1, 128, 22.90, 117197.45, 93383.75, 84250.00, 52842.10,
    1, 256, 22.90, 54531.72, 48046.32, 38346.15, 25921.05,
    1, 512, 22.90, 28195.49, 23849.88, 18673.08, 13826.09,
    1, 1024, 22.90, 13666.67, 11681.22, 9882.98, 7818.97,
    1, 2048, 22.90, 6673.62, 5900.62, 5865.77, 4779.66,
    1, 4095, 22.90, 3125.00, 2710.84, 3628.96, 2996.09,

    0 Not allowed! Not allowed!

  23. #23
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    Sorry for slow replies - forum subscribed thread email updates are not working for me. Are they working for others?

    Here is your table as a pdf so it's easier to read:LDR 2.pdf

    Sorry the data is not clear to me.
    1) The yellow and orange entries were apparently measured under the same PWM, 33k and temperature so why is the resistance so different?
    2) How does the data in columns 5 and 6 differ? Both were done with 100k.
    3) How does the data in columns 7 and 8 differ? Both were done with 10k.

    These really are a drop in for many vactorls at a great price. I see they do a LCR-0203 in an axial package like the vactrols too.

    0 Not allowed! Not allowed!
    Last edited by nickb; 12-31-2017 at 01:50 PM.
    Experience is something you get, just after you really needed it.

  24. #24
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    As for the yellow values, I've no idea, but yesterday evening, back home, I've lounched another simulation, with steps of one instead of poowers of two.

    Here below the results, and attached the txt file of all the data and here below the code.

    LDR resistance vs PWM control: 33k in series with the led, and 100 kOhm as voltage divider to ground.
    Click image for larger version. 

Name:	LCR-0202-33k-bypassed-100k-leak-A&B.jpg 
Views:	16 
Size:	66.0 KB 
ID:	46317


    LDR resistance vs PWM control: 33k in series with the led, and 1 kOhm as voltage divider to ground.
    Click image for larger version. 

Name:	LCR-0202-33k-bypassed-1k-leak-C&D.jpg 
Views:	21 
Size:	69.8 KB 
ID:	46318

    Both previous data in the same plot.
    Click image for larger version. 

Name:	LCR-0202-33k-bypassed-A&B&C&D.jpg 
Views:	20 
Size:	77.2 KB 
ID:	46319

    Code:
    #include <Wire.h>
    
    //to manage the LCR-0202s
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
    
    //just to show results
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 20, 4);
    
    //to read ambient temperature
    #include <SimpleDHT.h>
    int pinDHT22 = 2;
    SimpleDHT22 dht22;
    float temperature = 0;
    float humidity = 0;
    
    //just an array of 2^n
    //int pwm_values[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4095};
    
    //analog readings in voltage dividers
    int a_read[] = {0, 0, 0, 0};
    
    //LCR-0202 initial resistance values
    float LCR_ohm[] = {0, 0, 0, 0};
    
    //define "leak" resistors in voltage dividers
    unsigned long bottomR_ohm[] = {100000, 100000, 1000, 1000};
    
    void setup() {
      //PWM startup
      pwm.begin();
      pwm.setPWMFreq(1500); //to avoid wavering of the light
    
      //LCD startup
      lcd.init();
      lcd.backlight();
      lcd.clear();
    
      // Serial startup
      Serial.begin(9600);
    }
    
    void loop() {
      for (int b = 0; b < 2; b++) {
        for (int i = 1; i < 4096; i++) {
          for (int led_num = 0; led_num < 5; led_num++) {
            pwm.setPWM(led_num, 0, (4095 - i));
          }
          read_values();
          show_values(b, i);
        }
        for (int led_num = 8; led_num < 13; led_num++) {
          pwm.setPWM(led_num, 0, (4095 * b));
        }
      }
    }
    
    void read_values() {
      delay(1000);
      dht22.read2(pinDHT22, &temperature, &humidity, NULL);
      for (int gpio = 0; gpio < 4; gpio++) {
        a_read[gpio] = analogRead(gpio);
        LCR_ohm[gpio] = ((1023.00 / a_read[gpio]) - 1) * bottomR_ohm[gpio];
      }
    }
    
    void show_values(int b, int i) {
      lcd.clear();
      lcd.print("Robi's LCR-0202 Test");
    
      lcd.setCursor(0, 1);
      lcd.print("bit");
      lcd.print(b);
      Serial.print(b);
      Serial.print("  ");
    
      lcd.setCursor(6, 1);
      lcd.print("PWM");
      lcd.print(i);
      Serial.print(i);
      Serial.print("  ");
    
      lcd.setCursor(14, 1);
      lcd.print("T");
      lcd.print(temperature);
      Serial.print(temperature);
      Serial.print("  ");
    
      lcd.setCursor(0, 2);
      lcd.print(LCR_ohm[0]);
      Serial.print(LCR_ohm[0]);
      Serial.print("  ");
    
      lcd.setCursor(0, 3);
      lcd.print(LCR_ohm[1]);
      Serial.print(LCR_ohm[1]);
      Serial.print("  ");
    
      lcd.setCursor(10, 2);
      lcd.print(LCR_ohm[2]);
      Serial.print(LCR_ohm[2]);
      Serial.print("  ");
    
      lcd.setCursor(10, 3);
      lcd.print(LCR_ohm[3]);
      Serial.println(LCR_ohm[3]);
    }

    0 Not allowed! Not allowed!

  25. #25
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Three plots with the 33k bupassed (only the SMD 220 Ohm resistor on the PCA9685 board):

    LDR resistance vs PWM control: 220 Ohm in series with the led, and 100 kOhm as voltage divider to ground.
    Click image for larger version. 

Name:	LCR-0202-33k-unbypassed-A&B&C&D.jpg 
Views:	18 
Size:	77.3 KB 
ID:	46320

    LDR resistance vs PWM control: 220 Ohm in series with the led, and 1 kOhm as voltage divider to ground.
    Click image for larger version. 

Name:	LCR-0202-33k-unbypassed-1k-leak-C&D.jpg 
Views:	19 
Size:	69.9 KB 
ID:	46321

    Both previous data in the same plot.
    Click image for larger version. 

Name:	LCR-0202-33k-unbypassed-100k-leak-A&B.jpg 
Views:	20 
Size:	69.2 KB 
ID:	46322

    0 Not allowed! Not allowed!

  26. #26
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    This is part of the data I've collected, limited by the forum's limit of txt files (1 MB ).
    Attached Files Attached Files

    0 Not allowed! Not allowed!

  27. #27
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    Instead of taking one sample for each PWM setting, take (say) 16 and average the results. That will give you an effective two extra bits of resolution and reduce the noise.

    The tolerance is something like +/-20% based on this very small sample size. Not too bad really.

    0 Not allowed! Not allowed!
    Experience is something you get, just after you really needed it.

  28. #28
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Quote Originally Posted by nickb View Post
    2) How does the data in columns 5 and 6 differ? Both were done with 100k.
    3) How does the data in columns 7 and 8 differ? Both were done with 10k.
    Column 7 and 8 have 1k to ground, not 10k. The difference in both cases are due to the fact that I use two LDRs for each trial (four parallel trials at the same time).

    0 Not allowed! Not allowed!

  29. #29
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Quote Originally Posted by nickb View Post
    Instead of taking one sample for each PWM setting, take (say) 16 and average the results. That will give you an effective two extra bits of resolution and reduce the noise.
    That's logical, let's make it 1024 times, this will improve it even further. At the end I've nothing to do, the software does it all by itself, so no worries if it takes 1 hour or 4.
    Give a look at the code here below.

    Quote Originally Posted by nickb View Post
    The tolerance is something like +/-20% based on this very small sample size. Not too bad really.
    First trials with mean values of analog readings seem even better:
    0, 385, 23.40, 51331.26, 48004.06, 55805.95, 28921.45
    0, 449, 23.40, 43862.16, 41156.53, 43602.32, 24041.33
    0, 513, 23.40, 38319.50, 36120.92, 35899.09, 20699.56
    0, 577, 23.40, 34047.06, 32204.07, 30795.68, 18290.80
    0, 641, 23.40, 30663.62, 29088.16, 27017.76, 16420.19
    0, 705, 23.40, 27935.19, 26535.53, 24100.12, 14971.72
    0, 769, 23.40, 25633.93, 24426.04, 21766.80, 13750.23
    0, 833, 23.40, 23722.07, 22628.13, 19925.44, 12735.44
    0, 897, 23.40, 22063.43, 21098.49, 18353.94, 11878.22
    0, 961, 23.40, 20660.28, 19774.09, 17036.00, 11159.91
    0, 1025, 23.40, 19382.92, 18599.71, 15945.69, 10541.60
    0, 1089, 23.40, 18287.51, 17573.33, 14977.84, 9976.95
    0, 1153, 23.40, 17314.19, 16650.28, 14148.49, 9497.52
    Code:
    #include <Wire.h>
    
    //to manage the LCR-0202s
    #include <Adafruit_PWMServoDriver.h>
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
    
    //just to show results
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 20, 4);
    
    //to read ambient temperature
    #include <SimpleDHT.h>
    int pinDHT22 = 2;
    SimpleDHT22 dht22;
    float temperature = 0;
    float humidity = 0;
    
    //analog readings in voltage dividers
    int a_read[] = {0, 0, 0, 0};
    
    //LCR-0202 initial resistance values
    float LCR_ohm[] = {0, 0, 0, 0};
    
    //define "leak" resistors in voltage dividers
    unsigned long bottomR_ohm[] = {100000, 100000, 1000, 1000};
    
    void setup() {
      //PWM startup
      pwm.begin();
      pwm.setPWMFreq(1500); //to avoid wavering of the light
    
      //LCD startup
      lcd.init();
      lcd.backlight();
      lcd.clear();
    
      // Serial startup
      Serial.begin(9600);
    }
    
    void loop() {
      for (int b = 0; b < 2; b++) {
        for (int i = 1; i < 4096; i += 64) {
          for (int led_num = 0; led_num < 5; led_num++) {
            pwm.setPWM(led_num, 0, (4095 - i));
          }
          read_values();
          show_values(b, i);
        }
        for (int led_num = 8; led_num < 13; led_num++) {
          pwm.setPWM(led_num, 0, (4095 * b));
        }
      }
    }
    
    void read_values() {
      delay(1000);
      dht22.read2(pinDHT22, &temperature, &humidity, NULL);
      for (int gpio = 0; gpio < 4; gpio++) {
        LCR_ohm[gpio] = 0;
        for (int num_read = 0; num_read < 1024; num_read++) {
          a_read[gpio] = analogRead(gpio);
          LCR_ohm[gpio] = LCR_ohm[gpio] + (((1023.00 / a_read[gpio]) - 1) * bottomR_ohm[gpio]);
        }
        LCR_ohm[gpio] = LCR_ohm[gpio] / 1024;
      }
    }
    
    void show_values(int b, int i) {
      lcd.clear();
      lcd.print("Robi's LCR-0202 Test");
    
      lcd.setCursor(0, 1);
      lcd.print("bit");
      lcd.print(b);
      Serial.print(b);
      Serial.print(", ");
    
      lcd.setCursor(6, 1);
      lcd.print("PWM");
      lcd.print(i);
      Serial.print(i);
      Serial.print(", ");
    
      lcd.setCursor(14, 1);
      lcd.print("T");
      lcd.print(temperature);
      Serial.print(temperature);
      Serial.print(", ");
    
      lcd.setCursor(0, 2);
      lcd.print(LCR_ohm[0]);
      Serial.print(LCR_ohm[0]);
      Serial.print(", ");
    
      lcd.setCursor(0, 3);
      lcd.print(LCR_ohm[1]);
      Serial.print(LCR_ohm[1]);
      Serial.print(", ");
    
      lcd.setCursor(10, 2);
      lcd.print(LCR_ohm[2]);
      Serial.print(LCR_ohm[2]);
      Serial.print(", ");
    
      lcd.setCursor(10, 3);
      lcd.print(LCR_ohm[3]);
      Serial.println(LCR_ohm[3]);
    }

    0 Not allowed! Not allowed!

  30. #30
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    I report here the values of the 250k, 500k and 1M log pots based on the formula
    resistance = nominal value * (%Rot)^3.3

    Code:
    %Rot   250 k   500 k   1 M
    0%   0,00   0,00   0,00
    2%   0,00   0,00   0,00
    4%   0,01   0,01   0,02
    6%   0,02   0,05   0,09
    8%   0,06   0,12   0,24
    10%   0,13   0,25   0,50
    12%   0,23   0,46   0,91
    14%   0,38   0,76   1,52
    16%   0,59   1,18   2,36
    18%   0,87   1,74   3,49
    20%   1,23   2,47   4,94
    22%   1,69   3,38   6,76
    24%   2,25   4,50   9,01
    26%   2,93   5,87   11,73
    28%   3,75   7,49   14,98
    30%   4,70   9,41   18,81
    32%   5,82   11,64   23,28
    34%   7,11   14,22   28,44
    36%   8,58   17,17   34,34
    38%   10,26   20,52   41,05
    40%   12,15   24,31   48,62
    42%   14,28   28,56   57,11
    44%   16,65   33,29   66,59
    46%   19,28   38,55   77,11
    48%   22,18   44,37   88,74
    50%   25,38   50,77   101,53
    52%   28,89   57,78   115,56
    54%   32,72   65,44   130,89
    56%   36,89   73,79   147,58
    58%   41,42   82,85   165,70
    60%   46,33   92,66   185,31
    62%   51,62   103,24   206,49
    64%   57,32   114,65   229,29
    66%   63,45   126,90   253,80
    68%   70,02   140,04   280,08
    70%   77,05   154,10   308,19
    72%   84,55   169,11   338,22
    74%   92,56   185,11   370,22
    76%   101,07   202,14   404,28
    78%   110,12   220,23   440,47
    80%   119,71   239,42   478,85
    82%   129,88   259,75   519,50
    84%   140,62   281,25   562,50
    86%   151,98   303,96   607,92
    88%   163,96   327,92   655,83
    90%   176,58   353,16   706,32
    92%   189,86   379,73   759,45
    94%   203,83   407,65   815,31
    96%   218,49   436,98   873,97
    98%   233,88   467,75   935,50
    100%   250,00   500,00   1000,00

    0 Not allowed! Not allowed!

  31. #31
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    New results are almost amazing!
    Look at the plots of the mean value of 1024 analog readings and the R2 of the formulas:

    Click image for larger version. 

Name:	LCR-0202-33k-bypassed-1k-leak-1024mean-C&D.jpg 
Views:	27 
Size:	67.7 KB 
ID:	46337

    Click image for larger version. 

Name:	LCR-0202-33k-unbypassed-100k-leak-1024mean-A&B.jpg 
Views:	27 
Size:	66.2 KB 
ID:	46338

    0 Not allowed! Not allowed!

  32. #32
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    A simple look up table can be used to linearize (or other law) that with much greater accuracy that the typical potentiometer that uses a couple linear tracks to approximate the desired law.

    0 Not allowed! Not allowed!
    Experience is something you get, just after you really needed it.

  33. #33
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Exactly. I'm preparing some PWM/Ohm arrays for most used values, both for lin and log pots.

    Next step will be a 9V supplied voltage divider with a 1 M resistor from 9V to one LDR (upper part of the pot) to another LDR (lower part of the pot) to ground. This way I can better measure that not only the rotation is correct, but I can also keep the whole pot value (LDR1 + LDR2) constant, as a real pot.

    0 Not allowed! Not allowed!

  34. #34
    Senior Member
    Join Date
    May 2013
    Posts
    181
    Thumbs Up/Down
    Received: 2/0
    Given: 6/0
    Would it be possible to change the title of the thread?
    Who's the person I have to ask it?

    Thanks

    0 Not allowed! Not allowed!

  35. #35
    "Thermionic Apocalypse" -JT nickb's Avatar
    Join Date
    Dec 2009
    Location
    Devon, UK
    Posts
    2,786
    Thumbs Up/Down
    Received: 51/0
    Given: 32/0
    Quote Originally Posted by Roberto View Post
    Would it be possible to change the title of the thread?
    Who's the person I have to ask it?

    Thanks
    I'm pretty sure it cannot be done.

    0 Not allowed! Not allowed!
    Experience is something you get, just after you really needed it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. QSC PWM IC
    By lowell in forum Maintenance, Troubleshooting & Repair
    Replies: 94
    Last Post: 02-11-2016, 10:59 PM
  2. Any ideas for a temperature controlled fan for Bass amp
    By mikeydee77 in forum Mods & Tweaks
    Replies: 16
    Last Post: 12-04-2014, 08:34 PM
  3. PWM Class D amp using tubes?
    By PeanutNore in forum Theory & Design
    Replies: 2
    Last Post: 09-19-2014, 07:13 PM
  4. PWM frequency
    By KarbonHed in forum Tools and Coil Winding Gear
    Replies: 5
    Last Post: 06-26-2011, 04:14 PM
  5. Replies: 0
    Last Post: 03-27-2010, 01:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •