EmbDev.net

Forum: FPGA, VHDL & Verilog Problems with getting into state.


von State problems (Guest)


Rate this post
0 useful
not useful
I have a problem with timing in my program.

I have this codepiece
1
process(CLK)
2
variable prescaler: integer range 0 to 50000000;
3
Variable control: std_logic_vector(1 downto 0 ):= "00";
4
variable pointer: integer range 0 to 11:=0;
5
variable test: std_logic:='0';
6
variable error: std_logic:='0';
7
begin
8
if rising_edge (clk) then 
9
  if control = "00" and error = '0' then 
10
    winLEd <= "00";
11
      if(prescaler < 49999999/1) then   
12
        prescaler := prescaler + 1;    
13
      else
14
        prescaler := 0;
15
        top_pointer := top_pointer + 1;  -- Top pointer increment
16
        control := "11";  --- trigger event to get to new state
17
      end if;
18
  end if;    
19
  if control = "11"  and error = '0' then 
20
    winLEd <= "11";
21
    Led <= LISTEN(pointer-1);  
22
      if pointer > (top_pointer) then   -- If pointer is higher than toppointer, it means the sequence has to be incrementet. 
23
                
24
        LED <= "000000";
25
        control := "00";
26
        pointer := 0;
27
        test := '0';
28
        error:= '0';
29
      end if;
30
              
31
      if switch = LISTEN(pointer-1) and pointer<= top_pointer then -- Checks if the switch match the sequence. 
32
                  
33
        pointer:= pointer +1;
34
      end if;
35
                
36
      if switch /= LISTEN(pointer-1) and switch /= "0000" then  -- if it doesn not match, error will be set high => trigger an new state. 
37
        LED(4) <= '1';   
38
        error:= '1';    
39
      end if;      
40
      if switch = "0000" then
41
        LED(4) <= '0';
42
        error:= '0';
43
        control := "11";
44
      end if;                  
45
  end if; 
46
   if error = '1'  and control = "10" then  -- stays here infinetly until board is reset. 
47
    Led(4) <= '1';
48
    winLED <=  "10";
49
  end if; 
50
end if;              
51
end process;

I've commented the code to explain how it works.
LIsten is a array which contains different sequences.  The idea is that 
the user have to activate the switch so they match the sequence from the 
array.
My problems is that when i activate the switch for the first sequence, I 
automatically end in the error state,

I think it is because the clock. it is 50 mhz, and therefore the next 
sequence check appear while the switch is down from the first check.

Is there a way i can resolve this problem.
i tried adding a delay but that doesn't help so i am quite lost here..

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.