oscat.lib > Modulentwicklung / Module Development
gen_rdm
(1/1)
hugo:
ein random generator der zufällige werte in festen ezitabständen erzeugt.
die ausgangsamplitude und der offset sowie die Zeitspanne zwischen 2 werten sind programmierbar
FUNCTION_BLOCK gen_rdm
VAR_INPUT
PT : TIME;
AM : REAL := 1;
OS : REAL;
END_VAR
VAR_OUTPUT
Q : BOOL;
Out : REAL;
END_VAR
VAR
tx : TIME;
last : TIME;
init : BOOL;
temp : REAL;
END_VAR
(*
version 1.0 7 feb 2007
programmer oscat
tested BY oscat
this signal generator generates a random output. The signal is defined by period time (PT),
amplitude (AM), offset (OS).
The Output waveform will have its max peak at AM/2 + OS and its minimum peak at -AM/2 + OS.
The period time PT defines how often the output signal will jump to a new randow value.
The Output Q will be true for one cycle anytime the output OUT has changed
*)
(* read system time and prepare input data *)
tx := TIME() - last;
(* init section *)
IF NOT init THEN
init := TRUE;
last := tx;
tx := t#0s;
END_IF;
(* add last if one cycle is finished *)
IF tx >= pt THEN
last := last + pt;
tx := tx - pt;
(* generate output signal *)
out := am * (RDM(0) - 0.5) + os;
q := TRUE;
ELSE
q := FALSE;
END_IF;
Navigation
[0] Themen-Index
Zur normalen Ansicht wechseln