FX controller sun clock

Guide on how you can use the sun clock functionality

In Fidelix CPU:s there is a built in sun clock functionality that can be used, for example to control outside lighting.

To set up the sun clock, go to the “Settings” menu and to the page “Clock”.

Here you can:

  1. Set the geographical location of the CPU. The location uses the same coordinate system as GPS navigators. By default the CPU has the coordinates for Helsinki as shown in the picture below.
  2. Also you can see the calculated sun rise and set times.

 

To use this information to control outside lights the data needs to be read to IEC program. This can be done with the function “SunClockFB”.

With this function you can read three different data. The sun rise time in minutes, the sun set time in minutes and whether the sun is up or down.

Below is an example for reading all these data to IEC and displaying them on a graphic picture.

VAR
SunClock:SunClockFB;
RiseTime:Int;
RiseHours:Int;
RiseMinutes:Int;
SetTime:Int;
SetHours:Int;
SetMinutes:Int;
SunState:Int;
Result:Int;
END_VAR

SunClock();
RiseTime := SunClock.SunRiseMinutes;
SetTime := SunClock.SunsetMinutes;
SunState := SunClock.IsSunUp;

RiseHours := RiseTime / 60;
RiseMinutes := RiseTime mod 60;

SetHours := SetTime / 60;
SetMinutes := SetTime mod 60;

Result := SetDigitalPointF(RiseHours, 1, 'TEST_SUN_UP_H_M');
Result := SetDigitalPointF(RiseMinutes, 1, 'TEST_SUN_UP_M_M');
Result := SetDigitalPointF(SetHours, 1, 'TEST_SUN_DOWN_H_M');
Result := SetDigitalPointF(SetMinutes, 1, 'TEST_SUN_DOWN_M_M');
Result := SetDigitalPointF(SunState, 1, 'TEST_SUN_IS_UP_I');

 

The lines of code are explained below:

  1. Call the functionblock.
  2. Read the sun rise time as minutes.
  3. Read the sun set time as minutes.
  4. Read the state of the sun, 0 = down, 1 = up.
  5. Calculate the hours part of the sun rise time.
  6. Calculate the minutes part of the sun rise time.
  7. Calculate the hours part of the sun set time.
  8. Calculate the minutes part of the sun set time.
  9. Show the hours part of the sun rise time on graphic.
  10. Show the minutes part of the sun rise time on graphic.
  11. Show the hours part of the sun set time on graphic.
  12. Show the minutes part of the sun set time on graphic.
  13. Show the state of the sun on graphic.

 

And below is an example of how it can look on a graphic:

Day:

Night: