I want to take something like 100MHz clock input and use it to count variables in the FPGA.
If I want to create say 25Khz clock (but many clocks which are not divisible also!) , I would have something like..
Code: Select all
VAR1.CK = 100MHz
VAR1 = VAR1 +1
100,000,000 \ 25,000 = 4000
So I would have something like
Code: Select all
IF VAR <4000 THEN OUT1 = 0
IF VAR1 >4000 THEN OUT1 = 1
IF VAR1 > 4000 x 2 THEN VAR = 0
Over 4000 we flip the bit to 1 and OUT1 becomes 1
If we get to the end of the clock cycle (4000 x 2) then we set it back to zero to restart the count again.
So basically OUT1 will give a clock output of 25,000 Hz (25Khz).
Now if I want a clock 25,050Hz, I just do a new calculation..
100,000,000 \ 25,050 = 3992 clock, and I just use the same code but with 3992 instead of 4000. Then OUT1 will give a 25,050Hz clock output.
I actually want to set this "count to value" from the CPU via a register ultimatly..