Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 signal cnt_s : std_logic_vector(21 downto 0); signal temp_s : std_logic_vector(7 downto 0); begin process(reset_n_i, clk_128meg_i,cnt_s) begin if(reset_n_i='0') then cnt_s <= (others=>'0'); elsif (clk_128meg_i'event and clk_128meg_i ='1') then if(enable_i='1') then cnt_s <= std_logic_vector(unsigned(cnt_s)+1);
Don't use a counter use a shift register with the first bit set as 1 and all others set as 0. If you AND each bit (bit-wise AND)...
Now if you OR all the bits in the bitwise AND value you will have only one output bit in the first case v and the second case u.Code:shift reg: 00 0000 0000 0000 0000 0001 fsk_data: ab cdef ghij klmn opqr stuv bitwise AND: 00 0000 0000 0000 0000 000v reduction OR: v shift reg: 00 0000 0000 0000 0000 0010 fsk_data: ab cdef ghij klmn opqr stuv bitwise AND: 00 0000 0000 0000 0000 00u0 reduction OR: u etc..
Code VHDL - [expand] 1 2 3 4 5 if(fsk_data_i(unsigned(cnt_s))='0') then temp_s <= std_logic_vector(fsk_u_i); else temp_s <= std_logic_vector(fsk_l_i); end if;
shift reg: 00 0000 0000 0000 0000 0001
fsk_data: ab cdef ghij klmn opqr stuv
bitwise AND: 00 0000 0000 0000 0000 000v
reduction OR: v
shift reg: 00 0000 0000 0000 0000 0010
fsk_data: ab cdef ghij klmn opqr stuv
bitwise AND: 00 0000 0000 0000 0000 00u0
reduction OR: u
etc..
Yes and this results in a big multiplexer, though due to your lack of digital design knowledge you don't see this is the case.Thank you for the information. But what I actually need is that I need to select either fsk_u or fsk_l based on the logic of cnt_s. For example, if the cnt_s value is 5, then I need to push the 5th bit of fsk_data. And based on the pushed value (either 1 or 0), I need to select fsk_l or fsk_u.
Can I write a line directly like this:
Code VHDL - [expand] 1 2 3 4 5 if(fsk_data_i(unsigned(cnt_s))='0') then temp_s <= std_logic_vector(fsk_u_i); else temp_s <= std_logic_vector(fsk_l_i); end if;
Is this a requirement of the design (i.e. The logik function shall contain a counter based selection...), or some self imposed requirement because you decided that is what is needed?@ads-ee, thanks for the info. According to my FSK block I need to design the multiplexer by using only a counter and not a shift register. The 'Logik' function should only be a counter and not anything else. I have changed the counter to std_logic_vector(4 downto 0).
What your class notes or VHDL book don't have any information on multiplexers? That is a basic design element that any decent tutorial, book, or instructor should show you. If you've never been exposed to a multiplexer then you need find a better tutorial, book, or instructor. Try looking at the following https://www.mil.ufl.edu/3701/examples/vhdl/VHDL_examples.pdf which show multiple different ways to write the code for a multiplexer. I suggest using the case method. The counter needs to select the appropriate connection. I've pretty much already told you how to do this, outside of writing the code for you (which I refuse to do).My problem is that I can't design the counter in such a manner that it points each bit (like 1st bit, 2nd bit, 3rd bit (from LSB).....). I tried writing different codes for this, but still I couldn't solve this problem since I need to write a synthesizable code. I tried "when.. else" as well as "with...select" statements. But I have an error like these constructs are valid only in 2008 (something like that, I am not sure). I don't know how it works with for loops since I have defined cnt as a signal.
Help is appreciated.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity fsk_mod is port( clk_128meg_i : in std_logic; reset_n_i : in std_logic; enable_i : in std_logic; fsk_u_i : in std_logic_vector (7 downto 0); fsk_l_i : in std_logic_vector (7 downto 0); fsk_data_i : in std_logic_vector (21 downto 0); fsk_mod_o : out std_logic_vector (7 downto 0)); end fsk_mod; architecture rtl of fsk_mod is signal cnt_s : std_logic_vector(4 downto 0) := (others=> '0'); signal temp_s : std_logic_vector(7 downto 0); signal cntdiv_s : integer :=0; begin process(reset_n_i, clk_128meg_i) begin if(reset_n_i='0') then cntdiv_s <= 0; elsif (clk_128meg_i'event and clk_128meg_i ='1') then if(enable_i='1') then cntdiv_s <=cntdiv_s+1; else cntdiv_s <= 0; end if; end if; end process; process(reset_n_i, clk_128meg_i) begin if(reset_n_i='0') then temp_s <= (others=>'0'); cnt_s <= (others=>'0'); elsif (clk_128meg_i'event and clk_128meg_i ='1') then if(enable_i='1') then cnt_s <= std_logic_vector(unsigned(cnt_s)+1); if(cntdiv_s >= 1023) then if (fsk_data_i(to_integer((unsigned(cnt_s))))='1') then temp_s <= std_logic_vector(fsk_u_i); else temp_s <= std_logic_vector(fsk_l_i); end if; else cnt_s <= (others=>'0'); end if; else temp_s <= (others=>'0'); end if; end if; end process; fsk_mod_o <= std_logic_vector(temp_s) ; end rtl;
Code VHDL - [expand] 1 2 3 4 5 if (enable_i = '1') then cntdiv_s <=cntdiv_s+1; -- count from 0 to 4294967295 when enabled else cntdiv_s <= 0; -- clear counter when disabled end if;
cntdiv_s : unsigned (9 downto 0);
Code VHDL - [expand] 1 unsigned(10 downto 0)
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 if(cntdiv_s >="1111111111" ) then if (fsk_data_i(to_integer((unsigned(cnt_s))))='1') then temp_s <= std_logic_vector(fsk_u_i); else temp_s <= std_logic_vector(fsk_l_i); end if; else cnt_s <= (others=>'0'); end if;
Code VHDL - [expand] 1 2 3 4 5 if (cnt < 1024-1) then -- 1024 would normally be a constant like MAX_CNT so I would use MAX_CNT-1 cnt <= cnt + 1; else cnt <= (others => '0'); end if;
Code VHDL - [expand] 1 2 3 if (cnt = 1023) then -- do something every 1024 counts end if;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?