source: PlatformSupport/CustomPeripherals/pcores/radio_controller_v3_00_b/hdl/verilog/radio_controller_TxTiming.v

Last change on this file was 1766, checked in by murphpo, 12 years ago
File size: 4.2 KB
Line 
1module radio_controller_TxTiming
2(
3    input   clk,
4    input   reset,
5
6    input [0:1] clk_div,
7
8    input   sw_start,
9   
10    input [0:7] dly_GainRamp,
11    input [0:7] dly_TxEn,
12    input [0:7] dly_PHYStart,
13    input [0:7] dly_PowerAmpEn,
14   
15    input [0:5] gainRamp_TxGainTarget,
16    input [0:3] gainRamp_GainStep,
17    input [0:3] gainRamp_TimeStep,
18
19    output [0:5] gainRamp_TxGainOut,
20
21    output  TxEn,
22    output  PAEn,
23    output  PHYStart
24);
25
26    reg [0:11]  timing_counter_big;
27    reg [0: 7]  timing_counter;
28   
29    //clk_div = 0 -> Select 8 LSB for fastest processing ([4:11])
30    //clk_div = 3 -> Select 8 MSB for slowest processing ([1:8])
31   
32    always @*
33    begin
34    case(clk_div)
35        2'b00: timing_counter <= timing_counter_big[3:10];
36        2'b01: timing_counter <= timing_counter_big[2:9];
37        2'b10: timing_counter <= timing_counter_big[1:8];
38        2'b11: timing_counter <= timing_counter_big[0:7];
39    endcase
40    end
41
42    //Enable the outputs when the timing counter has excedded the various control thresholds given by the dly_* inputs
43    //  A delay value of 254 will hold the corresponding output high forever
44    //  A delay value of 255 will hold the corresponding output low forever
45    assign TxEn =       (((timing_counter > dly_TxEn)       || dly_TxEn == 8'd254)      && dly_TxEn != 8'd255);
46    assign PAEn =       (((timing_counter > dly_PowerAmpEn) || dly_PowerAmpEn == 8'd254)&& dly_PowerAmpEn != 8'd255);
47    assign PHYStart =   (((timing_counter > dly_PHYStart)   || dly_PHYStart == 8'd254)  && dly_PHYStart != 8'd255);;
48
49    //Instantiate a counter that starts when the software enables Tx mode and stops at its max value
50    // The counter used for timing is sliced from this big counter
51    always @( posedge clk )
52    begin
53        if(reset | ~sw_start)
54            timing_counter_big <= 0;
55        else if(sw_start & timing_counter < 255)
56            timing_counter_big <= timing_counter_big + 1;
57    end
58
59   
60    //Tx gain ramp logic
61    // Tx gain output starts at zero
62    // Once master counte reaches dly_GainRamp, Tx gain output begins incrementing
63    // Gain increments by gainRamp_GainStep every gainRamp_TimeStep cycles until reaching gainRamp_TxGainTarget
64    // Gain remains at gainRamp_TxGainTarget until Tx is disabled and process starts over
65    wire            GainRampEn;
66    wire    [0:6]   NewTxGain;
67    reg     [0:6]   TxGainAccum;
68    reg     [0:3]   GainRamp_clockEn_counter;
69
70    wire    [0:3]   gainRamp_TimeStep_safe;
71    wire    [0:3]   gainRamp_GainStep_safe;
72
73    //If user inputs are zero, force them to 1 to avoid stalling the logic below
74    // To bypass/disable the ramp, use 254/255 for dly_GainRamp
75    assign gainRamp_TimeStep_safe = (gainRamp_TimeStep == 0) ? 4'd1 : gainRamp_TimeStep;
76    assign gainRamp_GainStep_safe = (gainRamp_GainStep == 0) ? 4'd1 : gainRamp_GainStep;
77   
78    //Start the gain ramp after the specified delay
79    // A delay of 254 bypasses the ramp and holds the output gain at the target indefinitely
80    // A delay of 255 disables the remp and holds the output gain at 0
81    assign GainRampEn = (((timing_counter > dly_GainRamp)   || dly_GainRamp == 8'd254)  && dly_GainRamp != 8'd255);
82
83    //The output gain signal is the output of an accumulator, enabled after dly_RampGain clock cycles
84    //This signal is the input to the accumulator register. TxGainAccum has one extra MSB to ease overflow detection
85    assign NewTxGain = ( (TxGainAccum + gainRamp_GainStep_safe) > gainRamp_TxGainTarget) ? gainRamp_TxGainTarget : (TxGainAccum + gainRamp_GainStep_safe);
86
87    //The hw_TxGain output, which eventually connects to the radio's parallel gain control bus,
88    //  gets the 6 LSB of the internal accumulator value
89    assign gainRamp_TxGainOut = TxGainAccum[1:6];
90
91    //Instiantiates a counter which runs once the timing counter exceeds the threshold
92    //  for starting the ramping of Tx gains; the counter increments every (TxGain_rampTimeStep+1) cycles
93    always @( posedge clk )
94    begin
95        if(reset || (~sw_start) || (~GainRampEn))
96            TxGainAccum <= 0;
97        else if( GainRampEn & (GainRamp_clockEn_counter == gainRamp_TimeStep_safe))
98            TxGainAccum <= NewTxGain;
99    end
100   
101    //Instantiate a counter used to drive the clock enable of the gain ramp counter above
102    always @( posedge clk )
103    begin
104        if(reset || (~sw_start) || (~GainRampEn) || (GainRamp_clockEn_counter == gainRamp_TimeStep_safe))
105            GainRamp_clockEn_counter <= 0;
106        else
107            GainRamp_clockEn_counter <= GainRamp_clockEn_counter + 1;
108    end
109   
110   
111endmodule
Note: See TracBrowser for help on using the repository browser.