主要思想,用状态机驱动步进西玛电机!!!
总体感觉,整个程序比较繁琐,看见别人实现相同的功能代码也才那么几十行,我的……呃 差距可想而知了。。。
current<=s5; end always@(current1 )//or clk0 current<=s0; temp=adj[5]+adj[4]+adj[3]+adj[2]+adj[1]+adj[0]; end output [3:0]out; if(!reset) end cnt <=26'b0; s2: endcase current1<=s7; begin s5: begin end current<=s5; current<=s4; cnt <=26'b0; begin end current1<=s4; end out<=4'b0110; begin output a; end end end end end else if(temp==3'd2) if(!der) end module step (clk,reset,out,der,d);//总体模块d[5:0]调速控制端口 用6个拨码开关表示 全1速度最慢 全0时速度最快 其中1(0)的个数能表示西玛电机速度的快慢 else if(temp==3'd0) current1<=s1; s3: reg[2:0] current1; end if(cnt <= 8000) cnt <= cnt+1'b1;//0.5MS 1MS 2MS 4MS 8MS 4000 8000 16000 32000 64000 current<=s6; begin out<=4'b0010; begin a=~a; end begin parameter s0=3'b000,s1=3'b001,s2=3'b010, input clk1; if(!der) s7: end reg[25:0] cnt; begin else step1 l2 (p,reset ,out,der);//reset停止转动 out[3:0]西玛电机控制输出端口 der正反方向控制端 begin current1<=s5; begin else begin s4: s2: end end s6:
这两天,学校做关于cpld的课程设计,本来应该用VHDL写的,但是由于我对这个比较白痴,所以就选用Verilog HDL写了,由于旁边有同学是学这个的这样,有什么问题也好解决一点。下面就先把我Verilog HDL的处女作给大家贴出来,虽然功能比较简单,但毕竟也是第一个程序嘛。。。 module step1 (clk0,reset,out,der,x);//状态机module out<=4'b0001; current<=s0; current1<=s3; begin end cnt <=26'b0; begin begin s1: else if(temp==3'd4) begin current<=s7; endcase begin begin current<=s3; else input clk ,reset,der,d; else if(temp==3'd5) current1<=s0; end begin begin begin end input clk0,reset,der,x; begin reg[2:0] temp; a=~a; current<=s4; begin end current1<=s6; out<=4'b1001; end reg a; current<=s2; a=~a; wire[5:0] adj; current1<=s3; begin if(!der) end wire p; a=~a; else begin current1<=s0; s1: begin else if(!der) out<=4'b0100; end begin else begin begin current<=s1; end begin end begin if(!der) end begin begin end if(temp==3'd6) if(cnt <= 32000) cnt <= cnt+1'b1;//0.5MS 1MS 2MS 4MS 8MS 4000 8000 16000 32000 64000 current<=s3; end end s6: reg[15:0] counter; begin cnt <=26'b0; case(current) endmodule current<=s6; begin if(cnt <= 16000) cnt <= cnt+1'b1;//0.5MS 1MS 2MS 4MS 8MS 4000 8000 16000 32000 64000 end else else if(temp==3'd3) current<=s2; begin end always@(posedge clk0 or negedge reset ) end s6=3'b110,s7=3'b111; cnt <=26'b0; input[5:0] adj; s3=3'b011,s4=3'b100,s5=3'b101, cnt <=26'b0; if(cnt <= 12000) cnt <= cnt+1'b1;//0.5MS 1MS 2MS 4MS 8MS 4000 8000 16000 32000 64000 current1<=s6; begin end s4: else a=~a; end end current1<=s5; wire[5:0] d; if(cnt <= 6000) cnt <= cnt+1'b1;//0.5MS 1MS 2MS 4MS 8MS 4000 8000 16000 32000 64000 out<=4'b1000; begin else begin begin s7: s5: end end end s0: begin output[3:0] out; if(cnt <= 10000) cnt <= cnt+1'b1;//0.5MS 1MS 2MS 4MS 8MS 4000 8000 16000 32000 64000 current1<=s2; else else 西玛西玛电机