Developing a high speed stopwatch
I've been trying to make a high speed counter. Simulation says it should work- but the simulator I have working doesn't really account for gate propagation delays.
When I compile this, and download it to this Arduino Vidor 4000 which has a Cyclone 10 FPGA on it, even from initialization I'm getting noise out... I've tried a few different approaches. I was sort of thinking maybe the verilog compilation would have a method to know when a counter had completed counting, but in the netlist I don't really see anything like that.
This last iteration uses a small counter (9 bits) which 8 bits is used, and the 9th bit is a carry ingo a 17 bit counter, which 16 bits are used and the top bit carries into a 40 bit counter for a total of 64 bits of counting. the slower counters (above the 8 bit counter) should tick at a normal rate, but their output is just noise...
I was able to get it to sort of work by just assigning the rCOUNTER value (a 40 bit counter at the time) directly to the output, bypassing the latching registers - but that will not work for my needs... I do need as close to the correct count of ticks latched as I can get. Right now I can send a command to generate a latch - but that eventually will come from external hardware.
This is that version - it uses just a not-gate to drive the clock... I have had this working at various points somewhat better, but at some point something goes wrong and I just get noise out.
https://github.com/d3x0r/STFRPhysics/blob/master/hardware/fpga/new-counter2.v
This is a different version that just uses one 64 bit counter...
https://github.com/d3x0r/STFRPhysics/blob/master/hardware/fpga/clock-module.v
I sort of figured that the ripple count wouldn't matter a lot how fast it is clocked, since higher value bits in the counter would just be ahead of a prior input; and I would be able to latch that counter into 1 of 2 registers to provide a stable output to send out.
The whole idea is that there's a high speed counter, and two signals that will latch the counter into a register (one for each signal), and hold the value until the next rising edge latch basically - I did add a reset signal, so really it will latch a new value with a new latch signal after the lock on the register is released with a reset signal.
Is this possible with any FPGA? I have a requirement to count sub-nanosecond ticks, preferably 200ps or less. I tried looking for a more specialized sort of high tick rate realtime clock, but didn't really find anything, and I'd like to have something that is already on a board with USB communication to it...
The following is some of the output - tl2d and t2 are one 64 register, which is getting latched.
The other 64 bit tl3d and t3 (tl3d is the low part) has never been latched, and really should be 0 from the rLatch2 variable in the program...
tl2d:DFF1F3FF t2:FFFFFFF4 tl3d:1FF1F3FF t3:FFFFFFF6
tl2d:77F20909 t2:57539CD1 tl3d:1FF1F3FF t3:FFFFFFF6
tl2d:6D82597B t2:57EFFC73 tl3d:1FF1F3FF t3:FFFFFFF6
- this is another run, I delayed trying to do a latch for a few seconds, so this is what the board gives with nothing sent to it other than the FPGA code...
pins:0 tl2d:DFFF53FF t2:FFFFFFF6 tl3d:1FFF53FF t3:FFFFFFF6
pins:1 tl2d:6D39846D t2:1BF5FC1 tl3d:1FFF53FF t3:FFFFFFF6 (this is the first latched value, which the top 40 bits (t2 and the top byte of tl2d)) should be 0... I don't understand at all why everthing ends up so bad.
btw - do #N fields in verilog programs matter when compiled for hardware? or are they only simulation tips?