+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Junior Member level 3
    Points: 433, Level: 4

    Join Date
    Jul 2016
    Posts
    28
    Helped
    0 / 0
    Points
    433
    Level
    4

    On off register to activate each load...

    Hi friends,

    I try to write a code but i sure there is more simple way to do it..

    I have 8 components on my board that i can do them on/off switching.
    I get 8bit register(each bit for each load) and choose wht of the load will activate.
    I thought to do it with "case" statement but i will have a lots of states...

    Can anyone advise for a better way to implement it..

    •   Alt5th March 2018, 11:57

      advertising

        
       

  2. #2
    Advanced Member level 4
    Points: 7,451, Level: 20
    Achievements:
    7 years registered Created Blog entry
    dpaul's Avatar
    Join Date
    Jan 2008
    Location
    Germay
    Posts
    1,094
    Helped
    244 / 244
    Points
    7,451
    Level
    20
    Blog Entries
    1

    Re: On off register to activate each load...

    I try to write a code but i sure there is more simple way to do it..
    Show us what you have done first.

    I think a series of "if -else" would suffice.
    .....yes, I do this for fun!



    •   Alt5th March 2018, 12:43

      advertising

        
       

  3. #3
    Junior Member level 3
    Points: 433, Level: 4

    Join Date
    Jul 2016
    Posts
    28
    Helped
    0 / 0
    Points
    433
    Level
    4

    Re: On off register to activate each load...

    Thx a lot.
    See below the code..

    Code VHDL - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    Begin
    process(mclk, reset)
    begin
        if all_rst='1' then
            load_reg <= x"1ff";
        elsif rising_edge(mclk) then
            case load_reg is
                        when x"000"  => load0 <= '0'; load1 <= '0'; load2 <= '0'; load3 <= '0'; load4 <= '0'; load5 <= '0'; load6 <= '0'; load7 <= '0';
                        when x"001"  => load0 <= '1'; load1 <= '0'; load2 <= '0'; load3 <= '0'; load4 <= '0'; load5 <= '0'; load6 <= '0'; load7 <= '0';
                        when x"002"  => load0 <= '0'; load1 <= '1'; load2 <= '0'; load3 <= '0'; load4 <= '0'; load5 <= '0'; load6 <= '0'; load7 <= '0';
                        when x"003"  => load0 <= '0'; load1 <= '1'; load2 <= '1'; load3 <= '0'; load4 <= '0'; load5 <= '0'; load6 <= '0'; load7 <= '0';
                        when x"004"  => load0 <= '0'; load1 <= '0'; load2 <= '0'; load3 <= '1'; load4 <= '0'; load5 <= '0'; load6 <= '0'; load7 <= '0';
                        etc....
            End case;
            end if;
    end process;
    Last edited by ads-ee; 5th March 2018 at 15:50. Reason: Added code tags



    •   Alt5th March 2018, 15:38

      advertising

        
       

  4. #4
    Advanced Member level 4
    Points: 7,451, Level: 20
    Achievements:
    7 years registered Created Blog entry
    dpaul's Avatar
    Join Date
    Jan 2008
    Location
    Germay
    Posts
    1,094
    Helped
    244 / 244
    Points
    7,451
    Level
    20
    Blog Entries
    1

    Re: On off register to activate each load...

    Instead of having the load* as separate bits, have it as an 8 bits output port.

    Code:
    signal load0     : std_logic_vector(7 downto 0) :=(others => '0');
    signal load_reg : std_logic_vector(3 downto 0) := x"4"; 
    .
    .
    begin
        process(mclk, all_rst)
        begin
            if all_rst='1' then
                load0    <= x"ff";
           
            elsif rising_edge(mclk) then
                case load_reg is        
                        when x"0"  => load0 <= x"00";
                        when x"1"  => load0 <= "00000001";
                        when x"2"  => load0 <= "00000010";
                        when x"3"  => load0 <= "00000100";
                        when x"4"  => load0 <= "00001000";
                        etc....
                        when x"7"  => load0 <= "10000000";
                        when others => load0 <= x"ff"; -- reset value
                end case;
            end if;
        end process;
        
        load_out_o <= load0;
    Yes, it is almost similar yours, only the representation is smarter is guess.
    Even if "if...else" was used, the matching conditions needed to be mentioned explicitly.
    Last edited by dpaul; 5th March 2018 at 17:21.
    .....yes, I do this for fun!



  5. #5
    Advanced Member level 5
    Points: 36,062, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,589
    Helped
    1924 / 1924
    Points
    36,062
    Level
    46

    Re: On off register to activate each load...

    even better, why not just

    load <= load_reg?

    As thats what your code appears to imply you want to do, you turn LEDs on based on the bits from the register?
    If you need some other encoding scheme, then a case statement is probably the easiest. (but put the load output into a single bus)

    - - - Updated - - -

    even better, why not just

    load <= load_reg?

    As thats what your code appears to imply you want to do, you turn LEDs on based on the bits from the register?
    If you need some other encoding scheme, then a case statement is probably the easiest. (but put the load output into a single bus)


    1 members found this post helpful.

--[[ ]]--