Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Toggling switch button to start and pause using logic '0' or '1'

Hi Altera Friends,

I have an issue with design of clock. I have written a program for a clock to count from 0 to 9 and returns to zero. I use a switch as start/stop as in std_logic and i want a logic that I can use that when i press button ones, it will toggle between 1 and 0 so that the button can perform the two tasks start and stop. I will appreciate your urgent reply.

Thanks.

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    please post the code you have already done with specific questions about what the problem is.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    PORT

    (

    clOCK : IN STD_LOGIC;

    ce : IN STD_LOGIC;

    rst : IN STD_LOGIC;

    d1: BUFFER STD_LOGIC_VECTOR (3 DOWNTO 0);

    clk_2: OUT STD_LOGIC

    );

    -- {{ALTERA_IO_END}} DO NOT REMOVE THIS LINE!

    END mod_mod;

    -- Architecture Body

    ARCHITECTURE mod_mod_architecture OF mod_mod IS

    SIGNAL M: STD_LOGIC;

    BEGIN

    PROCESS (clock,rst,M)

    BEGIN

    IF (rst = '0') THEN

    d1 <= "0000";

    ELSIF (clOCK 'EVENT AND clOCK='1') THEN

    IF (ce = '0') THEN

    d1<= "0000" ;

    ELSE

    d1<= d1 + '1';

    M<= '0';

    END IF;

    IF d1= "1001" THEN

    d1<= "0000";

    M<= '1';

    END IF;

    END IF;

    clk_2<=M;

    END PROCESS;

    end mod_mod;

    I want ce to perform the function of start and stop.I want it to be like if i press ce switch it should change the logic from 1 to 0 to purse and for the next state to start after pressing same ce switch.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Ebony,

    Not sure what you are referring to here. If you wanted a CE using a KEY, you could simply read the KEY press (remember in DE2 boards its active LOW) and feed it as an enable input in a tri-state buffer. When key isnt pressed the clock output will be driven to Z. Not sure if this is what you wanted!?

    BP
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if i press the switch button on the altera board down without removing hand, it will purse or stop. if i rmove my hand from the button, it will start counting. I want the state to change such that if i press the switch button and remove my hand it will purse or stop and if i press the switch button and remove my hand next it should start counting.

    ce i assigned to start/stop switch.

    hope you understand it?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    if i press the switch button on the altera board down without removing hand, it will purse or stop. if i rmove my hand from the button, it will start counting. I want the state to change such that if i press the switch button and remove my hand it will purse or stop and if i press the switch button and remove my hand next it should start counting.

    ce is assigned as start/stop switch button.

    hope you understand it?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If I correctly understood your needs, you can try changing your code this way:

    SIGNAL M: STD_LOGIC;
    SIGNAL run: STD_LOGIC;
    SIGNAL last_ce: STD_LOGIC;
    PROCESS (clock,rst,M)
    BEGIN
       IF (rst = '0') THEN
          d1 <= "0000";
    	  run <= '0';
    	  last_ce <= ce;
       ELSIF (clOCK 'EVENT AND clOCK='1') THEN
          IF (run='1') THEN
              d1<= d1 + '1';
    		  M <= '0';
          END IF;
          IF d1= "1001" THEN
             d1<= "0000";
    		 M <= '1';
          END IF;
    	  IF (ce='1' and last_ce='0')
    	      run <= not run;
          END IF;
       END IF;
       clk_2<=M;
    END PROCESS;

    Regards