基于Verilog的FPGA步进电机控制.docx
-
资源ID:3385017
资源大小:36.97KB
全文页数:3页
- 资源格式: DOCX
下载积分:6.99金币
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
基于Verilog的FPGA步进电机控制.docx
基于Verilog的FPGA步进电机控制基于FPGA步进电机控制: 电机为四相步进电机,单四拍工作. Speed为电机运行状态输入; Direct 为电机转动方向输入; Out 为电机控制信号输出; 程序控制电机加速减速,采用计数原理,不同计数值控制电机旋转速度,再利用一个另外计数值控制特定速度运行时间,时间到则转到下一速度,设定有最大速度值,加速到最大速度自动进入匀速过程. module motor1(speed,rst,out,direct,clk, ); /运行状态输入 input 1:0 speed; /加速 parameter ups=2'b01; /减速 parameter dns=2'b10; /停止 parameter stop=2'b11; /最大速度 parameter aver=4'b1000; /电机运行方向,复位,时钟输入 input direct,rst,clk; /控制电机信号输出 output 3:0 out; reg 3:0 out; /加速速度转换计数 reg 3:0count1; /减速速度转换计数 reg 3:0count2; /加速速度数字代表 reg 3:0countup; /减速速度数字代表 reg 3:0countdn; /特定速度运行时间计数 reg 6:0count; /特定速度运行时间到标志 parameter countmax=7'b1111111; always(posedge clk or negedge rst) if(!rst) begin countup<=4'b1111; count1<=4'b1111; count2<=4'b1000; countdn<=4'b1000; count<=7'b0; end else if(speed=ups)|(speed=dns) begin count<=count+1; if(speed=ups) begin if(count1=0)count1<=countup; if(count1!=0) count1<=count1-1; if(countup>=4'b1001)&&(count=countmax) begin countup<=countup-1; count1<=countup-1; count=7'b0; end if(countup=aver)&&(count=countmax) begin count1<=aver; countdn<=aver; count<=7'b0; end end else if(speed=dns) begin count1=4'b1111; if(count2=0) count2<=countdn; if(count2!=0) count2<=count2-1; if(countdn<=4'b1110)&&(count=countmax) begin countdn<=countdn+1; count2<=countdn+1; count<=7'b0; end if(countdn=4'b1111)&&(count=countmax) begin count2<=4'b1111; count<=7'b0; end end end else if(speed=stop) begin countup<=4'b1111; countdn<=aver; count1<=4'b1111; count<=7'b0; end always(count1 or count2 or rst) if(!rst) out<=4'b1001; else if(count1=0)|(count2=0) begin if(speed=stop) out<=out; else if(speed=ups)|(speed=dns) begin if(direct=1) out<=out2:0,out3; else if(direct=0) out<=out0,out3:1; end end endmodule