0
\$\begingroup\$

I am writing code for a door lock combination. My inputs are b0, b1, b2 and b3, which correspond to the buttons to enter the code to unlock a door. The code to unlock this particular door is b2 --> b2 ---> b3 ---> b1.

However, between transitions,the code must take into account the user lifting their finger off the button before proceeding to press the next button for the door code.

ie. b2 --> release --> b2 --> release --> b2 --> release --> b3 ---> release --> any button ---> reset. If the user presses the wrong value in the process, the state must go back to the reset.

The picture below is my code, however, the synthesis is failing. I have looking through the next state logic of my code, but I can't seem to find any issue with it, and I am not getting any kind of syntax errors either.

I appreciate any help, thank you for your time.

https://i.stack.imgur.com/8zBji.png

 module Lock(input logic clk, reset, b0, b1, b2, b3,
 output logic unlock);

typedef enum logic[2:0] {s0, s1, s2, s3, s4, s5, s6, s7, s8} statetype;
statetype state, nextstate;



//state register
always_ff @(posedge clk, posedge reset)
    if (reset) state <= s0;
    else state<=nextstate; 

//next state logic    
always_comb
case (state)
s0: if (b2 & ~b1 & ~b0 & ~b3) nextstate = s1;
    else if (~(b2 & ~b1 & ~b0 & ~b3))nextstate = s0;//ie. if did not press the corrrect button (b2)

s1: if (~b2 & ~b1 & ~b0 & ~b3) nextstate = s2; //. ie move a state ahead when you release the b2
    else if (b2 & ~b3 & ~b1 & ~b0) nextstate = s1; //ie. If user is holdig down the button b2.

s2: if (b2 & ~b1 & ~b0 & ~b3) nextstate = s3; //entering the second digit of the door code
 else if(~(  b2 & ~b1 & ~b0 & ~b3))nextstate = s0; //back to reset if the second digit inserted is not b2
 else if  ( ~ b2 & ~b3 & ~b1 & ~b0) nextstate=s2;//e. if still havent pressed a button, stay in state s2

s3: if (~b2 & ~b1 & ~b0 & ~b3) nextstate = s4; // ie. when releasing button b2
     else if (b2 & ~b1 & ~b0 & ~b3) nextstate = s3;//ie. if holding down b2 still, stay in s3.

s4: if (b3 & ~b0 & ~b1 & ~b2) nextstate = s5;
   else if (~(b3 & ~b0 & ~b1 & ~b2))nextstate = s0;
    else if  ( ~ b2 & ~b3 & ~b1 & ~b0) nextstate=s4;

s5: if (~b2 & ~b1 & ~b0 & ~b3) nextstate = s6;
    else if (b3 & ~ b0 & ~ b1 & ~b2) nextstate=s5;

s6: if (b1 & ~b0 & ~b1 & ~b2 & ~b3) nextstate=s7;
    else if (~ (b1 & ~b0 & ~b1 & ~b2 & ~b3))nextstate=s0;
     else if  ( ~ b2 & ~b3 & ~b1 & ~b0) nextstate=s6;

s7: if (~b2 & ~b1 & ~b0 & ~b3) nextstate = s8;
    else if (b1 & ~b0 & ~b1 & ~b2 & ~b3) nextstate=s7;

s8: if (b0 + b1 + b2 + b3) nextstate = s0; //ie after unlocking, if press any button, return back to reset. 

endcase  

//output logic
assign unlock = (state==s7);

endmodule
\$\endgroup\$
  • \$\begingroup\$ PS. In the first case, S0, in the else if, the next state =S0, not S1. Apologies. I fixed that in my code, but it still is not synthesizing, \$\endgroup\$ – Michel Apr 3 at 22:07
  • \$\begingroup\$ Please add your code to the question rather than provide a screenshot. How do you know that "synthesis is failing"? If you are not getting syntax errors, are you getting any other errors or messages? Have you written a testbench and verified that your design works in simulation? \$\endgroup\$ – Elliot Alderson Apr 3 at 22:09
  • \$\begingroup\$ Hi. I have run my testbench, and the error I am receiving is: value '3'b000' for enum 's8' already used by enum 's0' \$\endgroup\$ – Michel Apr 3 at 22:18
0
\$\begingroup\$

Your logic enum has 3 bits but there are 9 values in the enumeration. You need to provide more bits for logic or reduce the number of values in the enumeration.

\$\endgroup\$
  • \$\begingroup\$ Thank you. I changed the number of bits and it successfully synthesized. However, when I try to generate the bitstream, I just get an error saying that it can not generate it. Would this again have something to do with my code? \$\endgroup\$ – Michel Apr 3 at 22:41
  • \$\begingroup\$ If it helps, the log is just showing me some peak and gain values. \$\endgroup\$ – Michel Apr 3 at 22:44
  • \$\begingroup\$ As always, you need to provide the exact text of any error messages. \$\endgroup\$ – Elliot Alderson Apr 3 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.