Verilog HDL中的延迟计时器(LS7212)

今天的项目是可编程数字延迟的实现 计时器Verilog 高密度脂蛋白。延迟计时器的Verilog代码已完整显示。

延迟计时器的Verilog代码

实现的数字延迟计时器是CMOS IC LS7212,它将生成可编程延迟。延迟计时器的规格很容易找到 这里。延迟计时器基本上具有4种操作模式:单次(OS),延迟操作(DO),延迟释放(DR),双延迟(DD)。这四种模式将通过输入mode_a和mode_b选择。

Verilog中的延迟计时器

wb [7:0]输入用于根据延迟定时器的规范中的给定方程式来编程延迟。要了解其在每种模式下如何工作以及输入如何控制延迟的更多信息,请参考其数据表。以下波形是每种模式下产生延迟的方式。


Verilog中的延迟计时器


以下是可编程数字延迟计时器LS7212的Verilog代码。 

 //hzgifts.cn: FPga projects, Verilog projects, VHDL projects
 // Verilog project: 延迟计时器的Verilog代码 LS7212 
 module delay_timer_ls7212  
 (   
      在 put [7:0] wb, // weighting bits  
      在 put clk, // clock 在 put
      在 put reset, // 计时器 reset  
      在 put trigger, // trigger 在 put  
      在 put mode_a, mode_b, // mode bits A and B  
      output reg delay_out_n // delay output, active low  
 );  
 reg[7:0] PULSE_WIDTH ;  
 reg [7:0] DELAY;  
 reg [7:0] TIMER=0;  
 reg trigger_sync_1=0,trigger_sync_2=0;  
 wire trigger_rising,trigger_falling;  
 reg 计时器_start=0,out_low=0;  
 wire 计时器_clear2,timer_clear3,timer_clear;  
 reg [1:0] mode;  
 reg reset_timer1=0,reset_timer2=0,reset_timer=0;  
 wire reset_timer3,reset_det;  
 reg reset_det1=0,reset_det2=0;  
//hzgifts.cn: FPga projects, Verilog projects, VHDL projects
 always @(posedge clk)  
 begin  
           trigger_sync_1 <= trigger; // the first Flip-Flop  
           trigger_sync_2 <= trigger_sync_1;// the second Flip-Flop  
           reset_timer1 <= reset_timer;  
           reset_timer2 <= reset_timer1;  
           reset_det1 <= reset;  
           reset_det2 <= reset_det1;  
 end  
 // Identify the zero to one transitions on trigger signal  
 assign trigger_rising = trigger_sync_1 & (~trigger_sync_2);   
 assign trigger_falling = trigger_sync_2 & (~trigger_sync_1);   
 assign reset_timer3 = reset_timer1 & (~reset_timer2);  
 assign reset_det = reset_det2 & (~reset_det1);  
 // sample Mode and wb  
 always @(trigger_rising,trigger_falling,mode_a,mode_b,wb)  
 begin  
      if(trigger_falling == 1 || trigger_rising == 1) begin  
           PULSE_WIDTH = wb;  
           DELAY = (2*wb + 1)/2;  
           mode = {mode_a,mode_b};  
      end  
 end  
 // modes  
 always @(mode,reset,trigger_falling,trigger_rising,TIMER,reset,trigger,PULSE_WIDTH,DELAY,reset_det)  
 begin  
      case(mode)  
                2'b00: // 一键式  
                          begin  
                               if(reset) begin  
                                    out_low <= 0;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                               else if(trigger_rising==1) begin  
                                    out_low <= 1;  
                                    计时器_start <= 1;  
                                    reset_timer <= 1;  
                                    end  
                               else if(TIMER>=PULSE_WIDTH) begin  
                                    out_low <= 0;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                          end  
                2'b01: // 延迟操作模式  
                          begin  
                               if(reset) begin  
                                    out_low <= 0;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                               else if(reset_det==1 && trigger==1) begin  
                                    计时器_start <= 1;  
                                    reset_timer <= 0;  
                               end  
                               else if(trigger_rising==1) begin  
                                    计时器_start <= 1;  
                                    reset_timer <= 0;  
                                    end  
                               else if(trigger_falling==1 || trigger == 0) begin  
                                    out_low <= 0;  
                                    reset_timer <= 1;  
                                    计时器_start <= 0;  
                               end  
                               else if(TIMER >= DELAY) begin  
                                    out_low <= 1;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                               //else  
                               //     reset_timer <= 0;  
                          end       
                2'b10: // 延迟释放模式  
                          begin  
                               if(reset) begin  
                                    out_low <= 0;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                               else if(trigger_rising==1 || trigger == 1) begin  
                                    out_low <= 1;  
                               end  
                               else if(trigger_falling==1 ) begin  
                                    计时器_start <= 1;  
                                    reset_timer <= 0;  
                                    end  
                               else if(TIMER>=DELAY) begin  
                                    out_low <= 0;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                          end       
                2'b11: // Delayed Dual Mode  
                          begin  
                               if(reset) begin  
                                    out_low <= 0;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                               else if(reset_det==1 && trigger==1) begin  
                                    计时器_start <= 1;  
                                    reset_timer <= 0;  
                               end  
                               else if(trigger_falling==1 || trigger_rising==1 ) begin  
                                    计时器_start <= 1;  
                                    reset_timer <= 0;  
                                    end  
                               else if(TIMER>=DELAY) begin  
                                    out_low <= trigger;  
                                    计时器_start <= 0;  
                                    reset_timer <= 1;  
                               end  
                          end  
           endcase  
 end  
//hzgifts.cn: FPga projects, Verilog projects, VHDL projects
 // 计时器  
 always @(posedge clk or posedge 计时器_clear)  
 begin  
 if(timer_clear)   
      TIMER <= 0;  
 else if(timer_start)  
      TIMER <= TIMER + 1;  
 end  
 assign 计时器_clear = reset_timer3 | trigger_rising == 1 | 计时器_clear3 ;  
 assign 计时器_clear2 = (trigger_rising == 1)|(trigger_falling == 1);  
 assign 计时器_clear3 = 计时器_clear2 & (mode == 2'b11);  
 //delay output  
 always @(posedge clk)  
 begin  
      if(out_low == 1)  
           delay_out_n <= 0;  
      else  
           delay_out_n <= 1;  
 end  
 endmodule  

延迟计时器的Testbench Verilog代码:

`timescale 1ns / 1ps  
//hzgifts.cn: FPga projects, Verilog projects, VHDL projects
// Testbench 延迟计时器的Verilog代码
 module tb_ls7212;  
      // Inputs  
      reg [7:0] wb;  
      reg clk;  
      reg reset;  
      reg trigger;  
      reg mode_a;  
      reg mode_b;  
      // Outputs  
      wire delay_out_n;  
      //hzgifts.cn: FPga projects, Verilog projects, VHDL projects
      // Instantiate the Unit Under Test (UUT)  
      delay_timer_ls7212 uut (  
           .wb(wb),   
           .clk(clk),   
           .reset(reset),   
           .trigger(trigger),   
           .mode_a(mode_a),   
           .mode_b(mode_b),   
           .delay_out_n(delay_out_n)  
      );  
      在 itial begin  
           // Initialize Inputs  
           wb = 10;  
           mode_a = 0;  
           mode_b = 0;  
           reset = 0;  
           trigger = 0;  
           #500;  
           trigger = 1;  
           #15000;  
           trigger = 0;  
           #15000;  
    trigger = 1;  
           #2000;  
           trigger = 0;  
           #2000;  
           trigger = 1;       
           #2000;  
           trigger = 0;       
           #20000;  
           trigger = 1;            
           #30000;  
           trigger = 0;  
           #2000;  
           trigger = 1;  
           #2000;  
           trigger = 0;       
           #4000;  
           trigger = 1;       
           #10000;  
           reset = 1;  
           #10000;  
           reset = 0;  
           // Delay Operate  
           // Add stimulus 这里  
      end  
   在 itial begin   
   clk = 0;  
   forever #500 clk = ~clk;  
      end  
 endmodule  
//hzgifts.cn: FPga projects, Verilog projects, VHDL projects

Verilog中数字延迟计时器的仿真波形

   One-Shot Mode


Verilog中的延迟计时器

   Delayed Operate Mode

Verilog中的延迟计时器

  延迟释放模式

Verilog中的延迟计时器

   Delay Dual Mode

Verilog中的延迟计时器

可编程延迟定时器的Verilog代码是可综合的,可以在FPGA上实现。 

推荐的 Verilog projects:
2. FIFO存储器的Verilog代码
3. 用于16位单周期MIPS处理器的Verilog代码
4. Verilog HDL中的可编程数字延迟计时器
5. 用于数字电路中基本逻辑组件的Verilog代码
6. 用于32位无符号除法器的Verilog代码
7. 用于定点矩阵乘法的Verilog代码
8. Verilog HDL中的车牌许可证识别
9. 提前进位乘法器的Verilog代码
10。 微处理器的Verilog代码
11。 4x4乘法器的Verilog代码
12 停车场系统的Verilog代码
13 使用Verilog HDL在FPGA上进行图像处理
14。 如何使用Verilog HDL将文本文件加载到FPGA中
15 交通信号灯控制器的Verilog代码
16。 FPGA上的闹钟的Verilog代码
17。 比较器设计的Verilog代码
18岁 D触发器的Verilog代码
19 Full Adder的Verilog代码
20 带testbench的计数器的Verilog代码
21 16位RISC处理器的Verilog代码
22 用于在FPGA上反跳按钮的Verilog代码
23。 如何为双向/输入端口编写Verilog Testbench
28。 解码器的Verilog代码
29。 复用器的Verilog代码
FPGA Verilog VHDL课程

1条评论:

热门FPGA项目