Important note:
After reading (again) your other question and its answers: You are stressing the input of your Arduino with negative voltages! Please set the offset of the signal to 2.5V (the middle between GND and VCC) and the amplitude to 5Vpp. The signal must neither be lower than GND nor higher than VCC! The input might withstand this for a while but given enough time and power it will get damaged.
Analysis of your problem:
1. The measurement of the period
Let's take a look at a "condensed" version of your time code:
void setup()
{
startMillis = millis();
}
void loop()
{
currentMillis = millis();
if (currentMillis - startMillis <= period)
{
startMillis = currentMillis;
}
}
I'm sure you see it now, too! Because right at the first call of loop() the time passed since setup() is short, the condition is true and startMillis is updated to the current time. This is repeated ever and ever again. The condition will always evaluate as true.
2. The number of pulses
In the function CountPulses() the counter is reset at the beginning. Then after some undefined very short duration (because your if-condition is always true) it is read. Chances are low for a pulse to be counted in that time span.
Additional note:
Just one more tip. You can define and use your own data types to show your intentions. For example the states look so much better like shown below, and you'll get free error messages from code analyzers.
typedef enum {
STATE_00, STATE_01, STATE_10, STATE_11,
} fsm_state_type;
fsm_state_type fsm_state = STATE_00;
EDIT after you added new informations:
Item #2
Why do you think you need to debounce the laser pulse? Is it generated by a mechanical switch? Only those need debouncing. If the pulses are generated from some electronic circuit they should be clean.
Item #4
You can reset the IRQcount and then wait for it to count up.
But as this involves disabling and enabling the interrupt and reading an int just for 1 event, I'd rather set a flag if the interrupt occurs. Then the FSM could wait for the flag to be set.
Another alternative is to poll the input pin directly and to wait for the leading edge. But for this the pulse has to be wide enough.
As @EdgarBonet pointed out it will be even simpler to poll the interrupt flag. But IIRC the interrupt has to be disabled for this, else the call of the interrupt service routine will clear the flag with no chance for the main program to see it.
A better alternative is to poll the interrupt flag (i.e.
if (bit_is_set(EIFR, INTF0)) { ... }). Then you don't need a wide pulse: once the hardware detects the rising edge, the flag is set and remains set until you explicitly clear it (EIFR = _BV(INTF0);).