The
Program:
This is the source for one segment implementation:
MODULE fader
TITLE
'LED fader'
"@alternate
!U22A
PIN;
SELCLK
PIN;
CK1 PIN;
Q4n0 node ISTYPE 'REG';
Q3n0 node ISTYPE 'REG';
Q2n0 node ISTYPE 'REG';
Q1n0 node ISTYPE 'REG';
R4n0
node ISTYPE 'REG';
R3n0 node ISTYPE 'REG';
R2n0 node ISTYPE 'REG';
R1n0 node ISTYPE 'REG';
glow
= [Q4n0, Q3n0, Q2n0, Q1n0];
equations
glow.CLK = SELCLK;
glow := glow+1;
[R4n0, R3n0, R2n0, R1n0] := [R4n0, R3n0, R2n0, R1n0]
+ 1;
[R4n0,
R3n0, R2n0, R1n0].clk = CK1;
when
([Q4n0, Q3n0, Q2n0, Q1n0]<[R4n0, R3n0, R2n0, R1n0])
then U22A = 1;
else U22A = 0;
END
It can be seen that u22A is the output LED. There
are two clocks SELCLK and CK1. the two 4-bit registers
are [R4n0, R3n0, R2n0, R1n0] and [Q4n0, Q3n0, Q2n0,
Q1n0], which is the register 'glow'. We have the counter
[R4n0, R3n0, R2n0, R1n0].clk, which operates at 2kHz
(we choose clock no. 11 for CK1 in Location Assignments,
and the set the frequency to 2KHz on the board). We
do have the 'glow' register too. Whenever the value
on the glow register is smaller than the value of
the counter, the LED u22a goes on. Else, it remains
off. Using the second clock, SELCLK, we start incrementing
the value on the register 'glow' by one. This frequency
is much lesser than 2KHz. Hence, the on-off time of
u22A goes on varying, when we execute the design.
On the board, we see the intensity of the LED changing.
That is why we call it a fader.
We
designed this fader for a single segment. But, it
can be extended to arbitrary number of segments. You
can see an example by downloading fader.abl where
two segments are fading.