Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Sunset time does not perform operation

alverman
2019-02-13
2019-02-28
  • alverman - 2019-02-13

    good morning,
    I would like to close my electric shutters at sunset.
    At the moment a closing time is a TOD imposed and the shutters close regularly at the set time.
    In my project I have a SystemTimePrg module with a submodule with an OSCAT_BASIC.SUN_TIME block.

    I set the Latitude, Longitude and Date in the SystemTimePrg module, and the OSCAT_BASIC.SUN_TIME module gives me the sunrise time of sunset and the declination of the sun.

    So I assigned the time of sunset as TOD variable in my OSCAT_BUILDING_TIMER that controls the blinds but at the time set but does not start.
    Even if I force a different value to test the operation does not start.

    The only difference from the manually set time is that the TOD variable is in HH format: mm while sunset is TOD HH: mm: ss.milliseconds
    Even if I force the TOD variable sunset in HH: mm does not start
    While the assignment of the TOD variables was previously imposed by the shutter control module, now I assign the variables to the SystemTimePrg module

    Where I'm wrong
    Thanks, Alberto

     
  • eschwellinger

    eschwellinger - 2019-02-13

    Hi,
    think you need to attach a small project…

    BR
    Edwin

     
  • elconfa - 2019-02-13

    I use this and it is OK:

    T_tramonto : TIME;
    SUN_TIME_casa : OSCAT_BASIC.SUN_TIME;
    udiUtcTime : UDINT;
    dDateUTC : DATE;

    ( get time in seconds since 1970 )
    udiUtcTime := SysTimeRtcGet(udiResult);
    IF udiResult <> 0 THEN
    RETURN;
    END_IF

    (converts the UTC time (seconds) to a DATE variable d#yyyy-mm-dd )
    dDateUTC := UDINT_TO_DATE(udiUtcTime);

    SUN_TIME_casa(
    LATITUDE:= 45.6291500,
    LONGITUDE:= 9.1518900,
    UTC:= dDateUTC,
    H:= ,
    MIDDAY=> ,
    SUN_RISE=> ,
    SUN_SET=> ,
    SUN_DECLINATION=> );

    T_tramonto := TOD_TO_TIME(SUN_TIME_casa.SUN_SET) + T#60M;

    Bye
    Massimo

     
  • alverman - 2019-02-13

    Thanks elconfa,
    I tried your code and it works but if I bring the value of T_tramonto in my timer as time of execution does not start.
    I did not try that hour directly but I forced an hour closer to the time of the test and the timer does not start.
    The timer is in a PRG Function Block Diagram while your code I put in SystemTimePrg which is a ST-POU

    How can I solve

     
  • alverman - 2019-02-13

    do not know why it does not work !!
    Of course I can not wait until tomorrow to test it so I force the value of TIME_DW_CUCINA in the OSCAT_TIMER2 module to start input at a time near the time of testing and the timer will not start.
    The value of the sunset I assign from the SystemTimePrg module

    Alberto

    IMG: P2.png

    IMG: P1.png

     
  • elconfa - 2019-02-14

    this is my complete function:

    ( get time in seconds since 1970 )
    udiUtcTime := SysTimeRtcGet(udiResult);
    IF udiResult <> 0 THEN
    RETURN;
    END_IF

    (converts the utc time (seconds) to a SYSTIMEDATE with year, month , day, and time etc. )
    udiResult := SysTimeRtcConvertUtcToDate(udiUtcTime, strTimeDate);
    IF udiResult <> 0 THEN
    RETURN;
    END_IF

    (converts the utc time to the local time, regarding timezone and summer time in seconds )
    udiResult := SysTimeRtcConvertUtcToLocal(udiUtcTime, udiUtcTimeLocal);
    IF udiResult <> 0 THEN
    RETURN;
    END_IF

    (convert the seconds in SYSTIMEDATE format, which show, year, month, day, hour, minutes ... )
    udiResult := SysTimeRtcConvertUtcToDate(udiUtcTimeLocal, strTimeDateLocal);
    IF udiResult <> 0 THEN
    RETURN;
    END_IF

    (converts the UTC time (seconds) to a DATE_AND_TIME variable dt#yyyy-mm-dd-hh:mm:ss )
    dtDateTimeUTC := UDINT_TO_DT(udiUtcTime);

    ( converts the DATE_AND_TIME to TOD(time of day) )
    todTimeOfDayUTC := DT_TO_TOD(dtDateTimeUTC);

    (converts the UTC time (seconds) to a DATE variable d#yyyy-mm-dd )
    dDateUTC := UDINT_TO_DATE(udiUtcTime);

    Calendar.DST_EN:=TRUE; // switch summertime
    Calendar.OFFSET:=60; //UTC Offset
    Calendar.UTC:=dtDateTimeUTC;

    SUN_TIME_casa(
    LATITUDE:= 45.6291500,
    LONGITUDE:= 9.1518900,
    UTC:= dDateUTC,
    H:= ,
    MIDDAY=> ,
    SUN_RISE=> ,
    SUN_SET=> ,
    SUN_DECLINATION=> );

    T_tramonto := TOD_TO_TIME(SUN_TIME_casa.SUN_SET) - T#60M;

    cc:=TOD_TO_TIME(Calendar.LTOD);

    IF (cc >= (T_tramonto - T#1S)) AND (cc < (T_tramonto + T#1S)) THEN
    Orologio_T_chiudeTutto := TRUE;
    ELSE
    Orologio_T_chiudeTutto := FALSE;
    END_IF

    For BLINDS I create a function. May be it is useful for you:

    FUNCTION_BLOCK FB_Ramp_Up_Down
    VAR_INPUT
    SET : BOOL;
    PT_UP : TIME;
    PT_DN : TIME;
    E : BOOL := TRUE;
    UP : BOOL := TRUE;
    RST : BOOL;
    LastPosition : word;
    END_VAR
    VAR_OUTPUT
    OUT : WORD;
    BUSY: BOOL;
    HIGH : BOOL;
    LOW : BOOL;
    END_VAR
    VAR
    rmpUP : OSCAT_BASIC._RMP_W;
    rmpDN : OSCAT_BASIC._RMP_W;
    END_VAR

    ( generate ramp )
    rmpUP(dir := UP, E := E AND UP, TR := PT_UP, rmp := out);
    rmpDN(dir := UP, E := E AND NOT UP, TR := PT_DN, rmp := out);

    ( set or reset operation )
    IF RST THEN
    out := 0;
    ELSIF SET THEN
    out := LastPosition;
    END_IF;

    ( checks for outputs stable and reset or set busy flag )
    low := out = 0;
    high := out = 65535;
    busy := NOT (low OR high) AND E;

     
  • alverman - 2019-02-14

    OK elconfa,
    but the boolean variable Orologio_T_chiudeTutto where is in your code ?
    Thanks, Alberto

     
  • elconfa - 2019-02-15

    alverman hat geschrieben:
    OK elconfa,
    but the boolean variable Orologio_T_chiudeTutto where is in your code ?
    Thanks, Alberto

    Global var
    It is used in other part of program to perform that operation

     
  • alverman - 2019-02-23

    Nothing ....... does not work.
    I set the sunset variable in GVL and it is GVL.TIME_DW_CUCINA
    I followed your code but if I put the global variable containing the calculated sunset time the timer will not start.
    If the hourly variable is assigned to the global variable, the timer starts with the time of sunset no.
    I checked that the sunset variable shows the time and in edit mode I see it correct but the timer does not start.
    Why ?

    IMG: c1.png.jpg

     
  • alverman - 2019-02-26

    work work

     
  • elconfa - 2019-02-27

    what did you change?

     
  • alverman - 2019-02-28

    elconfa hat geschrieben:
    what did you change?

    I only changed the type of representation on the edit page.
    I know it sounds absurd but now it works.
    Before I saw TOD # before the hour, but now I only see hours and minutes and it works

    IMG: setup.png.jpg

     

Log in to post a comment.