Strange arithmetic problem

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by Ingo, Jun 17, 2009.

  1. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    I cannot figure out why I get different results for an arithmetic function from PICED and a PAC. Below is what I am trying to achieve.

    What the above is supposed to do is take the Lux reading from the LightLevel meter, convert it to a CBus level of between 0 and 255. My max light level is 3370 and my minimum is 25. If I run through the arithmetic manually I get 255.3 as max and 1.9 as minimum.

    Now, when I use the Round() function to populate Group 245 it ends up as either 255, for Max, and 2, for Min, which is absulutely what I intend.

    When I download this code to the PAC it gives me 250 as max and not 255. As soon as I run PICED in simulation mode and run the logic code ONCE it changes Group 245 from 250 to 255. After a short while the PAC updates the counter back down to 250.

    I have fried my brain trying to figure this out, and I will feel pretty stupid if I missed something, but why is this behaviour different between the two units?

    Ingo
     
    Ingo, Jun 17, 2009
    #1
  2. Ingo

    Mark

    Joined:
    Oct 28, 2004
    Messages:
    196
    Likes Received:
    1
    Location:
    Grenoble, France
    Light Level s in PAC/C-Touch

    Hi Ingo,

    I suspect the problem is with the range of Light Level values. PICED runs on a machine with grunt, so it can do an accurate floating point calculation of the light level. PAC has limited resources, so it uses a look up table and a multiplier to approximate the same calculation.
    Exactly how the Light Level is calculated depends on the sensor you are using (SENLL or Multisensor), so if you let me know which you are using i can give more details. Otherwise, just check the max value you actually get in the PAC and adjust your calculations accordingly.

    Sorry for the troubles!
    Mark.
     
    Mark, Jun 23, 2009
    #2
  3. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Hi mark,

    I am using a SENLL. I'll relook at my calculations but I get 3370 from PICED and if I reverse the calculation and work out what the PAC must give me then it will be 3300. Is that possible??

    PICED: 3370 / 13.2 = ~255 and in reverse for the PAC:
    PAC: 250 * 13.2 = 3300.

    If this is actually true then why would the PAC report 3300 on Max light if PICED reports 3370?

    Ingo
     
    Ingo, Jun 23, 2009
    #3
  4. Ingo

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,427
    Likes Received:
    64
    Location:
    Adelaide
    The error is in the conversion of the (8 bit) reading from the light level sensor into lux.

    The conversion involves a calculation of e^n (where e is the natural logarithm)... PICED is running on a PC and does this properly using it's big grunty processor and math libraries. The PAC's much more modest processor uses an integer lookup table which has some rounding errors.

    Nick
     
    NickD, Jun 24, 2009
    #4
  5. Ingo

    Ingo

    Joined:
    Dec 2, 2006
    Messages:
    290
    Likes Received:
    1
    Location:
    South Africa
    Ok, I understand. So for me to 'correct' this problem I should assume the PAC will always return 250 and adjust my calculations from there. 3300 is close enough to 3370 anyways.

    Ingo
     
    Ingo, Jun 25, 2009
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.