集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1029|回复: 0

帮小弟看看vrilog程序问题~~~谢谢

[复制链接]
baggiolord 发表于 2012-9-2 16:11:21 | 显示全部楼层 |阅读模式
module qpsk(clk,rst,dac_clk,dac_data,dac_cs,dac_ldac);
input rst, clk;
output dac_data,dac_cs,dac_ldac,dac_clk;
reg dac_data,dac_cs,dac_clk;
reg x;
wire        dac_ldac;
reg [8:0] count;
reg [5:0] cnt;
reg [8:0] cnt1;
reg [15:0] y;
reg [15:0] y_buf;
reg [1:0] xreg;//2bit数据组标识
reg [1:0] xx;
reg [1:0] yreg;//2bit并行数据
reg [4:0] shift_reg;

//m序列发生器
always @(posedge dac_clk or negedge rst)
  begin
    if(!rst)
         begin shift_reg<=5'b00001;end //异步复位,低电平有效
  
    else begin
            shift_reg[0]<=shift_reg[2] ^ shift_reg[4];
                 shift_reg[4:1]<=shift_reg[3:0];
                 x<=shift_reg[4];
         end
  end

always @(posedge dac_clk or negedge rst) //串并转换
begin               
          if(!rst)
            begin
              xreg<=2'b0;
              yreg<=2'b0;
            end
          else  begin       
                if (count==9'h0)
                        begin                       
                                xreg[1]<=x;
                                yreg<=xreg;                                                                       
                        end
                                 else if (count==9'h100)
                        begin
                                xreg[0]<=x;                               
                        end        end                                               
end
       
always @(posedge dac_clk or negedge rst)
begin
        if(!rst) cnt1<=9'h0;
        else       
         begin  
          if(cnt1==9'b1)
                        cnt1<=9'b0;
                 else
                        cnt1<=cnt1+1'b1;
         end  
end

always @(posedge dac_clk or negedge rst) /*选相电路*/
begin               
          if(!rst) begin count<=0; end
  
     else  begin
          
          if(cnt1==257)
         
         begin
               
                case(yreg)
                       
           2'b11:count<=0;       //0
                       
                2'b01:count<=128;     //π/2   
                       
                2'b00:count<=256;     //π
                         
                2'b10:count<=384;     //3π/2
                default:count<=0;
                endcase
        end       
                  else  begin        count<=count+1;end
end end
wire   [4:0]jug;
assign jug=(count/16);       
always @(posedge dac_clk or negedge rst) /*十六相载波发生电路*/       
begin               
          if(!rst)
        begin

         y<=16'h0;
        end
else
  begin
    case(jug)
        0:y<=16'h7FFF;    1:y<=16'h98F8;
        2:y<=16'hB0FB;           3:y<=16'hC71C;
   4:y<=16'hDA81;           5:y<=16'hEA6C;
        6:y<=16'hF640;           7:y<=16'hFD89;
   8:y<=16'hFFFE;          9:y<=16'hFD89;
        10:y<=16'hF640;          11:y<=16'hEA6C;
   12:y<=16'hDA81;         13:y<=16'hC71C;
        14:y<=16'hB0FB;        15:y<=16'h98F8;
        16:y<=16'h7FFF;   17:y<=16'h6706;
        18:y<=16'h4F03;   19:y<=16'h38E2;
        20:y<=16'h257D;   21:y<=16'h1592;
        22:y<=16'h09BE;   23:y<=16'h0275;
        24:y<=16'h0000;   25:y<=16'h0275;
        26:y<=16'h09BE;   27:y<=16'h1592;
        28:y<=16'h257D;   29:y<=16'h38E2;
        30:y<=16'h4F03;   31:y<=16'h6706;
   
        default:y<=0;
       
        endcase
  end
end

always @(posedge dac_clk or negedge rst)
        begin
                if(!rst)
                        y_buf<=16'b0;
                else       
                        begin
                                if(count/16==0)
                                        y_buf<=y;
                                else
                                y_buf<=(y_buf<<1);
                        end
        end
                       
//DAC控制
reg [2:0] next;
parameter  state1 =3'd0;
parameter  state2 =3'd1;
parameter  state3 =3'd2;
parameter  state4 =3'd3;
reg [15:0] count1;

/*产生dac_clk*/
always @(posedge clk or negedge rst)
begin
  if(!rst)
  begin
   count1<=16'd0;
   dac_clk<=1'b1;
  end
  else
  if(count1==16'd100)
  begin
   count1<=16'd0;
   dac_clk<=~dac_clk;
  end
  else count1<=count1+16'b1;
end

/*传输数据*/
reg [4:0] cnt2;
reg cnt2_en;
wire cnt2_rst;

always @(posedge dac_clk or negedge rst)
  begin
  if(!rst)
   begin
         cnt2<=5'b0;
   end
        else if(cnt2_en)
                        begin
                                if(cnt2_rst)
                                        cnt2<=5'b0;
                                else
                                        cnt2<=cnt2+1'b1;
              end
  end
assign cnt2_rst=(cnt2==16)?1'b1:1'b0;
always @(posedge dac_clk or negedge rst)
begin
  if(!rst)
  begin
   next<=state1;
   dac_cs<=1'b1;
        cnt2_en<=1'b0;
  end
  else
          begin
                  case (next)
                  state1 :
                        begin
                         dac_cs<=1'b0;
                         next<=state2;
                         cnt2_en<=1'b0;
                        end
                  state2 :
                        begin
                         cnt2_en<=1'b1;
                         dac_data<=y_buf[15];
                         next<=state3;
                        end
                  state3 :
                        begin
                        if(cnt2<17)
                        next<=state2;
                        else
                        begin
                         next<=state4;
                        end
                        end
                  state4:
                        begin
                         dac_cs<=1'b1;
                         next<=state1;
                        end
                        default:next<=state1;
                       
                  endcase
         end
  end
assign dac_ldac=1'b0;

endmodule

这是我做的QPSK调制,然后驱动DAC,DAC芯片是DAC8831,但波形出来有问题啊,不知道哪里错了,哪位麻烦给指点一下,谢谢拉

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?我要注册

x
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-26 08:01 , Processed in 0.064633 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表