• 0
Sign in to follow this  
donwazonesko

BASYS3 - pushbutton creating another vector out of switches

Question

Hello!

I'm new in here.

 

I've wanted to create boolean calculator with basys3 board and mine idea is:

 

- use switches to created 8 bits std_logic_vector.

- use leds to represent vector value.

- use one of the buttons to remember the bits value.

- create another vector with switches and use leds to show it once again.

- use button to create another variable to remember the bits value.

- use second button to represent the boolean result of adding both of the vectors.

 

While using switchs and leds is not a big deal - creating variables with push buttons is kinda hard task. Could you please explain to me, how to create those?

Best regards, Michael

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

@D@n I'm begginer with vhdl and trying to create simple projects. Doing it in C it's easy but with fpga something is wrong.

 

I want to check the button state - get the vectors  value and add up both of them.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;

entity calc is
    Port ( 
           switch : in STD_LOGIC_VECTOR (7 downto 0);
           button : in STD_LOGIC_VECTOR (2 downto 0); 
                   
           vec1,vec2   : inout STD_LOGIC_VECTOR (7 downto 0):= "00000000";
           sum   : inout STD_LOGIC_VECTOR (7 downto 0);
           led : out STD_LOGIC_VECTOR (7 downto 0)
           
           );         
end calc;

architecture Behavioral of calc is

begin

led <= switch;

process (button,switch,vec1,vec2,sum)
begin
if (button(1) = '1') then
    vec1 <= switch;  
elsif (button(2) = '1') then
    vec2 <= switch;
elsif (button(0) = '1') then
    sum <= vec1 + vec2;
    led <= sum;
end if; 
end process;
end Behavioral;

 

 

Share this post


Link to post
Share on other sites
  • 0

@donwazonesko,

Please tell me you've debounced those buttons first before coming into the code you just showed me ... there's more than one student whose been burned by not debouncing buttons when doing an exercise like this.

You might also want to add an edge detect to them as well.  Something like: button_press = (button & !last_button); last_button = button; or some such.

Finally, if this is your first project, then let me recommend you find a good simulator and get familiar with it.  While I don't use VHDL (much), I've been told that ghdl is a good simulator that you can use.  It'll make your project so much easier than just debugginng on your board itself, and it'll also prepare you for your next (bigger) project where you will absolutely need it.

Dan

Share this post


Link to post
Share on other sites
  • 0
set_value: process(btn)
   begin
     if rising_edge(btn1) then
       value1 <= switches;
     end if;
   end process;
                         
display: process(btn2,value1, switches) 
   begin
      if btn2 = '1' then
        leds <= std_logic_vector(unsigned(value1)+unsigned(switches));
      else
        leds <= switches;
      end if;
    end process;

I haven't coded it and tested it, but with something like the above code should be possible to make an "add two binary numbers" calculator.

It is filled with errors in form and style (e.g. using a button input as a clock), but it should be possible to get something close to what you describe working, without jumping head-first into the technicalities of synchronous design.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this