ToolBox
Description
This library has two timer functions that expands the capabilities of B&R’s TON function. The last function is used to check an input against an ideal value and percentage tolerance.
Functions / Function Blocks
ProcessTimer FB
This library is used to calculate the time required to complete a process.
Parameters
| Direction | Name | Type | Description |
|---|---|---|---|
| In | Enable | BOOL | Enables the timer |
| In | Reset | BOOL | Resets calculated times |
| In | Count | UDINT | Number of processes completed since reset |
| Out | AverageTime | TIME | Average elapsed time per a count |
| Out | FilteredTime | TIME | Rolling average of last 10 elapsed times |
Usage
if (proccessStarted){
proccessStarted = 0;
ProcessTime_0.Count++;
ProcessTime_0.Enable = 1;
}
ProcessTimer(&ProcessTime_0);
if (processFinished){
processFinished = 0;
ProcessTime_0.Enable = 0;
timeOfProcess = ProcessTime_0.AverageTime;
}
TON_Pause FB
This is a timer function with the capability to pause and resume the timer.
Parameters
| Direction | Name | Type | Description |
|---|---|---|---|
| In | IN | BOOL | Enables timer while TRUE |
| In | Pause | BOOL | Pauses timer while TRUE |
| In | PT | TIME | Amount of time before the Q bit will go high |
| Out | Q | BOOL | True indicates the timer is complete |
| Out | ET | TIME | Current elapsed time since enabled |
| Out | PercentCompleted | REAL | Percentage of PT that the timer has completed (Et in percent form) |
| Out | TimeLeftRunning | TIME | When a pause has been initiated this output will retain the time left till timer is complete |
Usage
void _INIT ProgramInit(void)
{
PauseTimer.PT = 1000000;
startTimer = 1;
}
void _CYCLIC ProgramCyclic(void)
{
if (startTimer){
startTimer =0;
PauseTimer.IN = 1;
}
if(maintanceActive && !PauseTimer.Q){
PauseTimer.Pause = 1;
} else {
PauseTimer.Pause = 0;
}
timeRunning = PauseTimer.ET;
TON_Pause(&PauseTimer);
}
WithinPercent()
This function determines whether or not an input is within a percentage tolerance of an ideal value (setValue).
Parameters
| Direction | Name | Type | Description |
|---|---|---|---|
| In | InputValue | REAL | The value being checked. |
| In | SetValue | REAL | The ideal value for the input. |
| In | PercentWindow | REAL | The tolerance represented in percent form. |
| Out | return | BOOL | 0 indicates the input value is NOT within tolerance. 1 indicates the value is within tolerance. |
Usage
void _INIT ProgramInit(void)
{
// Setting tolerance to within 15% of idealTemp
tempTolerance = 15;
idealTemp = 85;
}
void _CYCLIC ProgramCyclic(void)
{
// Set an active warning if the tempInput is out of tolerance
if(!WithinPercent(tempInput, idealTemp, tempTolerance)){
activeWarning = 1;
} else {
activeWarning = 0;
}
}