Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A state machine fades a light on and off after a button is pressed (BTN = 1) (in

ID: 3582303 • Letter: A

Question

A state machine fades a light on and off after a button is pressed (BTN = 1) (in the ON and OFF states). Another circuit has already been designed which takes an 8-bit input and proportionally control the light's brightness based on the input value (where L = 8'b00000000 is 0% off and L = 8'b11111111 (255) is 100% on). The circuit initially starts at OFF (L0 = 1) and when the button is pressed (BTN = 1) the light goes to FADE_ON and stays in FADE_ON, fading on a rate of 2 brightness values per clock (Lp2 = 1) while the brightness remains below 252 (Lgte252 = 0). Once the brightness reaches 252 or greater (Lgte252 = 1) the light should go to 100% ON (L255 = 1) as long as the button is off (BTN = 0) and stay in ON while the button is not pressed (BTN = 0). But if the button is still on (BTN = 1) and the brightness is 252 or greater (Lgte252 = 1) the light goes to the FADE_OFF state (L255 = 1) and keeps fading off at a rate of 3 brighness values per clock (Lm3 = 1) while the brightness remains above 3 (Lgt3 = 1). Once the brightness falls to 3 or lower (Lgt3 = 0) the light should go to 0% OFF (L0 = 1) as long as the button is off (BTN = 0) and stay in OFF while the button is not pressed (BTN = 0). But if the button is still on (BTN = 1) and the brightness is 3 or lower (Lgt3 = 1) the light goes to the FADE_ON state (L0 = 1) and keeps fading on at a rate of 2 brightness values per clock (Lp2 = 1) while the brightness remains below 252 (Lgte252 = 0). As long as reset is off (reset = 0), all of this will be happening as described above, but if reset = 1, then the state machine goes to the initial state OFF, brighness is reset to 0 % (L0 = 1) and stays there until reset = 0 again.

These control signals are used to control the design flow:
Lp2: L = L + 2, Lm3: L = L - 3, L0: L = 0, L255: L = 255.
These status signals come from the design flow to provide input to the control unit:
Lgte252: true when L >= 252, Lgt3: true when L > 3.

Now for the question regarding this state machine. How can we recreate the functions of this state machine using the 4 following RTL design flow components in 8-bits: 2:1 Multiplexers, Adder, Comparator, and Load Register. Draw the RTL design flow using the 4 components (basically a block diagram, if you guys remember Quartus II). The inputs are going to be (INPUTS: clock, Lp2, Lm3, L0, L255, button, reset) the outputs are going to be (OUTPUTS: Lgte252, Lgt3, [7:0] L) where L is a 8-bit variable representing the value of brighness from 0-255. Again, how can we draw a block diagram that recreates the state machine above using only 8-bit versions of 2:1 MUX's, Adders, Comparators, and Load Registers? I've been struggling for a while now.

Lgte 252 ADE O BTN Lgte252 1 BTN 1 Lgte252 1 ON BT BTN 1 OFF LO BT L255 1 Lgt o BT 1 BTN 1 LO 1 Lgta DIE OF rese E 1 BT outputs: LO, 1255, Lp2, Lm3 Inputs: Lgte252, Lg3, BTN, reset States: OFF, FADE ON, ON, FADE OFF

Explanation / Answer

Answer:

int redled = 9; // assign LEDs to pins
int greenled = 10;
int blueled = 11;
int button2 = 2; // assign pushbuttons to pins
int button3 = 3;
int button4 = 4;
int button5 = 5;
int button6 = 6;
int button7 = 7;

int button2State = 0; // variable for reading the pushbuttons
int button3State = 0;
int button4State = 0;
int button5State = 0;
int button6State = 0;
int button7State = 0;
int fadered = 0;
int fadegreen = 0;
int fadeblue = 0;



void setup () {
pinMode(button2, INPUT); //initialize pushbutton pins as input:
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(button5, INPUT);
pinMode(button6, INPUT);
pinMode(button7, INPUT);
}

void loop() {
button2State = digitalRead(button2); //check button state
if(button2State == HIGH && fadered <= 250) {
// if button is pressed increase brightness by 5
// as long as brightness isn't greater than 250
fadered +=5;
analogWrite(redled, fadered); // lights LED at current brightness level
delay(250); // allows time so button won't be detected multiple times
}

button3State = digitalRead(button3); //check button state
if (button3State == HIGH && fadered >= 5) {
// if button is pressed decrease brightness by 5
// as long as brightness isn't less than 5
fadered -=5;
analogWrite(redled, fadered); // lights LED at current brightness level
delay(250); // allows time so button won't be detected multiple times
}

button4State = digitalRead(button4); //check button state
if (button4State == HIGH && fadegreen <= 250) {
// if button is pressed increase brightness by 5
// as long as brightness isn't greater than 250
fadegreen +=5;
analogWrite(greenled, fadegreen); // lights LED at current brightness level
delay(250); // allows time so button won't be detected multiple times
}

button5State = digitalRead(button5); //check button state
if (button5State == HIGH && fadegreen >= 5) {
// if button is pressed decrease brightness by 5
// as long as brightness isn't less than 250
fadegreen -=5;
analogWrite(greenled, fadegreen); // lights LED at current brightness level
delay(250); // allows time so button won't be detected multiple times
}

button6State = digitalRead(button6); //check button state
if (button6State == HIGH && fadeblue <= 250) {
// if button is pressed increase brightness by 5
// as long as brightness isn't greater than 250
fadeblue += 5;
analogWrite(blueled, fadeblue); // lights LED at current brightness level
delay(250); // allows time so button won't be detected multiple times
}

button7State = digitalRead(button7); //check button state
if (button7State == HIGH && fadeblue >= 5) {
// if button is pressed decrease brightness by 5
// as long as brightness isn't less than 250
fadeblue -= 5;
analogWrite(blueled, fadeblue); // lights LED at current brightness level
delay(250); // allows time so button won't be detected multiple times
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote