背景说明
该模块接收CXP的bootstrapreg的信号,设置相机对外输出的定时器的功能。
模块功能
当Counter and Timer Control设置时,输出对应设置的定时器触发信号。
TimerTriggerSource[TimerSelector] :仅支持该模式:ExposureStart
TimerTriggerActivation[TimerSelector]:仅支持该模式:FallingEdge
接口设计
TimerSelector:1,2,3,4
TimerDuration:Ifloat
TimerDelay:Ifloat
TimerReset:ICommand
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2024/8/3 11:29:12
// Design Name:
// Module Name: timer_gen_fp
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// if TimerDelay> 0 ,(TimerDelay + TimerDuration) should be less than then the period of Exposuretime
// else (TimerDelay + TimerDuration + period of Exposuretime) should be less than then the period of Exposuretime
//////////////////////////////////////////////////////////////////////////////////
module timer_gen_fp#(
parameter TIMER_MUL = 32'h42FA_0000, //125.0 时钟频率与us的倍数关系
parameter VALID_DELAY = 14,
parameter TIMER_NUM = 5 //最多支持8个定时器
)//
(input clk_in,// clock of timer,暂定为125M
input rst_n,//async reset signal , active low
//info from cxp
input set_valid , //为高的时候有效
input [31:0] TimerSelector, //当前参数设置的是哪个定时器的,32‘d0:timer0, 32'd1: timer1, 32'd2: timer2,32'd3: timer3,....
input [31:0] TimerDuration, // 定时器的脉冲宽度,浮点类型,单位us
input [31:0] TimerDelay, // 定时器相对于ExposureStart下降沿时间的延迟,浮点类型,单位us
input [31:0] TimerReset,//复位某个定时器,只有BIT0有效
input ExposureStart,
// timer_out
output [TIMER_NUM-1:0] timer_out
);
时序说明
代码
testbench
下面是 timer_gen_fp
模块的testbench代码示例:
module tb_timer_gen_fp;
// Parameter definitions
parameter TIMER_MUL = 32'h42FA_0000; // 125.0 Clock frequency to us multiplication factor
parameter VALID_DELAY = 14;
parameter TIMER_NUM = 5; // Support up to 8 timers
// Signal declarations
reg clk_in;
reg rst_n;
reg set_valid;
reg [31:0] TimerSelector;
reg [31:0] TimerDuration;
reg [31:0] TimerDelay;
reg [31:0] TimerReset;
reg ExposureStart;
wire [TIMER_NUM-1:0] timer_out;
// Instantiate the module under test
timer_gen_fp #(
.TIMER_MUL(TIMER_MUL),
.VALID_DELAY(VALID_DELAY),
.TIMER_NUM(TIMER_NUM)
) uut (
.clk_in(clk_in),
.rst_n(rst_n),
.set_valid(set_valid),
.TimerSelector(TimerSelector),
.TimerDuration(TimerDuration),
.TimerDelay(TimerDelay),
.TimerReset(TimerReset),
.ExposureStart(ExposureStart),
.timer_out(timer_out)
);
// Clock generation
initial begin
clk_in = 0;
forever #4 clk_in = ~clk_in; // 125MHz clock
end
// Clock generation
initial begin
ExposureStart = 1;
forever #400_0000 ExposureStart = ~ExposureStart; // 125MHz clock
end
// Stimulus process
initial begin
// Initialize all inputs
rst_n = 0;
set_valid = 0;
TimerSelector = 0;
TimerDuration = 0;
TimerDelay = 0;
TimerReset = 0;
ExposureStart = 0;
// Apply reset
#10;
rst_n = 1;
// Set timer 0
#20;
set_valid = 1;
TimerSelector = 32'd0;
TimerDuration = 32'h41200000; // Example duration, floating point representation
TimerDelay = 32'h41200000; // Example delay, floating point representation
TimerReset = 32'h00000000; // Reset timer 0
#10;
set_valid = 0;
// Wait and observe timer outputs
#1200_0000;
set_valid = 1;
TimerSelector = 32'd0;
// Reset the timers
TimerReset = 32'h00000001; // Reset timer 0 again
#10;
set_valid = 0;
TimerReset = 32'h00000000; // Deassert reset
// Set timer 1 with different values
#20;
set_valid = 1;
TimerSelector = 32'd1;
TimerDuration = 32'h42200000; // Example duration, floating point representation
TimerDelay = 32'h42200000; // Example delay, floating point representation
TimerReset = 32'h00000000; // Reset timer 1
#10;
set_valid = 0;
// Wait and observe timer outputs
#2000_0000;
// Finish the simulation
$stop;
end
endmodule
这个testbench执行了以下操作:
- 产生一个125MHz的时钟信号。
- 初始化所有输入信号。
- 应用复位信号。
- 设置第0个定时器的参数(脉冲宽度和延迟),然后取消设置有效信号。
- 触发曝光信号,并观察定时器输出。
- 重置第0个定时器。
- 设置第1个定时器的参数(不同的脉冲宽度和延迟),然后取消设置有效信号。
- 再次触发曝光信号,并观察定时器输出。
在仿真过程中,可以观察定时器输出信号 timer_out
的变化,以验证定时器模块的功能是否正确。
测试效果
2024年8月4日,测试输出完全满足设计要求。