我的新博客

雷达方向信号产生

声明:本部分代码非原创,作者系电子科技大学电科院李浩老师,仅加少许注释。如有不妥,请告之。

要求是给出雷达天线的船首信号bz脉冲此时表示天线方向角对准船首位置,我们需要此时产生的方位角为0,一个bp信号,用以计算此时的方位角。由于天线的方向性问题可以产生的bp信号不能满足要求,需要在其中均匀的插入脉冲信号。其中azimuth_pulse为处理后的脉冲信号,azimuth为此脉冲的方向角。

首先每个bp信号到来时计数与上个bp信号之间的时间长度,如果要插入8个脉冲则除以8,每当时间到时产生一个脉冲信号 。同时方位角加1.

先把代码贴这里 再分析

  
   1:  `timescale 1ns / 1ps
   2:   
   3:  //used to generator the azimuth by the BP and BZ signals;
   4:  module azimuth(
   5:      input sys_clk, // 100M clock
   6:      input sys_rst_n, 
   7:      input sys_en,
   8:      input bp,
   9:      input bz,
  10:      output reg [11:0] azimuth,
  11:      output reg azimuth_pulse
  12:      );
  13:   
  14:      //define the state
  15:      parameter IDLE = 2'b00;
  16:      parameter BPST = 2'b01;// first bp
  17:      parameter PROCESS = 2'b11;
  18:      parameter BPNX = 2'b10; // next bp
  19:   
  20:      // define the scan line number  2048 
  21:      parameter SCAN_NUM = 12'h800;
  22:      
  23:      //the time counter for the scan interval
  24:      //used for generating next bp signal
  25:      reg [19:0] scan_intv_cnt;
  26:   
  27:      // the current time coounter for the scan interval
  28:      // the pulse interval out of  last bp signal 
  29:      reg [19:0] curr_intv_cnt;
  30:   
  31:      //the time counter for the neighbor bp signals
  32:      reg [21:0] bp_intv_cnt;
  33:   
  34:      // the azimuth counter for the neighbor bp signals
  35:      // count the azimuth pulse between bp signals 
  36:      reg [4:0] bp_azimuth_cnt;
  37:   
  38:      // the azimuth generated only by the bp signals
  39:      // count the sum of azimuth pulse ,the low 3 bits used for betwwen bp 
  40:      reg [11:0] temp_azimuth;
  41:   
  42:      // the azimuth value when the bz signal arrival
  43:      
  44:      reg [11:0] bz_azimuth;
  45:   
  46:      // the FSM state and next state
  47:      reg [1:0] curr_st;
  48:      reg [1:0] next_st;
  49:      
  50:      // define the signals for abstract the edge of bp, bz
  51:      reg bp_ff1, bp_re;
  52:      reg bz_ff1, bz_re;
  53:      
  54:      always @ (posedge sys_clk or negedge sys_rst_n)
  55:          if (sys_rst_n == 1'b0) begin
  56:              bp_ff1 <= 1'b0;
  57:              bp_re <= 1'b0;
  58:              bz_ff1 <= 1'b0;
  59:              bz_re <= 1'b0;
  60:          end
  61:          else begin
  62:              bp_ff1 <= bp;
  63:              bp_re <= bp && ~bp_ff1;
  64:              bz_ff1 <= bz;
  65:              bz_re <= ~bz && bz_ff1;
  66:          end
  67:      // the FSM define
  68:      // define the current state
  69:      always @ (posedge sys_clk or negedge sys_rst_n)
  70:          if (sys_rst_n == 1'b0) curr_st <= IDLE;
  71:          else curr_st <= next_st;
  72:   
  73:      //define the state skip
  74:      always @ * begin
  75:          // while the system is reseted, the state is IDLE
  76:          if (sys_rst_n == 1'b0) next_st = IDLE;
  77:          // while the system is disable, the state is IDLE
  78:          else if (sys_en == 1'b0) next_st = IDLE;
  79:          else case (curr_st)
  80:              // if the first bp arrival, state skip to BPST
  81:              IDLE : 
  82:                  if (bp_re) next_st = BPST;
  83:                  else next_st = IDLE;
  84:              // if the bp signal arrival, state skip to the PROCESS
  85:              BPST : 
  86:                  if (bp_re) next_st = PROCESS;
  87:                  else next_st = BPST;
  88:              // the state skip to the BPNX in the next clock    
  89:              PROCESS : 
  90:                  next_st = BPNX;
  91:              // the state skip to the PROCESS while the bp signal arrival    
  92:              BPNX : 
  93:                  if (bp_re) next_st = PROCESS;
  94:                  else next_st = BPNX;
  95:          endcase
  96:      end
  97:      
  98:      // assign the signals in the FSM
  99:      always @ (posedge sys_clk or negedge sys_rst_n)
 100:          if (sys_rst_n == 1'b0) begin
 101:              scan_intv_cnt <= 0;
 102:              curr_intv_cnt <= 0;
 103:              bp_intv_cnt <= 0;
 104:              bp_azimuth_cnt <= 0;
 105:              temp_azimuth <= 0;
 106:              azimuth_pulse <= 0;
 107:          end
 108:          else case (next_st)
 109:              // all sigals in the IDLE state is same as the reset initial
 110:              IDLE : begin                
 111:                  scan_intv_cnt <= 0;
 112:                  curr_intv_cnt <= 0;
 113:                  bp_intv_cnt <= 0;
 114:                  bp_azimuth_cnt <= 0;
 115:                  temp_azimuth <= 0;
 116:                  azimuth_pulse <= 0;
 117:              end
 118:   
 119:              BPST : begin                
 120:                  // bp_intv_cnt is always increase in this state
 121:                  //calcaulate the inteval between the bp signal
 122:                  bp_intv_cnt <= bp_intv_cnt + 1'b1;               
 123:              end // end the BPST state
 124:    
 125:              PROCESS : begin
 126:                   // bp signal rise edge arrive
 127:                   // 
 128:                   // inteval between azimult pulse = inteval between bp sinals / pulse number between bp 
 129:                  // assign the curr_intv_cnt divided the bp_intv_cnt by 8
 130:                  curr_intv_cnt <= bp_intv_cnt[21:3]; 
 131:                 
 132:                  // clear the bp_intv_cnt
 133:                  bp_intv_cnt <= 22'h0;
 134:                  
 135:                  // clear the bp_azimuth_cnt
 136:                  bp_azimuth_cnt <= 5'h0;
 137:   
 138:                  // assign the temp_azimuth
 139:                  // if the bp_azimuth_cnt is less than 8, 
 140:                  //     temp_azimuth is added 8 compared to the last bp
 141:                  // if the bp_azimuth_cnt is larger than 8, but less than 12,
 142:                  //     temp_azimuth is added 8 compared to the last bp
 143:                  temp_azimuth[2:0] <= 3'h0;// the low 3bits used for pulse number between bp signals
 144:                  
 145:                  //bp arrive  azimuth pulse counter out of range, reset ,
 146:                  //or , bp_azimuth <=8, because bp_zaimuth= bp interval / pulse interval ,   
 147:                  // if <8 generate a pulse ,=8 just don't care      
 148:                  if (temp_azimuth >= SCAN_NUM - 1'b1) temp_azimuth[11:3] <= 9'h0; 
 149:                  else if (bp_azimuth_cnt < 5'h8) temp_azimuth[11:3] <= temp_azimuth[11:3] + 1'b1;
 150:   
 151:                  // assign the azimuth_pulse
 152:                  // if the bp_azimuth_cnt == 8, azimuth_pulse is low
 153:                  if (bp_azimuth_cnt == 5'h8) azimuth_pulse <= 1'b0;
 154:                  else azimuth_pulse <= 1'b1;
 155:              end // end the PROCESS state
 156:   
 157:              // BPNX state is similar to the BPST
 158:              // The differet is the scan_intv_cnt clear case
 159:              BPNX : begin
 160:                  if (scan_intv_cnt >= curr_intv_cnt) 
 161:                      scan_intv_cnt <= 19'h0;
 162:                  else scan_intv_cnt <= scan_intv_cnt + 1'b1;
 163:                  // azimuth pulse inteval 
 164:                  
 165:                  //bp inteval , used for next curr_intv_cnt, 
 166:                  bp_intv_cnt <= bp_intv_cnt + 1'b1;
 167:                  
 168:                  if (scan_intv_cnt >= curr_intv_cnt)
 169:                      bp_azimuth_cnt <= bp_azimuth_cnt + 1'b1; // time is up to generate a  azimuth_pulse  
 170:   
 171:                  if (scan_intv_cnt >= curr_intv_cnt && temp_azimuth >= SCAN_NUM - 1'b1)
 172:                      temp_azimuth <= 12'h0;  //azimuth_pulse   out of range and  time is up to generate a  azimuth_pulse   
 173:                  else if (scan_intv_cnt >= curr_intv_cnt)     // or ,just add 1 to temp_azimuth 
 174:                      temp_azimuth <= temp_azimuth + 1'b1;
 175:   
 176:                  if (scan_intv_cnt >= curr_intv_cnt) azimuth_pulse <= 1'b1;  //generate a pulse 
 177:                  else azimuth_pulse <= 1'b0; 
 178:              end
 179:          endcase
 180:   
 181:      // recorder the bz_azimuth
 182:      always @ (posedge sys_clk or negedge sys_rst_n)
 183:          if (sys_rst_n == 1'b0) bz_azimuth <= 12'h0;
 184:          else if (bz_re) bz_azimuth <= temp_azimuth;
 185:   
 186:      // assign output of azimuth
 187:      // azimuth is the value that temp_azimuth minus the bz_azimuth
 188:      // while temp_azimuth is less than bz_azimuth, then add 12'hE10 
 189:      always @ (posedge sys_clk or negedge sys_rst_n)
 190:          if (sys_rst_n == 1'b0) azimuth <= 12'h0;
 191:          else if (temp_azimuth < bz_azimuth)
 192:              azimuth <= 12'h800 + temp_azimuth - bz_azimuth;
 193:          else azimuth <= temp_azimuth - bz_azimuth;
 194:  endmodule    
 195:   
View Code
仿真结果如下

image

 


 
Creativity is the sudden cessation of stupidity.
--Dr. E. Land

posted @ 2013-11-20 23:14  Leon#0534  阅读(1520)  评论(0编辑  收藏  举报

我的新博客

专注天线学习,欢迎交流 yangli0534@gmail.com - 创建于 2010年

我永远是茫茫EE领域的一名小学生。