R
Rob Gaddi
Guest
On Sat, 18 Oct 2014 15:53:31 +0800
Bruce Varley wrote:
Your problem is a hair underdefined here. Is it imperative that
calcreg be reset to zero at the exact time of DR, or is it good enough
that the DR ensure that calcreg go to zero on the next sclk edge?
"Bad practice" is a bit of a blanket statement, but in this instance
yes. The two clock domains are causing you unnecessary grief and
probably can't be justified. mnentwig already provided example code
for how to do it synchronously; the /1024 counter becomes a "count up"
enable input, and DE becomes a synchronous reset.
In an FPGA, any time you find yourself with multiple clock domains you
should always ask "What is the technical reason that _requires_ it be
this way?" Sometimes that question will have a good answer, but when
it doesn't keep it all on the same clock.
Various forms of asynchronous horribleness. Gabor gave you one, Jan's
use of the async clear is another, and I'll present you a third by
saying to Google "flancter" (a clever little arrangement with two
cross-coupled flops and an XOR gate).
All these will work. All of them will require you to get creative
with your design's timing constraints if you want the tools to really
analyze the path and make _sure_ that it works over
process/temp/voltage variations. Timing analysis and async logic go
hand in hand, and both have the exciting feature that, unlike
synchronous logic, you'll never have a simulation that can tell you
that you've got it right. You just design it very hard, then sit there
digging through the report outputs of your timing analysis to make sure
that it actually got constrained, and that the constraint actually does
what you want, and then you hope that on subsequent recompiles key
signals don't get renamed and break it. Then you too can know the joy
of wasting an hour or two trying to get the tools to work properly on a
chunk of code that's only 20 lines long.
Or you can do it synchronously.
--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
Bruce Varley wrote:
I have two clocks, clk which is the FPGA clock rate, and sclk which I
create using a simple divide by n counter. Typically, sclk is 1024
times slower than clk.
An event occurs that sets a reg, DR, for one clk cycle.
There is a register, calcreg [7:0] which is to be incremented slowly,
but reset to zero on DR.
Your problem is a hair underdefined here. Is it imperative that
calcreg be reset to zero at the exact time of DR, or is it good enough
that the DR ensure that calcreg go to zero on the next sclk edge?
Is using the two clocks simply bad practice, ie. should everything be
done in a single always block at clk rate?
"Bad practice" is a bit of a blanket statement, but in this instance
yes. The two clock domains are causing you unnecessary grief and
probably can't be justified. mnentwig already provided example code
for how to do it synchronously; the /1024 counter becomes a "count up"
enable input, and DE becomes a synchronous reset.
In an FPGA, any time you find yourself with multiple clock domains you
should always ask "What is the technical reason that _requires_ it be
this way?" Sometimes that question will have a good answer, but when
it doesn't keep it all on the same clock.
Is there a standard way to latch the DR signal when it occurs on the
fast clock, so that it will be there on the next transition of sclk,
which must then clear the DR latch? I've tried this, and come up with
the same build error with the latch.
Various forms of asynchronous horribleness. Gabor gave you one, Jan's
use of the async clear is another, and I'll present you a third by
saying to Google "flancter" (a clever little arrangement with two
cross-coupled flops and an XOR gate).
All these will work. All of them will require you to get creative
with your design's timing constraints if you want the tools to really
analyze the path and make _sure_ that it works over
process/temp/voltage variations. Timing analysis and async logic go
hand in hand, and both have the exciting feature that, unlike
synchronous logic, you'll never have a simulation that can tell you
that you've got it right. You just design it very hard, then sit there
digging through the report outputs of your timing analysis to make sure
that it actually got constrained, and that the constraint actually does
what you want, and then you hope that on subsequent recompiles key
signals don't get renamed and break it. Then you too can know the joy
of wasting an hour or two trying to get the tools to work properly on a
chunk of code that's only 20 lines long.
Or you can do it synchronously.
--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.