集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1531|回复: 2

verilog新手求助

[复制链接]
inter 发表于 2010-6-27 23:52:18 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-7-12 13:59 编辑

开始学verilog,编写了一段直流电机控速的程序,编译时没错,但程序达不到要求,请各位高手帮忙看下到底是什么问题。
我想实现的功能是(speed_now<th_speed)是强加速,((th_speed<=speed_now)&(speed_now<=target_speed))使弱加速,speed_now==target_speed是定速,target_speed<=speed_now是减速
module zjm(reset,clk,speed_now,th_speed,target_speed,pwme,phase,flag);
input reset,clk;
input [7:0] speed_now,th_speed,target_speed;
output pwme;
output phase,flag;
reg pwme,phase,flag;
//reg [7:0] speed_now,th_speed,target_speed;
reg [2:0] clk_125,clk_375,clk_500;
always@(posedge clk or posedge reset)
begin
// clk<=~clk
if(reset==1)
begin
  pwme<=1;
  clk_125<=1;clk_375<=3;clk_500<=4;phase<=1;
end
else
if(phase==1)
begin
// case(speed_now)
  if(speed_now<th_speed)
  begin
  clk_125<=1;clk_375<=3;clk_500<=4;
  pwme<=1;
  end
  else
begin
  if((th_speed<=speed_now)&(speed_now<=target_speed))
   begin
  clk_125<=1;clk_375<=clk_375-1;clk_500<=4;
  pwme<=1;
   end
  else
  begin
   if(speed_now==target_speed)
    begin
    clk_500<=clk_500-1;clk_375<=3;clk_125<=1;
    pwme<=1;flag<=1;
    end
   else
    begin
   if(target_speed<=speed_now)
    begin
     clk_500<=4;clk_375<=clk_375-1;clk_125<=1;
      pwme<=0;
   end
    end
   end
   end
// end case;
  if((clk_500==0) | (clk_375==0))
  begin
   clk_500<=4;clk_375<=3;phase<=0;
  end
  end
else
  if(phase==0)
begin
//case(speed_now)
  if(speed_now<=th_speed)
begin
clk_500<=4;clk_375<=3;clk_125<=1;
pwme<=1;
end
  else
begin
if((th_speed<=speed_now)&(speed_now<=target_speed))
begin
clk_500<=4;clk_375<=3;clk_125<=clk_125-1;
pwme<=0;
end
  else
  begin
if(speed_now==target_speed)
begin
clk_500<=clk_500-1;clk_375<=3;clk_125<=1;
pwme<=0;
end
  else
  begin
if(target_speed<=speed_now)
begin
clk_500<=4;clk_375<=3;clk_125<=clk_125-1;
pwme<=1;
end
  end
   end
  end
  //end case;
if((clk_125==0)|(clk_500==0))
  begin
  clk_125<=1;clk_500<=4;phase<=1;
  end
end
end
endmodule
ups 发表于 2010-6-28 00:51:26 | 显示全部楼层
我的主要问题就是clk_125,和clk_500这两个技术器没有反应
weibode01 发表于 2010-11-5 14:21:43 | 显示全部楼层
把这几个模块分别编译仿真试一下??
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

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

GMT+8, 2024-12-26 14:01 , Processed in 0.059905 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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