I have a data signal (data) and his clock (data_clk : 4 MHz).
I would like to sampling these signal with an sampling clock (clk_smp : 88 MHz).
But this clock (clk_smp) is not synchronous with data_clk !!
I don't want to use a PLL.
It's what is doing an USART (Universal Synchronous ...)
How to do ?
1. Sample both data and data_clk using the oversampling clk_smp.
Now both these signals are synchronised to clk_smp.
2. Use the synchronised version of data_clk to identify the
correct moment for sampling the data.
For Step 2 you need to know the timing of data relative to
data_clk, and you have not told me that. Let me *guess* that
the correct sampling moment is at the falling edge of data_clk.
Then...
signal
-- INTERNAL SIGNALS
syn_data, -- incoming data resynchronised to 88MHz
syn_data_clk, -- incoming clock resynchronised to 88MHz
syn_data_clk_d, -- syn_data_clk delayed by one 88MHz cycle
-- OUTPUTS TO OTHER LOGIC, FULLY SYNCHRONOUS WITH 88MHz CLOCK
new_bit_available, -- asserted for one cycle: bit enable
new_bit_data: -- captured, resynchronised input data
std_logic;
....
process (clk_smp)
begin
if rising_edge(clk_smp) then
-- Capture synchronised versions of input data and clock
syn_data <= data;
syn_data_clk <= data_clk;
-- Get delayed version of syn_data_clk for edge detection
syn_data_clk_d <= syn_data_clk;
-- Clock edge detection
new_bit_available <= '0'; -- default
if syn_data_clk_d = '1' and syn_data_clk = '0' then
-- It's time to take a sample!
new_bit_available <= '1';
new_bit_data <= syn_data;
end if;
end if; -- rising_edge(clk_smp)
end process;
For extra credit:
- re-code my process so that all the internal flip-flops
are VHDL variables local to the process
- use your 88MHz oversampling to create a majority-voting
glitch filter on both clock and data
- add an additional input flip-flop on both clock and data
to reduce metastability risk
- add programmable sampling point, specified as a count of
88MHz cycles, so that sampling of data can be offset
from edges of data_clk
For lots of extra credit:
- automate the choice of sampling point offset, by
examining the position of data transitions and locating
the sampling point midway between transitions
Welcome to the wonderful world of multiple clock domains.
You have it pretty easy - your sampling clock is more than
20 times faster than your data rate. Things get harder
if that number is much smaller.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services
Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
[email protected]
Fax: +44 (0)1425 471573 Web:
http://www.doulos.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.