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.

Problem with clock counter in a mux design

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
Hi guys ,

I am designing a mux, i want the select line to be set to 1 on every rising edge and 0 on every falling edge, that way the mux is changing twice every clock cycle. I seem to be having problems getting this to work, any one have any simple code that will do what i require.

thanks

stuart
 

Iouri

Advanced Member level 2
Joined
Aug 17, 2005
Messages
682
Helped
87
Reputation
174
Reaction score
8
Trophy points
1,298
Activity points
4,814
Clock counter.

What is clock frequency?
 

MGT78000

Newbie level 4
Joined
Oct 29, 2007
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
Re: Clock counter.

Hello.

How about something like this

entity timer is
port(clk0, clk2x, a ,b in std_logic; sel, f out std_logic);
end timer;

architecture primary of timer is
signal bias std_logic;
begin
if (clk2x'event and clk2x='1') then
sel <= (not sel) or bias;
end if;
if (clk0'event and clk0='1' then
bias<=sel;
end if;
if (sel='0') then
f<=a;
elsif
f<=b;
end if
end primary

Added after 4 hours 10 minutes:

or, even better,

entity timer is
port(clk, a ,b: in std_logic; sel, f: out std_logic);
end timer;

architecture primary of timer is
signal Q1, Q2: std_logic;
begin
process
begin
wait until CLK'event
if clk='1' then
Q1<=not Q1
else
Q2<=Q1
end if
sel <= Q1 xor Q2;
if (sel='0') then
f<=a;
elsif
f<=b;
end if
end process
end primary
 

kanagavel_docs

Member level 1
Joined
Aug 18, 2007
Messages
41
Helped
8
Reputation
16
Reaction score
1
Trophy points
1,288
Location
Chennai
Activity points
1,520
Re: Clock counter.

Hi,

Just check this logic..

module counter(
reset,
clock,

mux0_in,
mux1_in,

mux_out)


input reset;
input clock;

input mux0_in;
input mux1_in;

output mux_out;

wire mux_en;
wire mux_out;

reg pos_flop;
reg neg_flop;

assign mux_en = pos_flop ^ neg_flop;
assign mux_out = (~mex_en) ? mux0_in : mux1_in;

//reset should be released in the low period of the clock
always @(posedge clock or negedge reset)
if(!reset)
pos_flop <= 1'b0;
else
pos_flop <= ~pos_flop;


always @(negedge clock or negedge reset)
if(!reset)
neg_flop <= 1'0;
else
neg_flop <= ~neg_flop;

endmodule
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
Clock counter.

Rising and falling edge of what? The clock?

How about using an ordinary 2-to-1 mux, with the select line connected to the clock?

What does "clock counter" mean in your subject line?
 

MGT78000

Newbie level 4
Joined
Oct 29, 2007
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
Re: Clock counter.

echo47 said:
How about using an ordinary 2-to-1 mux, with the select line connected to the clock?
Can you do that on a Spartan 3E? That would make my life a lot easier.
 

kanagavel_docs

Member level 1
Joined
Aug 18, 2007
Messages
41
Helped
8
Reputation
16
Reaction score
1
Trophy points
1,288
Location
Chennai
Activity points
1,520
Re: Clock counter.

Hi,

It is not recommended to use clock/reset in combinational logics
 

MGT78000

Newbie level 4
Joined
Oct 29, 2007
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
Re: Clock counter.

kanagavel_docs said:
It is not recommended to use clock/reset in combinational logics

What's the reason? Is the signal not strong enough?
But can you actually do it? And can you do the opposite, i.e. use a logic signal as the clock line on a latch?
 

anoop12

Member level 5
Joined
Nov 29, 2006
Messages
89
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,288
Activity points
1,867
Re: Clock counter.

Hi MGT78000
The reason is that in combinational circuits, thje clock may get GATED, so it may lead to clock skew and related problems
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
Clock counter.

Yes, you can connect a clock to a mux select input, but ISE will probably give you a warning that the clock is feeding into asynchronous logic. That's usually bad design practice in an FPGA, due to the increased difficulty in achieving reliable timing, but I don't know your design or the purpose of your mux.
 

nitin_ndg

Junior Member level 1
Joined
Sep 24, 2007
Messages
18
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,389
Clock counter.

echo47's reply posted if good 30 Oct 2007 10:59
 

cherjier

Member level 5
Joined
Dec 6, 2006
Messages
84
Helped
6
Reputation
12
Reaction score
1
Trophy points
1,288
Activity points
1,909
Re: Clock counter.

can do it in this way?

input ENABLE; <- optional
output MUX_SEL;
reg mux_sel_1, mux_sel_2;

assign MUX_SEL = (mux_sel_1 & !mux_sel_2) | (!mux_sel_1 & mux_sel_2 );

always @(posedge CLK or negedge RESET_N) begin
if (!RESET_N)
mux_sel_1 <= 1'b0;
else (ENABLE)
mux_sel_1 <= !mux_sel_1;
end

always @(negedge CLK or negedge RESET_N) begin
if (!RESET_N)
mux_sel_2 <= 1'b0;
else (ENABLE)
mux_sel_2 <= !mux_sel_2;
end

if that the case, u will have a MUX_SEL toggling at the same rate as the clock.
this will be a synchornous design by gating the register output rather than the clock.
the ENABLE signal is optional.. just for indication when to start toggling the mux select input.

i think this will have no problem in FPGA nor ASIC. if any issue please let me know as i'm a newbie as well.
 

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
Re: Clock counter.

Hi

It seams that you are doing DDR Thing.
The FPGA library should include some ready made IP which Facilitates your work.
In Vertix4 there's a lot of such facilities.
You should check your FPGA user manual or library guide to see if it supports such IP

Salam
Hossam Alzomor
www(.)i-g(.)org
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top