新手入门
- 积分
- 7
- 金钱
- 7
- 注册时间
- 2019-12-20
- 在线时间
- 3 小时
|
2金钱
本帖最后由 希庆 于 2020-1-10 09:09 编辑
在红外接收实验里的红外驱动中time_cnt寄存器的没有看懂
//对红外的各个状态进行计数
always @(posedge div_clk or negedge sys_rst_n) begin
if(!sys_rst_n)
time_cnt <= 8'b0;
else if(time_cnt_clr)
time_cnt <= 8'b0;
else
time_cnt <= time_cnt + 8'b1;
end
..................................
always @(posedge div_clk or negedge sys_rst_n ) begin
if (!sys_rst_n) begin
time_cnt_clr <= 1'b0; //计数器清零信号
time_done <= 1'b0; //计时完成信号
error_en <= 1'b0; //错误信号
judge_flag <= 1'b0; //检测出的标志信号 0:同步码高电平(空闲信号) 1:重复码
data_en <= 1'b0; ////数据有效信号
data <= 8'd0;
repeat_en <= 1'b0; //重复码有效信号
data_cnt <= 6'd0; //对接收的数据进行计数
data_temp <= 32'd0; //暂存收到的控制码和控制反码
end
else begin
time_cnt_clr <= 1'b0;
time_done <= 1'b0;
error_en <= 1'b0;
repeat_en <= 1'b0;
data_en <= 1'b0;
case(cur_state)
st_idle : begin //空闲状态
time_cnt_clr <= 1'b1;
if(remote_in_d0 == 1'b0)
time_cnt_clr <= 1'b0;
end
st_start_low_9ms : begin //监测同步码低电平 //9ms/0.125ms = 72
if(pos_remote_in) begin
time_cnt_clr <= 1'b1; 问题:当time_cnt_clr <= 1'b1时 time_cnt <= 8'b0,下一行的 if(time_cnt >= 69 && time_cnt <= 75) 就不能满足了 实在想不通
if(time_cnt >= 69 && time_cnt <= 75)
time_done <= 1'b1;
else
error_en <= 1'b1;
end
end
st_start_judge : begin //判断重复码和同步码高电平(空闲信号)
if(neg_remote_in) begin
time_cnt_clr <= 1'b1;
//重复码高电平2.25ms 2.25/0.125 = 18
if(time_cnt >= 15 && time_cnt <= 20) begin
time_done <= 1'b1;
judge_flag <= 1'b1;
end
//同步码高电平4.5ms 4.5/0.125 = 36
else if(time_cnt >= 33 && time_cnt <= 38) begin
time_done <= 1'b1;
judge_flag <= 1'b0;
end
else
error_en <= 1'b1;
end
end
st_rec_data : begin //接收数据
if(pos_remote_in) begin
time_cnt_clr <= 1'b1;
if(data_cnt == 6'd32) begin
data_en <= 1'b1;
data_cnt <= 6'd0;
data_temp <= 16'd0;
if(data_temp[7:0] == ~data_temp[15:8]) //校验控制码和控制反码
data <= data_temp[7:0];
end
end
else if(neg_remote_in) begin
time_cnt_clr <= 1'b1;
data_cnt <= data_cnt + 1'b1;
//解析控制码和控制反码
if(data_cnt >= 6'd16 && data_cnt <= 6'd31) begin
if(time_cnt >= 2 && time_cnt <= 6) begin //0.565/0.125 = 4.52
data_temp <= {1'b0,data_temp[15:1]}; //逻辑“0”
end
else if(time_cnt >= 10 && time_cnt <= 15) //1.69/0.125 = 13.52
data_temp <= {1'b1,data_temp[15:1]}; //逻辑“1”
end
end
end
st_repeat_code : begin //重复码
if(pos_remote_in) begin
time_cnt_clr <= 1'b1;
repeat_en <= 1'b1;
end
end
default : ;
endcase
end
...........................
|
最佳答案
查看完整内容[请看2#楼]
两个always是并行的,begin-end里的非阻塞赋值也是并行的,在这个时钟周期里赋值给time_cnt_clr的时候,同时也判断了 time_cnt的值,第一个always也已经判断完此时time_cnt_clr!=1而执行 time_cnt
|