- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wrote a verilog program as follow
UD_Cnt(CLK,UD_counter) is a Up-down counter module, CPS_PWM(CLK,Cx) is a PWM module, containing multiple UD_Cnt module with different initial value。 UD_cnt is invoked in main module(CPLD5) and CPS_PWM. I used quartus II 15.1 to compile (http://www.baidu.com/link?url=hl0pwwsl_hj-i4clqiz0y2n6xemffylppwh-xtcverq_ldgxunk9rlteichzbh4-j2momajutajil8jgc64km7ueb3vynbhjpeb5uu_74r3) this project, then simulated in quartus. The simulate result shows that, only the UD_cnt of UDxx in CP1 is correct. The initial value of UDxx in CPLD5 and UD2 UD3 UD4 in CP1 in wrong. It seems that, only the counter which is finally output in CPLD5 is correct. Then I used modelsim to simulate the same project, and everything is fine, the initial value of every counter is correct. Did anyone knows what's wrong with my project?module CPLD5(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 XA;
input XD;
output Aup,Adown,Bup,Bdown,Cup,Cdown;
output UD_counter,Cx;
wire CC;
output O1,O2,O3,o4;
output CLK1M;
UD_Cnt# (257) UDxx(CLK_150M,CC);
CPS_PWM CP1(CLK_150M,UD_counter);
endmodule
module CPS_PWM(CLK,Cx);/*synthesis noprune*/
input CLK;
output Cx;
wire C1,C2,C3;/*synthesis noprune*/
UD_Cnt# (259) UDxx(CLK,Cx);
UD_Cnt# (0,0) UD2(CLK,C1);
UD_Cnt# ((500/2),1) UD3(CLK,C2);
UD_Cnt# (500,0) UD4(CLK,C3);
endmodule
module UD_Cnt(CLK,UD_counter);/*synthesis noprune*/
parameter CNT_ini = 167,Dir_ini = 0;
input CLK;
output reg 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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't you need to pass two parameters? If so, these lines are wrong:
UD_Cnt# (257) UDxx(CLK_150M,CC); UD_Cnt# (259) UDxx(CLK,Cx); You're not including the direction parameter.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, these tow paramters are needed to be passed, but I hope to correct the initial value at this moment.
--- Quote Start --- Don't you need to pass two parameters? If so, these lines are wrong: UD_Cnt# (257) UDxx(CLK_150M,CC); UD_Cnt# (259) UDxx(CLK,Cx); You're not including the direction parameter. --- Quote End ---- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Don't you need to pass two parameters? If so, these lines are wrong: UD_Cnt# (257) UDxx(CLK_150M,CC); UD_Cnt# (259) UDxx(CLK,Cx); You're not including the direction parameter. --- Quote End --- Not wrong. If you don't supply the parameter in the module instantiation it will use the default value supplied in the parameter statement. However, in the UD_Cnt module in a couple of IF statements you use the bitwise AND operator (&) instead of the logical AND (&&) operator to combine conditionals.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank u for your reply. I think using AND operator instead of logical AND doesn't lead to the wrong initial value of UD2,UD3,UD4. Do you have any idea about waht may cause wrong initial value?
--- Quote Start --- Not wrong. If you don't supply the parameter in the module instantiation it will use the default value supplied in the parameter statement. However, in the UD_Cnt module in a couple of IF statements you use the bitwise AND operator (&) instead of the logical AND (&&) operator to combine conditionals. --- Quote End ---
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page