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.

Alternative for if-elsif. please Discuss your opinions .

Status
Not open for further replies.

oursriharsha

Member level 3
Joined
Apr 23, 2009
Messages
54
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Location
Mumbai, India
Activity points
1,622
hello ,
i have to read from a memory location say 10 x8 location , which i term as
Vector.

Can anyone suggest me an alternative way of reading those vector locations at some different counts.

say at every 120µs,125µs,130µs,220µs,225µs,250µs,...... at different 32 time slots.

for example in the code below ,
i have taken a vector with 8 locations and initialised them with different values.
clk is 1us /1Mhz .

is there any alternative for using that many no of if elsif loops .





As rightly said by one ouf our members here , this would seem a procedural language.


So please suggest some synthesiable alternative .

Would highly appreciate and points as well.




Code:
  -----***** VECTOR INITIALIZATION *********** -----

VECTOR(0) <= "1001000001";
Vector(1) <= "0001000001";
VECTOR(2) <= "0000000000";
Vector(3) <= "0000000000";
VECTOR(4) <= "0000000000";
Vector(5) <= "0000111110";
VECTOR(6) <= "0001111111";
Vector(7) <= "0000000001";
--------------------------------------------------

process (CLK_SEQ ,CNTR_SEQ,RST_TOP,VECTOR(0),VECTOR(1),VECTOR(2),VECTOR(3),VECTOR(4))         

begin 

     if ( RST_TOP =  '0' ) then 
        CNTR_SEQ <= "00000000000";
    
     elsif (RST_TOP ='1') then   
                           
     if ( CLK_SEQ'event and CLK_SEQ ='1') then

                --ALE_TOP<='1'; 
                RW_SEQ     <=    TEMP_VECTOR(9);
                STRB_SEQ   <=    TEMP_VECTOR(8 downto 6);
                ADDR_SEQ   <=    TEMP_VECTOR(5 downto 0);

                CNTR_SEQ<= CNTR_SEQ+1;

                if  ( CNTR_SEQ = "00001111000" )  then         -- count of 120 
                TEMP_VECTOR <= VECTOR(0);
                
                elsif (CNTR_SEQ ="00001111110") then           -- count of 126
                TEMP_VECTOR <= VECTOR(1);
                                                     
                elsif (CNTR_SEQ ="00010000010") then         
                TEMP_VECTOR <= VECTOR(2);

                elsif (CNTR_SEQ ="00010000100") then 
                TEMP_VECTOR <= VECTOR(3);
              
                elsif (CNTR_SEQ ="00011110000") then
                CNTR_SEQ <= "00000000000";
  

                end if;
       end if ;            
end if ;

if (RST_SEQ='0') then 

DATABUS<= "00000000";

elsif (CLK_SEQ'event and CLK_SEQ ='1') then 
if (RW_SEQ='0') then 

DATABUS <= DATABUS_TEMP1;

end if ;-- rw_seq looop

end if;-- reset looop .


end process;


Regards
harsha
 

oursriharsha said:
hello ,
i have to read from a memory location say 10 x8 location , which i term as
Vector.

Can anyone suggest me an alternative way of reading those vector locations at some different counts.

say at every 120µs,125µs,130µs,220µs,225µs,250µs,...... at different 32 time slots.

for example in the code below ,
i have taken a vector with 8 locations and initialised them with different values.
clk is 1us /1Mhz .

is there any alternative for using that many no of if elsif loops .





As rightly said by one ouf our members here , this would seem a procedural language.


So please suggest some synthesiable alternative .

Would highly appreciate and points as well.




Code:
  -----***** VECTOR INITIALIZATION *********** -----

VECTOR(0) <= "1001000001";
Vector(1) <= "0001000001";
VECTOR(2) <= "0000000000";
Vector(3) <= "0000000000";
VECTOR(4) <= "0000000000";
Vector(5) <= "0000111110";
VECTOR(6) <= "0001111111";
Vector(7) <= "0000000001";
--------------------------------------------------

process (CLK_SEQ ,CNTR_SEQ,RST_TOP,VECTOR(0),VECTOR(1),VECTOR(2),VECTOR(3),VECTOR(4))         

begin 

     if ( RST_TOP =  '0' ) then 
        CNTR_SEQ <= "00000000000";
    
     elsif (RST_TOP ='1') then   
                           
     if ( CLK_SEQ'event and CLK_SEQ ='1') then

                --ALE_TOP<='1'; 
                RW_SEQ     <=    TEMP_VECTOR(9);
                STRB_SEQ   <=    TEMP_VECTOR(8 downto 6);
                ADDR_SEQ   <=    TEMP_VECTOR(5 downto 0);

                CNTR_SEQ<= CNTR_SEQ+1;

                if  ( CNTR_SEQ = "00001111000" )  then         -- count of 120 
                TEMP_VECTOR <= VECTOR(0);
                
                elsif (CNTR_SEQ ="00001111110") then           -- count of 126
                TEMP_VECTOR <= VECTOR(1);
                                                     
                elsif (CNTR_SEQ ="00010000010") then         
                TEMP_VECTOR <= VECTOR(2);

                elsif (CNTR_SEQ ="00010000100") then 
                TEMP_VECTOR <= VECTOR(3);
              
                elsif (CNTR_SEQ ="00011110000") then
                CNTR_SEQ <= "00000000000";
  

                end if;
       end if ;            
end if ;

if (RST_SEQ='0') then 

DATABUS<= "00000000";

elsif (CLK_SEQ'event and CLK_SEQ ='1') then 
if (RW_SEQ='0') then 

DATABUS <= DATABUS_TEMP1;

end if ;-- rw_seq looop

end if;-- reset looop .


end process;


Regards
harsha



Hi Harsha,
If I am not wrong why dont you use two luts.One for vector declaration and other for CNTR_SEQ.
Compare CNTR_SEQ with the value and print it.However,You should use an if statement for this as well.

Added after 4 minutes:

If not "IF statement "you can go for case statement as well.
 

hi Tan,
thanks for the reply , but if you notice, the code i m trying to decode the data i have extracted from the vectors.
i totally agree with creating 2 LUT as in my earlier prob , it will just be helpful in the modularity . (correct me if i m wrong.) /code handling.

what do u say ?
 

oursriharsha said:
hi Tan,
thanks for the reply , but if you notice, the code i m trying to decode the data i have extracted from the vectors.
i totally agree with creating 2 LUT as in my earlier prob , it will just be helpful in the modularity . (correct me if i m wrong.) /code handling.

what do u say ?

Hi harsha,
I ddnt fine any decoded data there.Like According to the address or counter mentioned the data is selected right??
Yeah LUTs are used for code handling and also as FPGA contains certain number of luts in it.This luts will use those..so there will not be extra hardware utilisation.
 

You could try the following code...and let me know if this works for you..

Code:
-----***** VECTOR INITIALIZATION *********** ----- 

VECTOR(0) <= "1001000001"; 
Vector(1) <= "0001000001"; 
VECTOR(2) <= "0000000000"; 
Vector(3) <= "0000000000"; 
VECTOR(4) <= "0000000000"; 
Vector(5) <= "0000111110"; 
VECTOR(6) <= "0001111111"; 
Vector(7) <= "0000000001"; 
-------------------------------------------------- 
-- Separate Process for Clocked events and 
-- assignments based on Clock Edge
Process (CLK_SEQ, RST_TOP)
Begin
  If (RST_TOP = '0') Then
    CNTR_SEQ <= "00000000000";
  ElsIf(CLK_SEQ'Event AND CLK_SEQ = '1') Then
    RW_SEQ     <=    TEMP_VECTOR(9); 
    STRB_SEQ   <=    TEMP_VECTOR(8 downto 6); 
    ADDR_SEQ   <=    TEMP_VECTOR(5 downto 0); 
    CNTR_SEQ<= CNTR_SEQ+1; 
  End If;
End Process;

-- Combinational Process block for 
-- Assigning temporary variables
-- TEMP_VECTOR can be declared globally (SIGNAL) or 
-- inside the Process as a VARIABBLE type
Process (CNTR_SEQ)
Begin
  Case CNTR_SEQ Is
    When "00001111000" => TEMP_VECTOR <= VECTOR(0);
    When "00001111110" => TEMP_VECTOR <= VECTOR(1);
    When "00010000010" => TEMP_VECTOR <= VECTOR(2);
    When "00010000100" => TEMP_VECTOR <= VECTOR(3);
    When "00011110000" => TEMP_VECTOR <= "00000000000";
    When OTHERS => ?????;  -- Use this others clause to avoid inferring latches 
                           -- in your design.
  End Case;
End Process;

-- Either Assign ouputs here OUTPUT <= TEMP_VECTOR
-- or use registered outputs by using another Process
-- based on CLK_SEQ and assign the output on the
-- clock edge

Process (CLK_SEQ, RST_SEQ)
Begin
  If (RST_SEQ = '0') Then
    DATABUS <= "00000000";
  ElsIf (CLK_SEQ'Event AND CLK_SEQ = '1') Then
    If (RW_SEQ = '0') Then
      DATABUS <= DATABUS_TEMP1;
    End If;
  End If;
End Process;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top