Skip to content

Commit

Permalink
replace timedelay with a .comp version, so that we get uniform naming…
Browse files Browse the repository at this point in the history
… and automatic documentation
  • Loading branch information
jepler committed Dec 31, 2007
1 parent 2414935 commit 5e8e3d4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 255 deletions.
249 changes: 0 additions & 249 deletions src/hal/components/timedelay.c

This file was deleted.

37 changes: 37 additions & 0 deletions src/hal/components/timedelay.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
component timedelay "The equivalent of a time-delay relay";

pin in bit in;
pin out bit out """Follows the value of \\fBin\\fR after applying the delays
\\fBon-delay\\fR and \\fBoff-delay\\fR.""";

param rw float on-delay = 0.5 """The time, in seconds, for which \\fBin\\fR must be
\\fBtrue\\fR before \\fBout\\fR becomes \\fBtrue\\fR""";
param rw float off-delay = 0.5 """The time, in seconds, for which \\fBin\\fR must be
\\fBfalse\\fR before \\fBout\\fR becomes \\fBfalse\\fR""";

param r float elapsed "Current value of the internal timer";
variable double timer;

function _;

license "GPL";
author "Jeff Epler, based on works by Stephen Wille Padnos and John Kasunich";
;;
hal_bit_t in_ = in;
if(in_ != out) {
timer += fperiod;
elapsed = timer;
if(in_) {
if(timer >= on_delay) {
out = 1;
timer = 0.0;
}
} else {
if(timer >= off_delay) {
out = 0;
timer = 0.0;
}
}
} else {
timer = 0.0;
}
12 changes: 6 additions & 6 deletions tests/timedelay.0/test.hal
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
loadrt sampler cfg=bb depth=4096
loadrt sampler cfg=bb depth=100
loadrt timedelay
loadrt not
loadrt threads name1=thread period1=1953125

# Thread period is 1/512 second.
# on-delay is 1/128 + 1/1024 second, or 4.5 periods.
# off-delay is 1/64 + 1/1024 second, or 8.5 periods.
setp delay.0.on-delay 0.0087890625
setp delay.0.off-delay 0.0166015625
setp timedelay.0.on-delay 0.0087890625
setp timedelay.0.off-delay 0.0166015625

net square not.0.out => delay.0.in sampler.0.pin.0
net delayed delay.0.out => not.0.in sampler.0.pin.1
net square not.0.out => timedelay.0.in sampler.0.pin.0
net delayed timedelay.0.out => not.0.in sampler.0.pin.1

addf not.0 thread
addf process_delays thread
addf timedelay.0 thread
addf sampler.0 thread

start
Expand Down

0 comments on commit 5e8e3d4

Please sign in to comment.