Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21616 Discussions

How to compare input value to previous value by number of counts

Altera_Forum
Honored Contributor II
2,954 Views

Hello all, 

 

I have a module takes in input [15:0] in and I want to compare this new input to my previous value by number of counts. 

 

module _update(input clk, input [15:0] in, ....) 

reg [15:0] rPrev, rChange; 

 

always @(posedge clk) begin 

rPrev <= in; 

end 

 

always @(posedge clk) begin 

if (in > rPrev) 

rChange <= in - rPrev; 

else if (in < rPrev) 

rChange <= rPrev - in; 

end 

 

always @(posedge clk) begin 

if (rPrev != in && rChange >= 50 && rChange <= 100) begin // rChange has to be in range 50 to 100 counts 

// update  

 

end 

end  

 

 

Am I doing this right? 

 

 

Thanks, 

Sean
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
2,094 Views

why not simulate it in a testbench and find out yourself?

0 Kudos
Altera_Forum
Honored Contributor II
2,094 Views

People who ask "help me with my homework/project" questions on the forums will probably learn more by talking with fellow students and the prof. You need to learn how to simulate hardware to move forward with this.

0 Kudos
Reply