Free Mode


Free mode is normal counter mode of ST.

st_set_free

Available commands of pid_ioctl function in free mode are as follows:

Command Sub Command Description
set mode free set mode: free mode
div sec set unit: second
ms set unit: millisecond
us set unit: microsecond
dir up set counter direction: up counter
down set counter direction: down counter
count [T] set the starting count value in down counter mode
reset - reset
get count get count value
state get current state
start - start
stop - stop

Set Counter Direction

ST can be used as both up counter and down counter. Default value of this item is up counter.

Direction Syntax
up counter pid_ioctl($pid, "set dir up");
down counter pid_ioctl($pid, "set dir down");

Set Count

When ST is down counter mode, the starting value of counter can be set.
How to set count value is as follows:

Command Syntax
set count pid_ioctl($pid, "set count T");

Note that up counter always starts from 0 and is not affected by "set count" command. Valid ranges for T in down counter are as follows:

Unit Valid Range for T
Microsecond 0 ~ (263 - 1)
milisecond 0 ~ (263 - 1) / 1,000
second 0 ~ (263 - 1) / 1,000,000

Get Count Value

Command "get count" returns a current count value.

Command Syntax
get count pid_ioctl($pid, "get count");

Examples of Free Mode

Command "get count" allows you to get the current count value of ST.

<?php
$tick = pid_ioctl($pid, "get count");
?>

example of up counter

This example sets ST to up counter and prints counter value in every second.

<?php
$pid = pid_open("/mmap/st0");               // open ST 0
pid_ioctl($pid, "set mode free");           // set mode: free
pid_ioctl($pid, "set div sec");             // set unit: second
pid_ioctl($pid, "set dir up");              // set direction: up counter
pid_ioctl($pid, "start");                   // start ST
for($i=0; $i<10; $i++)
{
    $value = pid_ioctl($pid, "get count");  // read the count value
    echo "$value\r\n";                      // print the count value
    sleep(1);
}
pid_close($pid);
?>

example of down counter

This example sets ST to down counter with the starting count value and prints counter value in every second.

<?php
$pid = pid_open("/mmap/st0");               // open ST 0
pid_ioctl($pid, "set mode free");           // set mode: free
pid_ioctl($pid, "set div sec");             // set unit: second
pid_ioctl($pid, "set dir down");            // set direction: down counter
pid_ioctl($pid, "set count 10");            // set count value: 10
pid_ioctl($pid, "start");                   // start ST
for($i = 0; $i < 10; $i++)
{
    $value = pid_ioctl($pid, "get count");  // read the count value
    echo "$value\r\n";                      // print the count value
    sleep(1);
}
pid_close($pid);
?>