1匹涮、M序列產(chǎn)生電路
M序列產(chǎn)生以移位寄存器為基礎(chǔ),每次輸出移位寄存器的最后一位,并更新數(shù)值宵距,從而形成偽隨機(jī)序列。
m_p:process(clk,reset)
begin
dataout<=shifter(7);
if (reset='0') then shifter<="00001111"; -——移位寄存器的初始值
elsif rising_edge(clk) then
shifter(7 downto 1)<=shifter(6 downto 0); ——輸出最后一位
shifter(0)<=shifter(3) xor shifter(4) xor shifter(5) xor shifter(7); ——移位更新數(shù)據(jù)
end if;
end process;
```
(2)位時(shí)鐘提取電路
為了程序的易讀性以及編程的可控性吨拗,在編程實(shí)現(xiàn)位時(shí)鐘同步提取電路的過程中主要使用狀態(tài)機(jī)來完成满哪。第一個狀態(tài)機(jī)用來檢測一段時(shí)間內(nèi)兩個上升沿之間的最小間隔,用來提取同步時(shí)鐘
```
process(clk)
begin
if clk'event and clk='1' then
case state is
when 0=> min_reg<=20000000; ——設(shè)定最小值
state<=1;
when 1=> if m='1' and m_delay1='0' then ——當(dāng)檢測到M序列的上升沿
state<=2;
count2<=0;
end if;
when 2=> count1<=count1+1; ——探測時(shí)間范圍控制
count2<=count2+1; ——兩個上升沿之間的時(shí)間間隔
if m='1' and m_delay1='0' then
state<=3;
end if;
when 3=> if count2<min_reg then
min_reg<=count2;
end if;
if count1>=30000000 then
state<=4;
count1<=0;
else
state<=1;
end if;
when 4=> min_reg2<=min_reg;
if min_reg2=min_reg then ——為了防止跳變劝篷,使用一級寄存器哨鸭,當(dāng)連
min<=min_reg2; ——兩次檢測到相同的最小值,才輸出
end if;
state<=0;
end case;
end if;
end process;
待檢測到最小時(shí)間間隔后携龟,可用時(shí)鐘計(jì)數(shù)除
2作為同步時(shí)鐘的周期兔跌,并根據(jù)
M
序列做相位同步。
process(clk)
begin
if clk'event and clk='1' then
case step is
when 0=>
period<=min+26;
step<=1;
when 1=> if m='1' and m_delay1='0' then ——檢測
M
序列的上升沿
step<=2;
end if;
when 2=> if count3<period/4 then ——產(chǎn)生高電平
reclk<='1';
count3<=count3+1;
else
if count5<127 then ——每個M序列的周期同步一次相位
step<=3;
count3<=0;
count5<=count5+1;
else
step<=1;
count5<=0;
end if;
end if;
when 3=> if count4<period/4 then ——產(chǎn)生低電平
reclk<='0';
count4<=count4+1;
else
count4<=0;
if period>=min then
re<=period-min;
else
re<=min-period;
end if;
if re>37 then ——用來防止信號的不穩(wěn)定帶來的跳變
step<=0;
else
step<=2;
end if;
end if;
when others=> step<=0;
end case;
end if;
end process;
```
因?yàn)榍凹壞M電路中低通濾波器的頻率響應(yīng)不平整峡蟋,造成相位的變化坟桅,加之FPGA在整除過程中對結(jié)果進(jìn)行了舍位操作,導(dǎo)致測周法提取的時(shí)鐘存在誤差蕊蝗,所以在要求嚴(yán)格要求相位抖動的時(shí)候還是應(yīng)該使用鎖相環(huán)法仅乓,對于一位FPGA的菜鳥來說,鎖相環(huán)的工作原理和實(shí)現(xiàn)方法值得我們?nèi)ヌ骄俊?