Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Festive lights homework using state machines

Status
Not open for further replies.

BiscuitDuke

Newbie level 6
Newbie level 6
Joined
Sep 4, 2014
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
112
I need help with his homework problem:

Create a festive lights display with 8 light bulbs (B7-B0). When activated (A0=1),
the appearance is of two balls bouncing off each other, as follows: 10000001,
01000010, 00100100, 00011000, 00100100, 01000010, 10000001, repeat. Each
output configuration lasts for one second. Use bit-manipulation methods rather than
numerous states. When deactivated, the display turns off all bulbs within 1 second.

I have no clue how to use bit manipulation and my textbook doesnt do a good job at explaining. I am able to get the effect of 10000000,01000000,00100000,...,00000001 and repeat, but im having trouble shifting the left most bit to the right and right most bit to the left. any help is appreciated. thanks in advance.
 

That is so easy. Actually you can do it with any cheap MCU as PIC16f84A.

You can declare an array of 8 bytes each one, or write the combinations for each case. You can also do a mathematical operation as bit left/right shift.

If you don't care about memory and speed, you may declare every combination you wrote before in different positions of the array. Then with a counter (declare another variable) and a delay or timer interruption which increases its value. Then put the combination from the array position selecting it with the counter, which would be like that in C: PORTB=combination[counter];

Then the only thing you have to think about is the bulbs driver circuit, like relays or triacs. I recommend the last ones since you will switch the lamps on and off relatively fast and relays are not designed for that, and at least where I live relays are more expensive than a triac.

Hope being useful.
 

Use bit-manipulation methods rather than numerous states.

So, according to your condition you can't have 7 states for the following values 10000001, 01000010, 00100100, 00011000, 00100100, 01000010, 10000001. Right ?
 

Try something like this. Have two states. One is initial and another is wait state. In initial state a counter is incremented every milli sec and when milli sec (msec) is 1000 it goes to wait state and waits there for 1 sec (another counter used) and then returns to initial state and also clears counter in initial state and also the one in wait state. There will be another counter (thitd) which will increment in wait state and this is for LED. There will be six arrows from and to initial state and each will have a condition like if(cnt==1) Action B = 10000001, if(cnt==2) Action B = 01000010...
 

Try something like this. Have two states. One is initial and another is wait state. In initial state a counter is incremented every milli sec and when milli sec (msec) is 1000 it goes to wait state and waits there for 1 sec (another counter used) and then returns to initial state and also clears counter in initial state and also the one in wait state. There will be another counter (thitd) which will increment in wait state and this is for LED. There will be six arrows from and to initial state and each will have a condition like if(cnt==1) Action B = 10000001, if(cnt==2) Action B = 01000010...

Even though Im really not suppose to do it like this, its better than nothing so i went with it. Right now my problem is getting the cycle to repeat in one second, but it takes two to restart. heres my SM

 

It is actually 4 display states with 2 directions states making 8 states depending on previous state to determine next state.
Using 100ms delay per state jump this will cycle in less than 1 s or use 125ms and be exactly 1s.

If you have these as variables you can design your state machine with Tool
 

Alright, I got the working state diagram, here it is:



Now, just to fill in the requirement of the assignent, I need to reduce this part:
Code:
++cnt;
if(cnt==1){
B=0x81;
}
else if(cnt==2){
B=0x42;
}
else if(cnt==3){
B=0x24;
}
else if(cnt==4){
B=0x18;
}
else if(cnt==5){
B=0x24;
}
else if(cnt==6){
B=0x42;
}
else if(cnt==7){
B=0x81;
}

to something simpler using bit manipulation (in other words, to get rid of all the if/else statements). Thanks everyone for your help so far.
 

I doubt that referring to bit operations will really simplify the code, measured by number of instructions or execution time. A decoder table is probably the most efficient implementation.
 

Yes, even if the MCU is going to control just those 8 lights.

He can also design different effects, it's better when several lights are available (more than 8, like 40 or 50). You can charlieplex the MCU pins to drive as much lights.
 

I believe he suspected that he was not using the right approach, which is correct. It is likely a learning exercise for the State machine software and as I pointed out , each memory cell is a state and there are two variables direction (1,0) and output ( which 4 unique values)

It would be better to begin fresh with initial conditons for both then add states to create the process rather than If statements. As this is how more complex State Machines are designed.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top