|
定义了一个计数器模块module UD_Cnt(CLK,UD_counter);(第94行),里面有两个parameter用于计数初值和计数方向的初始化。
但是我发现在主模块CPLD4里面调用该模块(第16行),和在另外一个模块(CPS_PWM)里面用同样的指令(第53行)调用得到的结果不一样。在主模块中计数器的初值是对的,但是仿真结果里面在CPSPWM里面的初值不对,而且计数值也不对,如图所示
- module CPLD4(CLK_150M,CS,RD,XA,XD,Aup,Adown,Bup,Bdown,Cup,Cdown,UD_counter,O1,O2,O3,o4,CLK1M,Cx);/*synthesis noprune*/
- parameter cntini = 511;
- input CLK_150M,CS,RD;
- input[4:0] XA;
- input[15:0] XD;
- output[7:0] Aup,Adown,Bup,Bdown,Cup,Cdown;
-
- output[10:0] UD_counter,Cx;
- output O1,O2,O3,o4;
-
- output CLK1M;
-
- CLK150_to_1 DIV1(CLK_150M,CLK1M,1);
-
- UD_Cnt #(cntini/2) UD1(CLK_150M,UD_counter);
- UD_Cnt #(250 ) UDxx(CLK_150M,Cx);
- CPS_PWM CP1(CLK_150M,100,300,500,Aup,Adown,Bup,Bdown,Cup,Cdown,1);
- endmodule
- module CLK150_to_1(CLK150M,CLK1M,RST);
- input CLK150M,RST;
- output CLK1M;
- reg[7:0] div_cnt;
-
- initial
- div_cnt = 0;
-
- always@(posedge CLK150M)
- begin
- if(div_cnt < 150)
- div_cnt = div_cnt+1;
- else
- div_cnt = 0;
- end
-
- assign
- CLK1M = (div_cnt > 74)? 1:0;
- endmodule
- module CPS_PWM(CLK,UrefA,UrefB,UrefC,PWM_UoA,PWM_DoA,PWM_UoB,PWM_DoB,PWM_UoC,PWM_DoC,BLOCK);
- parameter counter_limit = 500;
-
- input CLK,BLOCK;
- input[10:0] UrefA,UrefB,UrefC;
- output[7:0] PWM_UoA,PWM_DoA,PWM_UoB,PWM_DoB,PWM_UoC,PWM_DoC;
-
- wire[7:0] PWM_UA,PWM_DA,PWM_UB,PWM_DB,PWM_UC,PWM_DC;
- wire[10:0] C0[7:0];
- wire[10:0] Cx;
- /////////////////////////////////////////////////////////////
- UD_Cnt #(250 ) UD1(CLK,C0[0]);
- UD_Cnt #(250 ) UDx(CLK,Cx);
- UD_Cnt #(0 ,0) UD2(CLK,C0[1]);
- UD_Cnt #((500/2) ) UD3(CLK,C0[2]);
- UD_Cnt #(500 ) UD4(CLK,C0[3]);
-
- UD_Cnt #((500/4) ) UD5(CLK,C0[4]);
- UD_Cnt #((500/4) ) UD6(CLK,C0[5]);
- UD_Cnt #((500*3/4)) UD7(CLK,C0[6]);
- UD_Cnt #((500*3/4)) UD8(CLK,C0[7]);
- ////////////////////////////////////////////////////////////
- genvar j;
- generate
- for(j=0; j<4; j=j+1) begin:x
- assign
- PWM_UA[2*j] = (UrefA > C0[j]) ? 1'b1:1'b0, PWM_UA[2*j+1] = !PWM_UA[2*j],
- PWM_DA[2*j] = (UrefA > C0[j+4]) ? 1'b1:1'b0, PWM_DA[2*j+1] = !PWM_DA[2*j],
-
- PWM_UB[2*j] = (UrefB > C0[j]) ? 1'b1:1'b0, PWM_UB[2*j+1] = !PWM_UB[2*j],
- PWM_DB[2*j] = (UrefB > C0[j+4]) ? 1'b1:1'b0, PWM_DB[2*j+1] = !PWM_DB[2*j],
-
- PWM_UC[2*j] = (UrefC > C0[j]) ? 1'b1:1'b0, PWM_UC[2*j+1] = !PWM_UC[2*j],
- PWM_DC[2*j] = (UrefC > C0[j+4]) ? 1'b1:1'b0, PWM_DC[2*j+1] = !PWM_DC[2*j];
- end
- endgenerate
- ///////////////////////////////////////////////////////////
- genvar f;
- generate
- for(f=0; f<8; f=f+1) begin:DT
- delay_DT DT_UA(PWM_UA[f],CLK,BLOCK,PWM_UoA[f]);
- delay_DT DT_DA(PWM_DA[f],CLK,BLOCK,PWM_DoA[f]);
-
- delay_DT DT_UB(PWM_UB[f],CLK,BLOCK,PWM_UoB[f]);
- delay_DT DT_DB(PWM_DB[f],CLK,BLOCK,PWM_DoB[f]);
-
- delay_DT DT_UC(PWM_UC[f],CLK,BLOCK,PWM_UoC[f]);
- delay_DT DT_DC(PWM_DC[f],CLK,BLOCK,PWM_DoC[f]);
- end
- endgenerate
- endmodule
- module UD_Cnt(CLK,UD_counter);
- parameter CNT_ini = 167,Dir_ini = 0;
- input CLK;
- output reg[10:0] UD_counter;
- reg Dir;
-
- initial
- begin
- UD_counter = CNT_ini;
- Dir = Dir_ini;
- end
- always@ (posedge CLK)
- begin
- if(Dir == 0)
- UD_counter = UD_counter + 1;
- else
- UD_counter = UD_counter - 1;
- end
-
- always@ (posedge CLK)
- begin
- if((UD_counter == 500)&(Dir == 0))
- Dir = 1;
- else if((UD_counter == 1)&(Dir == 1))
- Dir = 0;
- end
- endmodule
- module delay_DT(pluse,CLK,Block,pluse_out);
- //1us delay(counter = 10) for posedge of pluse,Block=0(Block the IGBT)
- parameter CMP = 10;
- input CLK,pluse,Block;
- output pluse_out;
- reg[4:0] DT_counter;
- wire DT;
- initial
- DT_counter = 0;
- always@ (posedge CLK)
- begin
- if((pluse == 1) & (DT_counter < 5'd20))
- DT_counter = DT_counter + 1;
- else if(pluse == 0) //no operation on counter when pluse ==1 and counter=255
- DT_counter = 0;
- end
- assign
- DT = (DT_counter >= CMP) ? 1:0,
- pluse_out = pluse & DT & Block;
- endmodule
复制代码
|
|