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.

easy counter problem..

Status
Not open for further replies.

suddy72

Member level 2
Joined
Jun 28, 2007
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,694
anyone got code for counting from 0000 to 1111 but when it gets to 1111 , goes to 0001 instead of 0000 then counts down again, and synchrounous with the clock.

thanks
 

BOOL y; // or use int8
int8 x;

if((x=0x0F)&&(!y)){x=0x01;y=TRUE;}
else{x=0x00;y=FALSE;}
 

sorry meant to say in VHDL.

What i am doing is counting through adresses and when i get to the bottom of the address array i dont want to go back to address 0000 i want to go back to adresss 0001
 

convert the code aspect to your vhdl structure needed

same thing really
 

module counter(q,clk,rst);
output reg [3:0]q;
input clk;
input rst;
//reg p;
always @(posedge clk or negedge rst)
begin
if(!rst)
q <= 4'b0000;
else if (q == 4'b0000)
q <= 4'b0001;
else
q <= q+1;
end
endmodule
 

Please correct this code

module counter(q,clk,rst);
output reg [3:0]q;
input clk;
input rst;
//reg p;
always @(posedge clk or negedge rst)
begin
if(!rst)
q <= 4'b0000;
//else if (q == 4'b0000)
else if(q == 4'b1111)

q <= 4'b0001;
else
q <= q+1;
end
endmodule
 

module counter(q,clk,rst);
output reg [3]q;
input clk;
input rst;
//reg p;
always @(posedge clk or negedge rst)
begin
if(!rst)
q <= 4'b0000;
else if (q == 4'b1111)
q <= 4'b0001;
else
q <= q+1;
end
endmodule

Added after 35 minutes:

Hope it help !
Please don't forget to push helped me button.
Thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top