Problems with getting into state.

Guest #3640982
Rate this post
• ▲ 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

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.