Tutorial RevPiTimer

In this tutorial we want to configure a virtual timer for the RevPi Flat.

The virtual device “RevPiTimer” is available in PiCtory . RevPiTimer is a timer clock that switches on and off to the minute and on a weekly basis. There are 16 switching times available for each RevPiTimer. However, you can also use several RevPiTimer if 16 switching times are not sufficient.

We set the following switching times:

#Timer

Switch on

Switch off

Day

Time

Day

Time

1

Mon – Fri

7:00 AM

Mon – Fri

5:00 PM

2

Sat

10:00 AM

Sat

10:15 AM

The logon window opens.

  • Log on with the username “admin”.
  • Enter your password. You can find it on the sticker on the side of your RevPi Flat.
  • Click on “Login”.

You can now see the current device status of your RevPi Flat.

  • Click on the “Apps” tab.
  • Click on the start button behind the entry “PiCtory” to open PiCtory.
  • PiCtory opens.
  • Select the virtual device “RevPiTimer” from the device catalog.
  • Drag and drop it onto the configuration board.
  • Click on “File -> Save as”. This saves the configuration.
  • Click on “Tools -> Reset Driver”. This restarts the driver.

Programming the Timer

Each timer consists of a switch-on time and a switch-off time.

Timer

Variable

Function

1

T1_ON_active_day

Switch on bit field: on days and active or inactive

1

T1_ON_hour

Switch on hours 00 to 24

1

T1_ON_minute

Switch on minutes 00 to 59

1

T1_OFF_active_day

Switch off bit field: on days and active or inactive

1

T1_OFF_hour

Switch off hours 00 to 24

1

T1_OFF_minute

Switch off minutes 00 to 59

2

T2_ON_active_day

Switch on bit field: on days and active or inactive

2

T1_ON_hour

Switch on hours 00 to 24

2

T1_ON_minute

Switch on minutes 00 to 59

2

T1_OFF_active_day

Switch off bit field: on days and active or inactive

2

T1_OFF_hour T1_OFF_hour

Switch off hours 00 to 24

2

T1_OFF_minute

Switch off minutes 00 to 59

16

T16_ON_active_day

Switch on bit field: on days and active or inactive

The bit field for days and activation is coded as follows:

T1_ON_active_day und T1_OFF_active_day

Bit

7

6

5

4

3

2

1

0

Value

Active

Sun

Sat

Fri

Thu

Wed

Tue

Mon

In our example we need to enter the following values:

Timer1

Days: Mon – Fri + activation, time: 7:00 AM till 5:00 PM

Bit

7

6

5

4

3

2

1

0

Value

Active

Sun

Sat

Fri

Thu

Wed

Tue

Mon

Mon – Fri

1

0

0

1

1

1

1

1

This results in the binary value “10011111”. This corresponds to the decimal value “159”. This value must be written to the process image later on.

Therefore, following values have to be written into the process image for Timer1:

Variable

Value

T1_ON_active_day

159

T1_ON_hour

7

T1_ON_minute

0

T1_OFF_active_day

159

T1_OFF_hour

17

T1_OFF_minute

0

You can do this for example using the tool “piTest”. Open the command line.

  • Enter the following commands:

piTest –w T1_ON_active_day,159

piTest –w T1_ON_hour,7

piTest –w T1_ON_minute,0

piTest –w T1_OFF_active_day,159

piTest –w T1_OFF_hour,17

piTest –w T1_OFF_minute,0

Timer2

Days: Saturday + activation, time: 10:00 AM till 10:15 AM

Bit

7

6

5

4

3

2

1

0

Value

Active

Sun

Sat

Fri

Thu

Wed

Tue

Mon

Mon – Fri

1

0

1

0

0

0

0

0

This results in the binary value “10100000”. This corresponds to the decimal value “160”.

Therefore, following values have to be written into the process image for Timer2:

Variable

Value

T1_ON_active_day

160

T1_ON_hour

10

T1_ON_minute

0

T1_OFF_active_day

160

T1_OFF_hour

10

T1_OFF_minute

15

  • Enter the following values in the command line:

piTest –w T2_ON_active_day,160

piTest –w T2_ON_hour,10

piTest –w T2_ON_minute,0

piTest –w T2_OFF_active_day,160

piTest –w T2_OFF_hour,10

piTest –w T2_OFF_minute,15

Query Timer Events

The variable “TimerStatus” indicates whether a timer event is currently active. This is a bit field with 16 bits.

If the bit is set, the timer is on. If the bit is not set, the timer is off.

TimerStatus

Bit

7

6

5

4

3

2

1

0

Timer No.

Timer 8

Timer 7

Timer 6

Timer 5

Timer 4

Timer 3

Timer 2

Timer 1

Mon – Fri

15

14

13

12

11

10

9

8

Timer No.

Timer 16

Timer 15

Timer 14

Timer 13

Timer 12

Timer 11

Timer 10

Timer 9

To write a program that responds to Timer1, you can do the following, for example:

Find out where the bit of Timer1 is located in the process image:

piTest -v TimerStatus

variable name: TimerStatus

offset: 11

length: 16

bit: 0

There you go! It is in byte 11, in the first bit!

  • Query this bit:

piTest -g 11,0

Get bit 0 at offset 11. Value 0

If you only want to output the value without text for processing it in a script, you can simply query it like this:

piTest –q -g 11,0

0

Set Timer Inactive

Switching the timer inactive means that the switching times are not overwritten but also not executed.

If you want to disable a timer you can do this by deleting the respective “Active” bit in the variable “T1_ON_active_day” and “T1_OFF_active_day”. It is bit 7.

Find the variables in the process image:

piTest -v T1_ON_active_day

variable name: T1_ON_active_day

offset: 13

length: 8

bit: 0

piTest -v T1_OFF_active_day

variable name: T1_OFF_active_day

offset: 16

length: 8

bit: 0

The offsets are therefore as follows:

  • T1_ON_active_day: 13
  • T1_OFF_active_day: 16
  • Set switch-on and switch-off time inactive:

piTest -s 16,7,0

Set bit 7 on byte at offset 16. Value 0

piTest -s 13,7,0

Set bit 7 on byte at offset 13. Value 0

Variants

You only want to define a switch-on time, but no switch-off time? No problem! Set the “active bit” only at the switch-on time and omit it at the switch-off time.

In the example for Timer1 you can change it like this:

piTest -s 16,7,1

Set bit 7 on byte at offset 16. Value 1

piTest -s 13,7,0

Set bit 7 on byte at offset 13. Value 0