OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 351|回复: 2
打印 上一主题 下一主题

[ALTERA] cp4ce10控制ms5541输出异常

[复制链接]

64

主题

241

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1093
金钱
1093
注册时间
2015-11-29
在线时间
146 小时
跳转到指定楼层
楼主
发表于 昨天 14:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
50金钱
        always @(posedge sys_clk)
        begin
                if(rst_n == 1'b0) begin
                        //mo_pre_normal<=16'd0,
                    mo_normal<=16'd0;
                    pa1_normal<=16'd0;
                    pa2_normal<=16'd0;
                        normal_rdy <= 1'b0;
                        cnt_delay <= 32'd0;
                        //K1_en<= 1'b0;//pa2
                        //K2_en<= 1'b0;//pa1
                        K3_en<= 1'b1;//mo
                        state <= A;
                end
                else begin//run_moshi模式
                        case(state)        //laser_mode
                        A: begin
                                if ({s3, s4} == 2'b10) begin                                        // 0x02帧装订成功后,直接进入预热       
                   //K1_en<= 1'b1;//pa2
                            // K2_en<= 1'b1;//pa1               
                                        if(run_moshi==2'd0)begin//连续模式
                                          mo_normal<=mo_value;
                                          pa1_normal<=pa1_value;
                                           pa2_normal<=pa2_value;
                                          cnt_delay <= 32'd0;
                                          state <= B;
                                        end else
                                        if(run_moshi==1'd1)begin//脉冲模式
                                          cnt_delay <= 32'd0;
                                          mo_normal<=mo_value;
                                          state <= D;
                                        end
                                        else
                                        if(run_moshi==1'd2)begin//双波模式
                                          cnt_delay <= 32'd0;
                                          mo_normal<=mo_pre_value;
                                          state <= F;
                                        end
                                end
                                         
                        end
                        B: begin
                        if(laser_mode==1'b0)begin //关闭激光器
                                pa1_normal<=16'd0;
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                        end                       
                        C: begin
                        if(cnt_delay >= pa_mo_guanbi_yanshi) begin        //
                                pa2_normal<=16'd0;
                                pa1_normal<=16'd0;
                                mo_normal<=16'd0;
                                //pa1_normal<=16'd0;
            //pa2_normal<=16'd0;
                                cnt_delay <= 32'd0;                                            
                                state <= A;
                                end
                                else begin
                                        cnt_delay <= cnt_delay + 32'd1;
                                end                                                  
                        end                       
                        D: begin
                        if(cnt_delay>=mo_maikuan-32'd1)begin
                           mo_normal<=16'd0;
                          cnt_delay <= 32'd0;
                          state <= E;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end       
                        end
                        E: begin
                         if(cnt_delay>=period_num_debug-mo_maikuan-32'd2)begin
                           mo_normal<=mo_value;
                          cnt_delay <= 32'd0;
                          state <= D ;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                        end
                  F:begin
                  if(cnt_delay>=mo_pre_maikuan-32'd1)begin
                      mo_normal<=16'd0;
                           cnt_delay <= 32'd0;
                                state <= G;
                  end  else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                       
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
             end       
                  G:begin
                   if(cnt_delay>=mo_doub_yanshi)begin
                      mo_normal<=mo_value;
                           cnt_delay <= 32'd0;
                                state <= H;
                  end  else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                  end
                  H:begin               
                  if(cnt_delay>=mo_maikuan-32'd1)begin
                           mo_normal<=16'd0;
                          cnt_delay <= 32'd0;
                          state <= I;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                  end
                  I:begin
                   if(cnt_delay>=period_num_debug-mo_maikuan-mo_pre_maikuan-mo_doub_yanshi-32'd3)begin
                           mo_normal<=mo_pre_value;
                          cnt_delay <= 32'd0;
                          state <= F ;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                  end          
                        default: begin
                   //if(laser_mode==1'b0)begin //关闭激光器
                               
                                cnt_delay <= 32'd0;   
                                state <= C;
                                //end
                                       
                       
                       
                        end
                        endcase                       
                end
                       
        end
always@(posedge sys_clk)
        begin
                s1 <= laser_mo;// 检测sim_start信号的上升沿
                s2 <= s1;
               
                s3 <= laser_mode;//功率百分比开启上升沿
                s4 <= s3;
                //s5 <= debug_ld_st;
                //s6 <= s5;

        end
mo_normal,pa1_normal,pa2_normal为3个dac数据,目前run_moshi为连续模式,控制IO口laser_mode高低来控制3个dac输出,现在遇到一个问题,只有把mo_normal,pa1_normal,pa2_normal放在以恶个always的时候可以正常输出,放在不同的always,mo_normal,pa1_normal,pa2_normal这三个dac会随机出现无法关闭或者开启的情况,实际上需要控制这3个DAC的输出时序,所以只能放在不同的always里面

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

64

主题

241

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1093
金钱
1093
注册时间
2015-11-29
在线时间
146 小时
2#
 楼主| 发表于 昨天 14:39 | 只看该作者
        always @(posedge sys_clk)
        begin
                if(rst_n == 1'b0) begin
                        //mo_pre_normal<=16'd0,
         mo_normal<=16'd0;
         //pa1_normal<=16'd0;
         //pa2_normal<=16'd0;
                        normal_rdy <= 1'b0;
                        cnt_delay <= 32'd0;
                        //K1_en<= 1'b0;//pa2
                        //K2_en<= 1'b0;//pa1
                        K3_en<= 1'b1;//mo
                        state <= A;
                end
                else begin//run_moshi模式
                        case(state)        //laser_mode
                        A: begin
                                if ({s3, s4} == 2'b10) begin                                        // 0x02帧装订成功后,直接进入预热       
                   //K1_en<= 1'b1;//pa2
                            // K2_en<= 1'b1;//pa1               
                                        if(run_moshi==2'd0)begin//连续模式
                                          mo_normal<=mo_value;
                                          //pa1_normal<=pa1_value;
                 //pa2_normal<=pa2_value;
                                          cnt_delay <= 32'd0;
                                          state <= B;
                                        end else
                                        if(run_moshi==1'd1)begin//脉冲模式
                                          cnt_delay <= 32'd0;
                                          mo_normal<=mo_value;
                                          state <= D;
                                        end
                                        else
                                        if(run_moshi==1'd2)begin//双波模式
                                          cnt_delay <= 32'd0;
                                          mo_normal<=mo_pre_value;
                                          state <= F;
                                        end
                                end
                                         
                        end
                        B: begin
                        if(laser_mode==1'b0)begin //关闭激光器
                               
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                        end                       
                        C: begin
                        if(cnt_delay >= pa_mo_guanbi_yanshi) begin        //
                                //pa2_normal<=16'd0;
                                //pa1_normal<=16'd0;
                                mo_normal<=16'd0;
                                //pa1_normal<=16'd0;
            //pa2_normal<=16'd0;
                                cnt_delay <= 32'd0;                                            
                                state <= A;
                                end
                                else begin
                                        cnt_delay <= cnt_delay + 32'd1;
                                end                                                  
                        end                       
                        D: begin
                        if(cnt_delay>=mo_maikuan-32'd1)begin
                           mo_normal<=16'd0;
                          cnt_delay <= 32'd0;
                          state <= E;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end       
                        end
                        E: begin
                         if(cnt_delay>=period_num_debug-mo_maikuan-32'd2)begin
                           mo_normal<=mo_value;
                          cnt_delay <= 32'd0;
                          state <= D ;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                        end
                  F:begin
                  if(cnt_delay>=mo_pre_maikuan-32'd1)begin
                      mo_normal<=16'd0;
                           cnt_delay <= 32'd0;
                                state <= G;
                  end  else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                       
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
             end       
                  G:begin
                   if(cnt_delay>=mo_doub_yanshi)begin
                      mo_normal<=mo_value;
                           cnt_delay <= 32'd0;
                                state <= H;
                  end  else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                  end
                  H:begin               
                  if(cnt_delay>=mo_maikuan-32'd1)begin
                           mo_normal<=16'd0;
                          cnt_delay <= 32'd0;
                          state <= I;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                  end
                  I:begin
                   if(cnt_delay>=period_num_debug-mo_maikuan-mo_pre_maikuan-mo_doub_yanshi-32'd3)begin
                           mo_normal<=mo_pre_value;
                          cnt_delay <= 32'd0;
                          state <= F ;
                        end else begin
                        cnt_delay <= cnt_delay + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delay <= 32'd0;   
                                state <= C;
                                end
                  end          
                        default: begin
                   //if(laser_mode==1'b0)begin //关闭激光器
                               
                                cnt_delay <= 32'd0;   
                                state <= C;
                                //end
                                       
                       
                       
                        end
                        endcase                       
                end
                       
        end
       



        always @(posedge sys_clk)
        begin
                if(rst_n == 1'b0) begin
                        //mo_pre_normal<=16'd0,
         //mo_normal<=16'd0;
         pa1_normal<=16'd0;
        // pa2_normal<=16'd0;
                        //normal_rdy <= 1'b0;
                        cnt_delaypa1 <= 32'd0;
                        //K1_en<= 1'b0;//pa2
                        K2_en<= 1'b0;//pa1
                        //K3_en<= 1'b1;//mo
                        statePA1 <= A;
                end
                else begin//run_moshi模式
                        case(statePA1)        //laser_mode
                        A: begin
                                if ({s3, s4} == 2'b10) begin                                        // 0x02帧装订成功后,直接进入预热       
                   //K1_en<= 1'b1;//pa2
                              K2_en<= 1'b1;//pa1       
                                        pa1_normal<=16'd0;
                                   statePA1 <= B;       
                                         cnt_delaypa1 <= 32'd0;
                               
                                end                               
                        end
                        B: begin
                       
                        if(cnt_delaypa1 >= pa1_mo_yanshi) begin
                            cnt_delaypa1 <= 32'd0;
                                if(run_moshi==2'd0)begin//连续模式
                                                  pa1_normal<=pa1_value;
                                                  statePA1 <= C;
                                                end else
                                                if(run_moshi==1'd1)begin//脉冲模式
                                                  pa1_normal<=pa1_value;
                                                  statePA1 <= D;
                                                end
                                                else
                                                if(run_moshi==1'd2)begin//双波模式
                                                  pa1_normal<=pa1_pre_value;
                                                  statePA1 <= F;
                                                end                          
                              end else begin
                                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;
                                  end       
                           if(laser_mode==1'b0)begin //关闭激光器
                                  cnt_delaypa1 <= 32'd0;  
                                  pa1_normal<=16'd0;
                                  statePA1 <= C;
                                 end       
               
                        end                       
                        C: begin
                        //statePA1 <= A;
                         if(laser_mode==1'b0)begin //关闭激光器
                                  cnt_delaypa1 <= 32'd0;  
                                  pa1_normal<=16'd0;
                                  statePA1 <= A;
                                 end       
               
                               
                        end                       
                        D: begin
                        if(cnt_delaypa1>=pa1_maikuan-32'd1)begin
                           pa1_normal<=16'd0;
                          cnt_delaypa1 <= 32'd0;
                          statePA1 <= E;
                        end else begin
                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delaypa1 <= 32'd0;
                      pa1_normal<=16'd0;               
                                statePA1 <= C;
                                end       
                        end
                        E: begin
                         if(cnt_delaypa1>=period_num_debug-pa1_maikuan-32'd2)begin
                           pa1_normal<=pa1_value;
                          cnt_delaypa1 <= 32'd0;
                          statePA1 <= D ;
                        end else begin
                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delaypa1 <= 32'd0;
                 pa1_normal<=16'd0;                       
                                statePA1 <= C;
                                end
                        end
                  F:begin
                  if(cnt_delaypa1>=pa1_pre_maikuan-32'd1)begin
                      pa1_normal<=16'd0;
                           cnt_delaypa1 <= 32'd0;
                                statePA1 <= G;
                  end  else begin
                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;//period_num_debug
                        end
                       
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delaypa1 <= 32'd0;   
                                 pa1_normal<=16'd0;
                                statePA1 <= C;
                                end
             end       
                  G:begin
                   if(cnt_delaypa1>=pa1_doub_yanshi)begin
                      pa1_normal<=pa1_value;
                           cnt_delaypa1 <= 32'd0;
                                statePA1 <= H;
                  end  else begin
                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delaypa1 <= 32'd0;
                      pa1_normal<=16'd0;               
                                statePA1 <= C;
                                end
                  end
                  H:begin               
                  if(cnt_delaypa1>=pa1_maikuan-32'd1)begin
                           pa1_normal<=16'd0;
                          cnt_delaypa1 <= 32'd0;
                          statePA1 <= I;
                        end else begin
                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                                cnt_delaypa1 <= 32'd0;   
                                statePA1 <= C;
                                end
                  end
                  I:begin
                   if(cnt_delaypa1>=period_num_debug-pa1_maikuan-pa1_pre_maikuan-pa1_doub_yanshi-32'd3)begin
                           pa1_normal<=pa1_pre_value;
                          cnt_delaypa1 <= 32'd0;
                          if(laser_mode==1'b1)begin //关闭激光器
                          statePA1 <= F ;
                         end
                        else  statePA1 <= J;
                        end else begin
                        cnt_delaypa1 <= cnt_delaypa1 + 32'd1;//period_num_debug
                        end
                       
                  end
                J:begin
                if(laser_mode==1'b0)begin //关闭激光器
                                //pa2_normal<=16'd0;
                                pa1_normal<=16'd0;
                                cnt_delaypa1 <= 32'd0;   
                                statePA1 <= C;
                                end
        end                
                        default: begin
                        end
                        endcase                       
                end
                       
        end
       


        always @(posedge sys_clk)
        begin
                if(rst_n == 1'b0) begin
                        //mo_pre_normal<=16'd0,
         //mo_normal<=16'd0;
         pa2_normal<=16'd0;
        // pa2_normal<=16'd0;
                        //normal_rdy <= 1'b0;
                        cnt_delaypa2 <= 32'd0;
                        //K1_en<= 1'b0;//pa2
                        K1_en<= 1'b0;//pa1
                        //K3_en<= 1'b1;//mo
                        statePA2 <= A;
                end
                else begin//run_moshi模式
                        case(statePA2)        //laser_mode
                        A: begin
                                if ({s3, s4} == 2'b10) begin                                        // 0x02帧装订成功后,直接进入预热       
                   //K1_en<= 1'b1;//pa2
                                  pa2_normal<=16'd0;
                                  cnt_delaypa2 <= 32'd0;
                              K1_en<= 1'b1;//pa1
                             statePA2 <= B;               

                                end                               
                        end
                        B: begin
                                if(cnt_delaypa2 >= pa2_mo_yanshi) begin        //
                                if(run_moshi==2'd0)begin//连续模式
                                          pa2_normal<=pa2_value;
                                          cnt_delaypa2 <= 32'd0;
                                          statePA2 <= C;
                                        end else
                                        if(run_moshi==1'd1)begin//脉冲模式
                                          cnt_delaypa2 <= 32'd0;
                                          pa2_normal<=pa2_value;
                                          statePA2 <= D;
                                        end
                                        else
                                        if(run_moshi==1'd2)begin//双波模式
                                          cnt_delaypa2 <= 32'd0;
                                          pa2_normal<=pa2_pre_value;
                                          statePA2 <= F;
                                        end
                                end
                                else begin
                                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;
                                end               
                        if(laser_mode==1'b0)begin //关闭激光器
                                //pa2_normal<=16'd0;
                                pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end
                        end                       
                        C: begin
                        cnt_delaypa2 <= 32'd0;                                            
                                //statePA2 <= A;
                                if(laser_mode==1'b0)begin //关闭激光器
                                //pa2_normal<=16'd0;
                                pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= A;
                                end
               
                               
                        end                       
                        D: begin
                        if(cnt_delaypa2>=pa2_maikuan-32'd1)begin
                           pa2_normal<=16'd0;
                          cnt_delaypa2 <= 32'd0;
                          statePA2 <= E;
                        end else begin
                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;//period_num_debugn
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                           pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end       
                        end
                        E: begin
                         if(cnt_delaypa2>=period_num_debug-pa2_maikuan-32'd2)begin
                           pa2_normal<=pa2_value;
                          cnt_delaypa2 <= 32'd0;
                          statePA2 <= D ;
                        end else begin
                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                            pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end
                        end
                  F:begin
                  if(cnt_delaypa2>=pa2_pre_maikuan-32'd1)begin
                      pa2_normal<=16'd0;
                           cnt_delaypa2 <= 32'd0;
                                statePA2 <= G;
                  end  else begin
                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;//period_num_debug
                        end
                       
                        if(laser_mode==1'b0)begin //关闭激光器
                        pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end
             end       
                  G:begin
                   if(cnt_delaypa2>=pa2_doub_yanshi)begin
                      pa2_normal<=pa2_value;
                           cnt_delaypa2 <= 32'd0;
                                statePA2 <= H;
                  end  else begin
                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                        pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end
                  end
                  H:begin               
                  if(cnt_delaypa2>=pa2_maikuan-32'd1)begin
                           pa2_normal<=16'd0;
                          cnt_delaypa2 <= 32'd0;
                          statePA2 <= I;
                        end else begin
                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                        pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end
                  end
                  I:begin
                   if(cnt_delaypa2>=period_num_debug-pa2_maikuan-pa2_pre_maikuan-pa2_doub_yanshi-32'd3)begin
                           pa2_normal<=pa2_pre_value;
                          cnt_delaypa2 <= 32'd0;
                          statePA2 <= F ;
                        end else begin
                        cnt_delaypa2 <= cnt_delaypa2 + 32'd1;//period_num_debug
                        end
                        if(laser_mode==1'b0)begin //关闭激光器
                           pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2<= C;
                                end
                  end
              J:begin
                        if(laser_mode==1'b0)begin //关闭激光器
                           pa2_normal<=16'd0;
                                cnt_delaypa2 <= 32'd0;   
                                statePA2 <= C;
                                end
        end                       
                        default: begin
                        end
                        endcase                       
                end
                       
        end
这样3个dac就会时不时无法开启或者关闭
回复

使用道具 举报

64

主题

241

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1093
金钱
1093
注册时间
2015-11-29
在线时间
146 小时
3#
 楼主| 发表于 昨天 14:48 | 只看该作者
监测发现laser_mode为0关闭的时候,mo_normal,pa1_normal,pa2_norma有时候写入0失败。00 00 99 99 89 99,有时候aser_mode为1开启时写入数据失败 99 99 00 00 99 99
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-10-12 05:51

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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