Fader
 
 

Purpose: To implement a fader on the development board using the MACH4 - 64/32 CPLD. The instructions can be found on the Digital Systems Lab Web Site

Procedure:
We create a new project as shown in the previous experiments. We will develop the program using the instructions from the Digital Systems Lab Web Site.
This fader will be implemented in two stages by two state machines. In the first stage, we implement the so-called Pulse-Width-Modulation (PWM) of the LED's. We take a 4-bit counter at clock frequency of 2kHz and we take another 4-bit register. If the value in the counter is smaller than the value in the register, the LED will go on. Else, it will remain off. This is our first state machine.

In the second stage, we implement the second state machine. Now, we start changing the value of the register using a second clock. However, the change of value of this register will be much slower than the other clock, which is set to 2kHz.

 
 
You can download the program from here: fader.abl. There is also another fader implementation with only one segment fading. You can download it from here: faderalone.abl. There is more detailed information about the making of the program in "The Program" section.
 
 
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.

 
 

Observations:

-The fader is actually an illusion. The intensity of the light from the LED's never changes. When we change the value on the register with the second clock, the on-off time of the LED also starts changing. This is perceived by our eye as a change in intensity and so we call it a FADER.

 
 

Problems and Conclusion:

-We needed two counters: One that was incremented each clock cycle and one that was only incremented approximately once per second. The LED should glow whenever the value of the fast counter was smaller than the value of the slow counter. Because the clock was set to its maximum speed, the fast counter was incremented approximately 2000 times per second and so the LED was switched on and off very rapidly, which led to an illusion of a dim glow. The brightness increased when the small counter reached higher values, because then the LED On/Off ratio increased. The longer the LED was on, the brighter the light appeared to be.
-For 2 LEDs the program works perfectly. But trying to do it for more, although the syntax is correct gives compilation errors. It is because somehow the maximum number of nodes of the board is exceeded.

 
 

The movie of the experiment -this is the .avi demonstration of how the program works.