Forum Discussion
Altera_Forum
Honored Contributor
11 years agoHow to compare input value to previous value by number of counts
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, Sean2 Replies
- Altera_Forum
Honored Contributor
why not simulate it in a testbench and find out yourself?
- Altera_Forum
Honored Contributor
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.