
經過一再的錯誤嘗試,我好像終於寫出來了.
我是用Verilog,但要如何改成VHDL我就不清楚了.
我這一次不但把load與sclk拆開,
我還把計數器改成負緣觸發.
我測試過這個code可以跑過
Synthesis, Post-Fit Simulation.
我是用Xilinx ISE WebPACK 9.1i作Synthesis,
再呼叫ModelSim作Post-Fit Simulation.
這是合成後的電路與Post-Fit Simulation:
http://web.cc.ncu.edu.tw/~93501025/verilog.png
這是Verilog code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`timescale 1ns / 1ps
module test2(clk, sclkout, cntout, loadout);
input clk;
reg [3:0] cnt;
output [3:0] cntout;
assign cntout = cnt;
reg load;
output loadout;
assign loadout = load;
reg sclk;
output sclkout;
assign sclkout = sclk;
always@(negedge clk) begin
if (cnt<='b 1000)
cnt = cnt+1;
else
cnt = 'b 0;
end
always@(clk) begin
if(clk == 'b 1) begin
if (cnt<='b 0010 & cnt>'b 0) begin
load = 'b 0;
sclk = 'b 0;
end
else begin
load = 'b 1;
sclk = 'b 1;
end
end
else
sclk = 'b 0;
end
endmodule
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
※ 引述《CuckooBoy (阿書)》之銘言:
: 謝謝各位的回答!
: 我知道怎麼解決了!
: 程式如下,用兩個clk
: 一個是輸入的clk,一個是除頻的clk1
: 用clk計數,用clk1去決定開關..
: 放慢...開關的速度,避開....開關clk同步
: 不知這樣講有人聽得懂嗎?不過看下面程式應該就知道我的意思!!
: 再次感謝!!
: library IEEE;
: use IEEE.STD_LOGIC_1164.ALL;
: use IEEE.STD_LOGIC_ARITH.ALL;
: use IEEE.STD_LOGIC_UNSIGNED.ALL;
: entity MBI is
: Port
: (
: clk : in std_logic;
: sclk : out std_logic;
: rclk : out std_logic
: );
: end MBI;
: architecture Behavioral of MBI is
: signal clk1 :std_logic;
: signal cnt,cnt2 : std_logic_vector (3 downto 0);
: signal load,div_out :std_logic;
: begin
: process(clk)
: begin
: if rising_edge(clk) then
: clk1 <= not clk1;
: end if;
: end process;
: process(clk)
: begin
: if rising_edge(clk) then
: if cnt<10 then
: cnt <= cnt+1;
: else
: cnt <= "0000";
: end if;
: end if;
: end process;
: process(clk1)
: begin
: if rising_edge(clk1) then
: if cnt <3 then
: sclk <='0';
: else
: sclk <='1';
: end if;
: end if;
: end process;
: process(clk1)
: begin
: if rising_edge(clk1) then
: if cnt <5 then
: rclk <='0';
: else
: rclk <='1';
: end if;
: end if;
: end process;
: end Behavioral;
--
Albert Einstein :
If there is any religion that could cope with modern scientific needs it
would be Buddhism.
《金剛經》離一切諸相,則名諸佛。
http://web.cc.ncu.edu.tw/~93501025/jg.doc
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.200.121
