Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

On off register to activate each load...

Status
Not open for further replies.

manush30

Member level 1
Joined
Jul 14, 2016
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
340
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..
 

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.
 

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 a moderator:

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:

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)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top