写了一个DDS的程序,用bdf文件是可以实现的。如下图:
但是写成verilog文件以后(DDS_BLOCK.v),编译发现文件编译后,RTL图,逻辑都是对的,但是就是不在CPLD上面布线。用到的逻辑单元也只有6个。实在是疑惑不解。
module DDS_BLOCK
(
DATABUS,
ADDR,
WRITE,
READ,
CLK,
DDS_SINE,
PD_SINE
);
inout [7:0]DATABUS;
input [7:0]ADDR;
input WRITE,READ;
input CLK;
output [7:0] DDS_SINE;
output [2:0] PD_SINE;
wire CLK_DIV_N;
wire [8:0] ADDRBUS;
parameter addr_N_H=8'h0b;
parameter addr_N_L=8'h0c;
parameter addr_M=8'h0d;
parameter addr_PHASE=8'h0e;
reg [7:0] reg_N_H,reg_N_L,reg_M,reg_PHASE;
always @ (ADDR)
begin
case(ADDR)
addr_N_H: reg_N_H=DATABUS;
addr_N_L: reg_N_L=DATABUS;
addr_M: reg_M=DATABUS;
addr_PHASE: reg_PHASE=DATABUS;
default:;
endcase
end
CLK_DIV CLK_DIV_en
tity
(
.CLK(CLK),
.N(16),
.CLK_div_N(CLK_DIV_N)
);
ADDR_COUNT ADDR_COUNT_entity
(
.CLK(CLK_DIV_N),
.M(M),
.EN(reg_PHASE[7]),
.ADDR(ADDRBUS)
);
DDS_512 DDS_512_entity
(
.ADDR_i(ADDRBUS),
.DATA_o(DDS_SINE)
);
DDS_8 DDS_8_entity
(
.ADDR_i(ADDRBUS),
.PHASE_i(reg_PHASE[1:0]),
.DATA_o(PD_SINE)
);
endmodule
后来找到原因了~是因为输入端口不能用reg变量给值。always @ (ADDR)
begin
case(ADDR)
addr_N_H: reg_N_H=DATABUS;
addr_N_L: reg_N_L=DATABUS;
addr_M: reg_M=DATABUS;
addr_PHASE: reg_PHASE=DATABUS;
default:;
endcase
end
DDS_8 DDS_8_entity
(
.ADDR_i(ADDRBUS),
.PHASE_i(reg_PHASE[1:0]),
.DATA_o(PD_SINE)
);
如标红的代码处,这里PHASE_i是输入端口,不能用寄存器变量赋值,需要用一个输出线来驱动,后来写了一个三态8位寄存器,用它的输出来给定值就可以了
module Bus8
(
EN,
READ,
WRITE,
DATABUS,
DATA_FROM_BUS
);
input EN,READ,WRITE;
inout [7:0] DATABUS;
output [7:0]DATA_FROM_BUS;
reg [7:0] Data_reg;
reg [7:0] State;
assign DATA_FROM_BUS=State;
assign DATABUS=(~EN & READ & ~WRITE)?Data_reg:8'bz;
always @(EN or READ or WRITE or DATABUS or State)
if(~EN & READ & ~WRITE)//output to Databus
Data_reg=State;
else
if(~EN & ~READ & WRITE)//Databus input to State
State=DATABUS;
endmodule
一周热门 更多>