欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 定時計數器的Verilog代碼 [打印本頁]

作者: zfyzfyzfy    時間: 2018-11-4 20:12
標題: 定時計數器的Verilog代碼
`timescale 1ns / 1ps
`define  ENABLE           1'b1
`define  DISABLE           1'b0
`define  HIGH              1'b1
`define  LOW               1'b0
`define  DATA_W     8
`define  EA      7
`define  TF      6
`define  ET0      0
`define  ET1      1
`define  OV      2
module timer_counter(
input wire         clk,
    input wire         reset,
input wire        count,
input   wire  [`DATA_W-1:0]     th,
input   wire  [`DATA_W-1:0]     tl,
input   wire  [`DATA_W-1:0]     tmod,
input   wire  [`DATA_W-1:0]     ie,
output  wire                    mul,
output reg            irq_timer0,
output reg            irq_timer1
   
);
reg [`DATA_W-1:0]   th0;
reg [`DATA_W-1:0]   tl0;
wire     flag;
reg     a,b;
always @(posedge clk)
begin
if(!reset)
begin
th0<=8'h0;
tl0<=8'h0;
irq_timer1<=`DISABLE;
end
else if(ie [`EA])
if(ie [`TF])
begin
if(tmod[1]==`LOW)
begin
  if((tmod [0]==`LOW)&&(ie [`ET0]==`ENABLE))
  begin
   if((16'hFFFF-{th,tl})=={th0,tl0})
   begin
    tl0<=8'h0;
    th0<=8'h0;
    irq_timer0<=`ENABLE;
//   ov       <=`ENABLE;
   end
   else  {th0,tl0}<={th0,tl0}+1;
   
  end
  else if((tmod [0]==`HIGH)&&(ie [`ET1]==`HIGH))
  begin
    if(tl0==8'hFF)
    begin
    tl0  <=8'h0;
    irq_timer1<=`ENABLE;
  //  ov          <=`ENABLE;
    end
    else  tl0<=tl0+1;   
  end
end
else if(tmod [1]==`HIGH)
begin
if((tmod [0]==`LOW)&&(ie [`ET0]==`ENABLE)&&flag)
  begin
   if((16'hFFFF-{th,tl})=={th0,tl0})
   begin
    tl0<=8'h0;
    th0<=8'h0;
    irq_timer0<=`ENABLE;
//   ov       <=`ENABLE;
   end
   else  {th0,tl0}<={th0,tl0}+1;
   
  end
  else if((tmod [0]==`HIGH)&&(ie [`ET1]==`HIGH))
  begin
    if({tl0}==8'hFF)
    begin
    irq_timer1  <=`ENABLE;
    tl0<=8'h0;
  //  ov          <=`ENABLE;
    end
    else  tl0<=tl0+1;   
  end
end
end
else begin
   irq_timer0<=`DISABLE;
   irq_timer1<=`DISABLE;
   tl0<=8'h0;
            th0<=8'h0;
   end
end
always @(*)
begin
a<=count;
b<=a;
end
//assign irq_timer0=c&&!d;
assign flag=a&&!b;
assign mul=tmod [0]&&ie [`ET1]&&ie [`EA]&&ie [`TF];
endmodule






歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1