P
Pleg
Guest
Hi everybody, I was trying to play with the push buttons of a proto board,
to see if I'm able to get the buttons work correctly --- I'm not ^__^;
I've already looked to some old answers, but still I can't figure out the
solution.
What I wanted to do is: I've a 7 segments display, and I want to show a
digit on it, starrting with 0. Button A increases the digit, button B
decreases it. My first attempt gave me the "bad synchronous description
error", because I wrote
count_up_down: process(debounced_button_A,debounced_button_B)
begin
if(debounced_button_A'event and debounced_button_A='0') then
case current_state_1 is
when zero => next_state_1 <= one;
...
end case;
elsif(debounced_button_B'event and debounced_button_B='0') then
case current_state_1 is
when zero => next_state_1 <= nine;
...
end case;
end if;
end process count_up_down;
Now, I understand the error, and I've already found some answers in a mex of
one year ago, suggesting to use synchronous description (using the clock),
something like
if clk'event and clk = '1' then
if debounced_button_A = '0' then
...
elsif debounced_button_B = '0' then
...
but I don't think it's the same: I want to be sensitive to edges in the
buttons state, not the clock! I mean, I've a clock at 100 MHz, if I use the
above code, when I push button A (for example) it'll stay down for a lot of
clock cycles, my display will increase the digit one million times, right?
I tried then with
flag <= debounced_button_A and debounced_button_B;
process(flag,debounced_button_A,debounced_button_B)
begin
if(flag'event and flag='0') then
if(debounced_button_A='0') then
case current_state_1 is
when zero => next_state_1 <= one;
...
end case;
elsif(debounced_button_B='0') then
case current_state_1 is
when zero => next_state_1 <= nine;
...
end case;
else null;
end if;
end if;
end process;
In my mind, now the process is sensitive to the edge of only one signal (the
"flag", which "summarize" both buttons), and then in the if clause I see
which one of the buttons was pushed. I simulated it with modelsim and it
works correctly, but once loaded on the FPGA it doesn't work! The display
never changes :-(
BTW, also the display is a little mistery: I want to initialize the display
state to 0, and so I write
signal current_state_1, next_state_1: display_state := zero;
where "type display_state is (zero, one, two, three, four, five, six, seven,
eight, nine);"
But the display starts with an invalid state... there's no number on it,
just a "-", that is what I want it to show when something's wrong. Why
doesn't it intialize correctly?
I've tried with just one button (it counts only forward), and, though it
doesn't initialize, it works (I've added a clause that says that when the
state is unknown, it has to go to five at the push of the button. So, it
starts with "-", then when I push the button it goes to 5, and then counts
correctly).
I hope somebody was patient enough to read all this and can help me
Pleg
to see if I'm able to get the buttons work correctly --- I'm not ^__^;
I've already looked to some old answers, but still I can't figure out the
solution.
What I wanted to do is: I've a 7 segments display, and I want to show a
digit on it, starrting with 0. Button A increases the digit, button B
decreases it. My first attempt gave me the "bad synchronous description
error", because I wrote
count_up_down: process(debounced_button_A,debounced_button_B)
begin
if(debounced_button_A'event and debounced_button_A='0') then
case current_state_1 is
when zero => next_state_1 <= one;
...
end case;
elsif(debounced_button_B'event and debounced_button_B='0') then
case current_state_1 is
when zero => next_state_1 <= nine;
...
end case;
end if;
end process count_up_down;
Now, I understand the error, and I've already found some answers in a mex of
one year ago, suggesting to use synchronous description (using the clock),
something like
if clk'event and clk = '1' then
if debounced_button_A = '0' then
...
elsif debounced_button_B = '0' then
...
but I don't think it's the same: I want to be sensitive to edges in the
buttons state, not the clock! I mean, I've a clock at 100 MHz, if I use the
above code, when I push button A (for example) it'll stay down for a lot of
clock cycles, my display will increase the digit one million times, right?
I tried then with
flag <= debounced_button_A and debounced_button_B;
process(flag,debounced_button_A,debounced_button_B)
begin
if(flag'event and flag='0') then
if(debounced_button_A='0') then
case current_state_1 is
when zero => next_state_1 <= one;
...
end case;
elsif(debounced_button_B='0') then
case current_state_1 is
when zero => next_state_1 <= nine;
...
end case;
else null;
end if;
end if;
end process;
In my mind, now the process is sensitive to the edge of only one signal (the
"flag", which "summarize" both buttons), and then in the if clause I see
which one of the buttons was pushed. I simulated it with modelsim and it
works correctly, but once loaded on the FPGA it doesn't work! The display
never changes :-(
BTW, also the display is a little mistery: I want to initialize the display
state to 0, and so I write
signal current_state_1, next_state_1: display_state := zero;
where "type display_state is (zero, one, two, three, four, five, six, seven,
eight, nine);"
But the display starts with an invalid state... there's no number on it,
just a "-", that is what I want it to show when something's wrong. Why
doesn't it intialize correctly?
I've tried with just one button (it counts only forward), and, though it
doesn't initialize, it works (I've added a clause that says that when the
state is unknown, it has to go to five at the push of the button. So, it
starts with "-", then when I push the button it goes to 5, and then counts
correctly).
I hope somebody was patient enough to read all this and can help me
Pleg