But I have no idea how to read the actual ticks between two triggers to measure the speed.
There are two ways to do what you need to do.
1 - Count the time if takes for successive encoder pulses to come in.
2 - Count the encoder pulses that comes in per unit time.
For # 1, set an interrupt to increment a counter every 100 uS or so. When one pulse comes in, check the counter to see how long since the last pulse, then reset the counter and be ready for the next pulse
For #2, set an interrupt to run every 100mS (or so) and see how many pulses have come in the last 100mS.
Either way, to get the speed, you need a reference to time as in both the examples above.
NOTE: Method #1 cannot be used to track
position speed accurately, only
speed position, as you will lose partial counts when the pulse comes in. - added at edit - to gain more speed accuracy using this method, the interrupts need to get shorter, taking up more and more of the processor bandwidth -
Method #2 can be used to get both speed and position. If you set up the interrupts correctly, you will not lose any counts.