Temperature polling in PAC

Discussion in 'C-Bus Wired Hardware' started by ssaunders, Oct 7, 2009.

  1. ssaunders

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    243
    Likes Received:
    35
    Location:
    Melbourne
    Hi all.

    I'm having issues with some code that operates perfectly in PICED, but when run on a PAC does not function.

    The code reads the value of a Monitor that is configured to poll a 5031TS, and based on the reading sets the speed of a small exhaust fan.

    As mentioned, the code does what it is supposed to do in PICED with logic running and connected to CBus. But from what I can debug, the value of the monitor returns zero on the PAC. I have read on this forum that the use of monitors and GetUnitParameter did not used to be supported on a PAC, and this used to be mentioned specifically in the help file. But the firmware change log for PAC says support was introduced in 3.0 (and a fix in 3.43), so I don't think this is my problem. PICED in use is 4.7.1.0 with firmware 3.43.0 on the PAC.

    A single monitor is set up to poll the 5031TS at address 30 on network 253 every 60 seconds. The PAC is on network 254.

    Any insight appreciated.

    Steve.

    Code:
    HutchAVMinTemp = 22;
    HutchAVMaxTemp = 50;
    HutchAVMinLevel = 50;
    
    HutchAVTemp : Real;
    HutchAVExhaust : Integer;
    
    (Module: Environment)
    
    { Retrieve Hutch AV cupboard temperature sensor value every 4 minutes and adjust fan acordingly }
    
    Delay(240);
    
    HutchAVTemp := GetUnitParameter("Hutch", 30, ptTemperature);
    if not GetUnitParamStatus("Hutch", 30, ptTemperature) then ExitModule;
    
    if HutchAVTemp <= HutchAVMinTemp then
    begin
      if GetCBusLevel("Hutch","Lighting","Hutch AV Fan") > 0 then SetCBusState("Hutch","Lighting","Hutch AV Fan", OFF);
      ExitModule;
    end;
    
    { If AV cupboard temperature raised then set exhaust fan speed accordingly }
    HutchAVExhaust := HutchAVMinLevel + Round((255 - HutchAVMinLevel) * (HutchAVTemp - HutchAVMinTemp) / (HutchAVMaxTemp - HutchAVMinTemp));
    if HutchAVExhaust > 255 then HutchAVExhaust := 255;
    
    if GetCBusLevel("Hutch","Lighting","Hutch AV Fan") <> HutchAVExhaust then SetCBusLevel("Hutch","Lighting","Hutch AV Fan", HutchAVExhaust, "0s");
    (End module)
    
     
    ssaunders, Oct 7, 2009
    #1
  2. ssaunders

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    243
    Likes Received:
    35
    Location:
    Melbourne
    Temperature polling in PAC working

    Never mind. No problem with monitors or GetUnitParameter. Other evil forces must have been at work, so fixed now. :eek:

    Working code below for the record in case it helps others. Subtle changes are the positioning of GetUnitParamStatus and use of simplified GetLighting? and SetLighting? instead of GetCBus? and SetCBus?. The bridge broadcasts messages sent on the PAC local network over to the "Hutch" network where the dimmer and temp sensor live.

    Code:
    HutchAVMinTemp = 22;
    HutchAVMaxTemp = 50;
    HutchAVMinLevel = 0;
    
    HutchAVTemp : Real;
    HutchAVExhaust : Integer;
    HutchAVTempLevel : Integer;
    
    *** Module AVFan ***
    { Retrieve Hutch AV cupboard temperature sensor value every 2 minutes and adjust fan acordingly }
    
    if GetUnitParamStatus("Hutch", 30, ptTemperature) then
    begin
      HutchAVTemp := GetUnitParameter("Hutch", 30, ptTemperature);
    
      HutchAVTempLevel := Round(HutchAVTemp * 5);
      if HutchAVTempLevel < 0 then HutchAVTempLevel := 0 else if HutchAVTempLevel > 255 then HutchAVTempLevel := 255;
      if GetLightingLevel("Hutch AV Temp") <> HutchAVTempLevel then SetLightingLevel("Hutch AV Temp", HutchAVTempLevel, 0);
    
      if HutchAVTemp <= HutchAVMinTemp then
        { If AV cupboard temperature is below minimum set the fan off }
        HutchAVExhaust := 0
      else
      begin
        { If AV cupboard temperature raised then set exhaust fan speed accordingly }
        HutchAVExhaust := HutchAVMinLevel + Round((255 - HutchAVMinLevel) * (HutchAVTemp - HutchAVMinTemp) / (HutchAVMaxTemp - HutchAVMinTemp));
        if HutchAVExhaust > 255 then HutchAVExhaust := 255;
      end;
      
      if GetLightingLevel("Hutch AV Fan") <> HutchAVExhaust then SetLightingLevel("Hutch AV Fan", HutchAVExhaust, 0);
    
      Delay(115);
    end;
    
    Delay(5);
    Dimmer channel is tuned for a minimum level of 55 to ensure fan rotates at lowest level and maximum level of 80 to keep the noise down at fastest (and also because only so much air can be sucked into the cupboard through gaps). The constant HutchAVMinLevel is now defunct, as I worked out that to tune the constants would require too many PAC EEPROM cycles for comfort given its lifespan, so tuning with min/max levels is far superior in that regard. "Hutch AV Fan" level goes from 0 to 255 proportional with temperatures 22 to 50 celcius. Setting the "Hutch AV Temp" group is purely so I can monitor temperature in Toolkit for tuning, and is the sensor temperature multiplied by 5 allowing for integer representation with 0.2 degree resolution.

    Been running for a couple of days now, and doing exactly what I want it to. Nice and quiet, and keeps the temperature down beautifully.

    Cheers, all.
     
    Last edited by a moderator: Oct 10, 2009
    ssaunders, Oct 7, 2009
    #2
  3. ssaunders

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    Thanks for the update. It saves me spending hours tracking down a non-existent problem :)
     
    Darren, Oct 8, 2009
    #3
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.