Suppose we have an 8-bit counter out[7:0]
It needs to stay in each count for specified number of clocks x, where x can be any integer or fractional factor of 512.
Use 10 bit counter temp[9:0] that increments on every posedge clock
For x=512, increment temp in steps of 1, and increment out when temp==1
For x=256, increment temp in steps of 2, and increment out when temp==1 ....and so on.
Does anyone have a better idea than this, more resource efficient?
How to handle the case when x can take arbitrary values not necessarily related by factors of a particular number? We only know the max that x can be.
To clarify: x is just a normal 9 bit register. The value in x and number of hold clocks are related by 512/x = HoldClocks.
- 512/1 = 512
- 512/2 = 256
- 512/3 = 170.667
- 512/4 = 128
- 512/512 = 1.
How about the general case? What if max hold clocks isn't a power of 2? How would you handle the case where max hold clocks (x=1) is e.g 460 instead of 512?