在我最近的CPLD设计中,我实现了一个带有SPI从接口的频率计数器。 SPI主控MCU在DRDY引脚发出信号后读出计数器。我的计数器通过翻转来更新DRDY信号(DRDY< = ~DRDY),但它需要MCU侧的两个边沿引脚中断灵敏度。我想更普遍地实现它,例如典型的ADC芯片数据就绪信号行为,即:上升沿,保持x时钟然后下降沿。我认为应该很容易但是我在Verilog作为初学者加入了条件循环。
到目前为止,这是我的代码:
module ec2(INP, RST, SR, DRDY, DRDY2, DRDY3);
input INP, RST, SR;
output reg DRDY2, DRDY3;//LEDs for verification/testing purposes
output reg DRDY;
reg [23:0] Q;
event data_ready;
always @(posedge INP or negedge RST)
begin
if(!RST)
begin
Q <= 24'd0;
end
else if( (Q == 24'd1000000 && SR) || (Q == 24'd500000 && !SR))
begin
Q <= 24'd0;
->data_ready;
DRDY2 <=~DRDY2;
end
else
begin
Q <= Q + 1;
end
end
always @(data_ready)
begin
DRDY=1'b1;
//wait for 10ms?
DRDY=1'b0;
DRDY3 = DRDY2;
end
endmodule
答案 0 :(得分:0)
事件不可综合,您应该将data_ready转换为信号(reg)。在data_ready断言时触发DRDY的第二个计数器可以解决这个问题:
always @(posedge INP or negedge RST)
begin
if (RST)
begin
DRDY <= 1'b0;
drdy_count <= 4'd0;
end
else
begin
if (~DRDY && data_ready)
begin
DRDY <= 1'b1;
drdy_count <= 4'd0;
end
else if (DRDY)
begin
drdy_count <= drdy_count + 1;
if (drdy_count == 15)
DRDY <= 1'b0;
end
end
end