Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20704 Discussions

variable reset simple question

Altera_Forum
Honored Contributor II
1,187 Views

Hello friends,  

 

I have something like this 

 

always @(posedge clkin) 

begin 

 

... 

... 

cnt = cnt+1;// increment 

 

... 

... 

end 

 

and another input named OE. On posedge of OE I want cnt=0.  

 

always @(posedge OE) 

cnt=0 

 

invalid... 

 

How can I do that? 

 

Thanks,
0 Kudos
9 Replies
Altera_Forum
Honored Contributor II
433 Views

always @(posedge clkin or posedge OE) if(OE) cnt <= 0; else cnt <= cnt + 1;

0 Kudos
Altera_Forum
Honored Contributor II
433 Views

I already tried that but gives some error and I thought is invalid 

 

"cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct"... 

 

can you explain a little bit ? In addition, I need cnt to be blocking if possible
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

well, I solved a bit but isn't full working 

 

always @(posedge clkin or posedge OE) 

if(OE) 

cnt = 0; 

else 

begin 

 

.... other actions on posedge clkin possible only here but I need them always 

 

end 

 

cnt = cnt + 1; 

 

 

and when OE=1 no more counter increment. Can you suggest something please? I am trouble understanding what's behind yet since I'm used to circular flow like C. Thanks very much.
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

It's not possible to increment the counter and at the same time reset it. 

You need to choose your priorities. 

 

clk has priority and OE is read synchronously with one cycle delay: 

always @(posedge clkin) begin reg OE_D; OE_D <= OE; if (OE && ~OE_D) begin // synchronously detect rising edge of OE cnt <= 0; end else begin cnt <= cnt + 1; end end Otherwise you will need the other version, more economical (only a single register), but does not count up while OE =1 

 

always @(posedge clkin or posedge OE) begin if(OE) begin cnt <= 0; end else begin cnt <= cnt + 1; end end  

 

Which tool gives you the error: 

"cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct"... 

 

And how exactly did the code that triggered that error looked like ?
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

Dear Sir, 

 

This is exactly what I need, thank you very much! 

 

Memorize old_value and upon next clock goes HI, will have the situation old=LO and new=HI. Detecting only rising edge. 

 

Have a good day both, 

 

PS. Nevermind, error was given by using  

 

always @(posedge clock and posedge OE) 

 

if (!OE) would be error 

 

I have to get familiar with verilog :)
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

 

--- Quote Start ---  

I have to get familiar with verilog 

--- Quote End ---  

 

Yes. Did you notice the language templates accessible in the Quartus editor context menu. They are providing example code for similar basic constructs.
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

Hi, 

 

 

--- Quote Start ---  

Dear Sir, 

 

I need cnt to be blocking if possible 

 

--- Quote End ---  

 

 

It would be a very bad style trying model Sequential logic using blocking assigns. Use NBA instead.  

 

 

--- Quote Start ---  

 

I have to get familiar with verilog :) 

--- Quote End ---  

 

 

Yes, pick up a good book like Palnitkar/Bhasker to start with. If your company has it, use a LINT tool (such as ALINT from www.aldec.com). 

 

Good Luck 

Srini 

www.cvcblr.com/blog
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

Thank you all, I solved, great community.  

 

Btw. I changed all possible vars to NBA and saved few extra macrocells :) Simulation looks great and I'm very confident since no warnings except main clock undefined or so, no timing problems. This was just a minor update of a working project designed few moths ago. And however, I want to congratulate Quartus team, compared at least to Xilinx and worse Lattice it's a great job! 

 

We face now a terrible problem. Our prototype which includes this EPM3064 will be homologate somewhere in september but we cannot find anywhere to buy industrial version EPM3064ATI. As far as I heard from my colleagues, will be tested at -33deg C. There is no speed constraints since CPLD works at most on several hundred KHz but at all distributors there is only commercial version and industrial has 26 weeks delivery time. 

 

Does anyone knows Altera can send some samples? Can I fill some urgent request somewhere? Or to buy from somewhere else (we try Farnell, Digikey, Avnet, Future). 

 

Best regards, 

 

PS. We have old projects already with C versions working. Anyone knows if we know clock is under 1MHz can we use at -33deg ? (even my boss will now allow)
0 Kudos
Altera_Forum
Honored Contributor II
433 Views

Talk to your local FAE and/or Sales rep with regards to part procurement. They're really the only ones who can help you there. 

 

Jake
0 Kudos
Reply