nitheeshnas
Newbie level 4
- Joined
- Jan 14, 2014
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 52
i am doing a project on designing an ic for controlling the speed of a dc motor . the main modules in my project are pwm ,encoder,counter and pid..
i have generated the codes for counter, pid and pwm seperately but when i try to link it ..i am not getting it right ...plz help me..
these are my there modules
1,counter
2,pid
3,pwm
and i want to connect these 3 modules that is i want to input the output of counter to pid and output of pid to pwm...plz help me
i have generated the codes for counter, pid and pwm seperately but when i try to link it ..i am not getting it right ...plz help me..
these are my there modules
1,counter
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 module count(clk,a,out,r,n,e); input clk; input a; input [7:0]r; input [7:0]n; integer counter=0; output reg [7:0]e; output reg [7:0]out; reg [7:0]temp; always @ (a) begin if (a==1) counter=counter+1; temp=(counter/r); out=(temp*n); if (out>=200) e=out-200; else e=200-out; end endmodule
2,pid
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 module PIDdddd(u_out,e_in,clk,reset,u); output signed [15:0] u_out; output signed [15:0] u; input signed [15:0] e_in; input clk; input reset; parameter k1=107; parameter k2 = 104; parameter k3 = 2; reg signed [15:0] u_prev; reg signed [15:0] e_prev1; reg signed [15:0] e_prev2; assign err=(e_in/5); assign u =(u_prev)+(k1*err)+(k3*e_prev2); assign u_out = u+(-(k2*e_prev1)); always @ (posedge clk) if (reset == 1) begin u_prev <= 0; e_prev1 <= 0; e_prev2 <= 0; end else begin e_prev2 <= e_prev1; e_prev1 <= err; u_prev <= u_out; end endmodule
3,pwm
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 module pulse(clk,switches,pwm); input clk; input [16:0] switches; output pwm; reg pwm; reg [15:0] counter=0; parameter sd=195; always @ (posedge clk) begin counter=counter+5; if(counter<=switches*sd) pwm=1; else pwm=0; if (counter>=50000) counter=0; end endmodule
and i want to connect these 3 modules that is i want to input the output of counter to pid and output of pid to pwm...plz help me
Last edited by a moderator: