在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2505|回复: 6

[求助] 帮小弟看看verilog程序问题

[复制链接]
发表于 2012-9-2 21:23:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

x
本帖最后由 isaac@cheng 于 2012-9-2 21:28 编辑

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,但波形出来有问题啊,不知道哪里错了,哪位麻烦给指点一下,谢谢拉

                               
登录/注册后可看大图
发表于 2012-9-3 16:03:15 | 显示全部楼层
是指DAC后的模拟波形还是DAC的数字接口时序波形哦?不理解。呵呵。
 楼主| 发表于 2012-9-4 08:51:20 | 显示全部楼层
回复 2# duan_dzj


    是通过DAC后在示波器上看到的波形
发表于 2012-9-4 09:16:05 | 显示全部楼层
if (!rst) begin
    x <= ?
    ...
end
发表于 2012-9-4 16:17:43 | 显示全部楼层
程序太长,不好看,你仿一下就能看到数字部分是否正确了。
你的波形哪里有问题?我觉得这个系统中八成是你的DAC控制部分有错。
DAC控制状态机里面多少有些不合规矩的写法,一般而言,状态机推荐用三段式描述,你的状态机中有如下语句: dac_data<=y_buf[15];但其他状态又没有描述dac_data,这样就算功能正确,也会让人非常模糊。
建议仿一下,看看送到DAC端口上的时序是不是你想要的。
 楼主| 发表于 2012-9-8 16:52:53 | 显示全部楼层
回复 5# surge


    对啊,就是DAC控制部分由有错误,可实在看不出来,郁闷
发表于 2012-9-10 11:34:29 | 显示全部楼层
也没啥郁闷的,新人必经的过程,首先把状态机改一下把,变成标准的三段式,至少不要把数据赋值和状态跳转写在一起,写在一起也没关系,至少每一步都有清晰的数据赋值定义。你的这种写法,本身就是歧义很多。
之后先仿真,然后用逻辑分析仪抓一下ADC端口输入的数据,对着手册看看接口是不是送对了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-9-28 17:28 , Processed in 0.037803 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表