nesting counters

J

john

hello mike,

I tried to follow the diagram that u send me. Channel counter
increments the sample counter after 64
counts and I need the channel counter to increment sample counter
after every 32 times. The channel counter
increments the sample counter from "0000" to "0001" fine but then it
increments it after 64. I am unable to reset
the 5 th bit of the channel counter when it reaches 32. Please
adivce.!



-- Channel Counter routine Begins--
Process (Reset_out, DPR_CLK,incr)
Begin
If( Reset_out ='1') Then
channel_counter( 5 downto 0) <= (others =>'0');
elsif rising_edge(DPR_CLK) then
if(incr = '1') then
channel_counter( 5 downto 0) <= channel_counter ( 5 downto 0)+1;
End If;
End If;
End Process;

Process (DPR_CLK, channel_counter(5), Reset_out)
Begin
If( Reset_out ='1') Then
indicator_sample <= '0';
elsIf rising_edge(DPR_CLK) then
indicator_sample <= not channel_counter (5);
else
End If;
End process;
incr_sample <= indicator_sample and channel_counter(5);

-- Sample Counter Begins--
Process (Reset_out, DPR_CLK,incr_sample)
Begin
If(Reset_out ='1') Then
sample_counter <= (others =>'0');
elsif rising_edge(DPR_CLK) then
If (incr_sample = '1') Then
sample_counter <= sample_counter+1;
End If;
End If;
End Process;

Process ( DPR_CLK, Reset_out, sample_counter(5) )
Begin
If( Reset_out ='1') Then
indicator_frame <='0';

elsIf rising_edge(DPR_CLK) then
indicator_frame <= not sample_counter(5);
else
End If;
End process;
incr_frame <= indicator_frame and sample_counter(5);
 
J

jens

Formatting your code will make it much easier to read.

Check the empty else clause, is it doing anything it shouldn't be
doing?

The sensitivity lists aren't correct, all of them should only have
Reset_out and DPR_CLK.

The logic to try to increment the sample counter seems kind of
strange... if you're trying to increment it every 32 channel counts,
use a comparison in the channel counter process to enable the sample
counter.
 
J

john

jens said:
The logic to try to increment the sample counter seems kind of
strange... if you're trying to increment it every 32 channel counts,
use a comparison in the channel counter process to enable the sample
counter.

That solution will not work.
John
 
M

Mike Treseler

john said:
That solution will not work.

The good news is, the solution is really pretty simple:

procedure update_regs is -- distilled functional description
-- a counts every clock, b counts when a rolls, c counts when b rolls
begin
a:a_v := a_v + 1; -- fast count
b:if a_v(a_v'left) = '1' then -- a carry?
a_v(a_v'left) := '0'; -- clear carry
b_v := b_v + 1;
c:if b_v(b_v'left) = '1' then -- b carry?
b_v(b_v'left) := '0'; -- clear carry
c_v := c_v + 1; -- slow count, unsigned rolls over, no carry
end if c;
end if b;
end procedure update_regs;

The bad news is, the professor
will not like it this way :)

http://home.comcast.net/~mike_treseler/count_enable.vhd


-- Mike Treseler
 
J

john

Hi Mike,

Do not worry about the professors mike, you are not a student anymore
:) Thanks for the corrections. "channel counter" increments on every
"incr" signal and it increments the "Sample counter" after 32 counts
and "frame counter increments" atfter 32x 32 times.

What do you think about this
-- Frame Counter --
Process (Reset_out, DPR_CLK)
Begin
If (Reset_out ='1' )Then
Frame_cntr<=(others =>'0');
elsif rising_edge(DPR_CLK) then
If ( incr_frame = '1') Then
Frame_cntr <= Frame_cntr + 1 ;
End If;
End If;
End Process;

-- Sample Counter Begins--
Process (Reset_out, DPR_CLK,incr_sample)
Begin
If(Reset_out ='1') Then
sample_counter <= (others =>'0');
elsif rising_edge(DPR_CLK) then
If (incr_sample = '1') Then
sample_counter <= sample_counter+1;
End If;
If ( incr_frame = '1' ) Then
sample_counter (5) <= '0';
End If;
End If;
End Process;
Process ( DPR_CLK, Reset_out, sample_counter(5) )
Begin
If( Reset_out ='1') Then
indicator_frame<='0';
elsIf rising_edge(DPR_CLK) then
indicator_frame <= not sample_counter(5);
else
End If;
End process;
incr_frame <= indicator_frame and sample_counter(5);
-- Channel Counter routine Begins--
Process (Reset_out, DPR_CLK,incr)
Begin
If( Reset_out ='1') Then
channel_counter <= (others =>'0');
elsif rising_edge(DPR_CLK) then
if(incr = '1') then
channel_counter <= channel_counter +1;
End If;
If ( incr_sample ='1' ) Then
channel_counter (5) <='0';
End If;
End If;
End Process;

Process (DPR_CLK, channel_counter(5), Reset_out)
Begin
If( Reset_out ='1') Then
indicator_sample <= '0';
elsIf rising_edge(DPR_CLK) then
indicator_sample <= not channel_counter (5);
else
End If;
End process;
incr_sample <= indicator_sample and channel_counter(5);

John
 
J

john

Hi,
I simulate the code with QuatrusII. and the code that send u works
fine. But I still do need ur expert adivce on it.
Thanks
John
 
J

john

Hi,
I do not have a professor, I have a boss.
John said:
Hi,
I simulate the code with QuatrusII. and the code that send u works
fine. But I still do need ur expert adivce on it.
Thanks
John
 
M

Mike Treseler

john said:
What if the the 5 bit counter ( fast ) will run only for 16 counts
instead of counting upto 31. How can I increment the other counter?

That would make it a 4 bit counter.
Change the generic.

-- Mike Treseler
 
K

KJ

john said:
Hi,

I am sorry its not 16 , its 19 counts. Please advice!

John

Personally, I'd advise you to fire up the simulator and start working
on your design yourself before your boss realizes you need this much
help....then again, Mike did advise you to fire up the simulator as
well. Perhaps you should consider this?

KJ
 
J

john

Hello KJ,
Thank you for your reply. I did use simulator and tried many things.
But the problem is that inorder to get 19 number count we need 5 bits
to represent the number 19. Now, I can not use the carry bit option
which I used to increment the other counters by using simulator. I also
posted that code in my previous postings developed by my simulator
inspired by mike's advices. Please let me worry about my boss.
John
 
R

Ralf Hildebrandt

john wrote:

But the problem is that inorder to get 19 number count we need 5 bits
to represent the number 19. Now, I can not use the carry bit option
which I used to increment the other counters by using simulator.

If you can't use a carry-out, you can use a comparator:
if (cnt=19) then ...

Ralf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top