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.

[SOLVED] how to increment a counter for 5 cycles.

Status
Not open for further replies.

prashanthi999

Member level 1
Joined
Nov 19, 2014
Messages
39
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
287
hello every one, i have a doubt how to increment a counter for every 5 cycles not that
" for single cycle the count will be incrementing " i want to increment a counter for every 5 cycles ,
for eg: here in my code i have incremented for every single clock cycle but i want to increment a count for 5 clock cycles , so that it will stay as "5" for the first 5 clock cycles and "10" for the next five clock cycles and so on. plz guide me.





Code:
process(clk,reset)
   begin
		if(clk'event and clk='1') then
		    if(reset ='1') then
		       temp <= (others=>'0');
		       temp1<= (others=>'0');
		    else
		       temp<=temp1;
		       temp1<=temp1 + 5;
		    end if;
		  end if;
		end process;
 

try using 2 counters
1 counts on every clock
count2 increments when count1 = 5. reset count1. Etc.
 
as per ur midifications i designed it , is this it!!



Code:
entity trial is
    Port ( clk : in  STD_LOGIC;
           reset : in  STD_LOGIC;
           dataout : out  STD_LOGIC_VECTOR (31 downto 0));
end trial ;

architecture Behavioral of trial is
signal temp : std_logic_vector(31 downto 0);
signal temp1 : std_logic_vector(31 downto 0);
begin
 
dataout <= temp1;


   process(clk)
--   begin
--		if(clk'event and clk='1') then
--		    if(reset ='1') then
--		       temp <= (others=>'0');
--		        else
--		       temp<=temp + 1;
--		    end if;
--		  end if;
--		end process;


      process(clk)
--   begin
--		if(clk'event and clk='1') then
--		    if(reset ='1') then
--		       temp1 <= (others=>'0');
--		        else
--		       if (temp=5) then
                           temp1 <= temp1+5;
                      end if;
--		    end if;
--		  end if;
--		end process;

end Behavioral;
 

No, it's not, and the code is all commented out.

temp should count like this: 0,1,2,3,4, 0,1,2,3,4, 0... , so temp needs to be set back to 0 each time it reaches 4.

temp1 should count 0,1,2,3,4,5,6,.... every time temp == 4, checking for temp == 5 would end up with 6 counts each time 0,1,2,3,4,5. What is up with so many students NOT knowing this!?

Now try again using the above logic.
 

    V

    Points: 2
    Helpful Answer Positive Rating
il remove commets sir, im counting from 5,10,15,20 ,,, not 1,2,3,4, so i used temp1+5, 1st process i checked seperately its working , sir second process is just adding 5 to it, not counting !!!
in the second process i made for temp=0 , temp1<=temp+5 , since 5th cycle coming at (temp=0).


Code:
entity abha is
    Port ( clk : in  STD_LOGIC;
           reset : in  STD_LOGIC;
           dataout : out  STD_LOGIC_VECTOR (31 downto 0));
end abha;

architecture Behavioral of abha is
signal temp : std_logic_vector(31 downto 0);
signal temp1 : std_logic_vector(31 downto 0);
begin
 
dataout <= temp1;

process(clk)
   begin
		if(clk'event and clk='1') then
		    if(reset ='1') then
		     temp <= (others=>'0');
		     else
		     if(temp=4) then 
			  temp<=x"00000000"; else 
			  temp<= temp+1;
			  end if;
			  end if;
		  end if;
		end process;


process(clk)
   begin
		if(clk'event and clk='1') then
		    if(reset ='1') then
		      if(temp=0) then 
				temp1<=temp;
			  temp1<=temp+5; else 
			  temp1<= x"00000000";
			  end if;
			  end if;
		  end if;
		end process;

- - - Updated - - -

hey it worked thanx a lot
.
Code:
entity abha is
    Port ( clk : in  STD_LOGIC;
           reset : in  STD_LOGIC;
           dataout : out  STD_LOGIC_VECTOR (31 downto 0));
end abha;

architecture Behavioral of abha is
signal temp : std_logic_vector(31 downto 0);
signal temp1 : std_logic_vector(31 downto 0);
begin
 
dataout <= temp1;

process(clk)
   begin
		if(clk'event and clk='1') then
		    if(reset ='1') then
		     temp <= (others=>'0');
		     else
		     if(temp=4) then 
			  temp<=x"00000000"; else 
			  temp<= temp+1;
			  end if;
			  end if;
		  end if;
		end process;


process(clk)
   begin
		if(clk'event and clk='1') then
		    if(reset ='1') then
			      temp1<= x"00000000";
					else
		      if(temp=0) then 
				  temp1<=temp1+5;
			  end if;
			  end if;
		  end if;
		end process;

end Behavioral;
asaasda.PNG
 

hello every one , can we count in any manner , my aim is i want to count in a sequence like 2345,78910,12131415 and so on removing every 5th element(i.e 6,11,16,21,26....) can we do that??
 

Yes, next question...

























oh, wait you want the answer, since you can't figure it out.

Code:
if (cnt5 < 4) then
  count <= cnt5 +1;
else
  cnt5 <= 0;
end if;

if (cnt5 == 4) then
  count <= count +2;
else
  count <= count +1;
end if;

There that skips every 5th count value.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top