Hi DaeCheol,
You need to sync up the HWAG with the first missing tooth by using the ARM CPU.
On each tooth arrival you record the PCNT (tooth width measurement).
Let's say that the tooth interrupt occurs, you go read PCNT and call this PCNT(n-1). You've saved the last two PCNT in a buffer and the previous tooth width is PCNT(n-2) and the one prior to that is PCNT(n-3).
You are looking for the case when PCNT(n-2) > PCNT(n-3) + PCNT(n-1). In other words your current tooth is a normal tooth, the previous was the gap, and the one prior to that was a normal tooth. The assumption is that the gap is 2 teeth wide and the measurement is ~3 tooth widths for PCNT(n-2).
When this condition is met, you can clear the HWAG's interrupt pending flags and start the HWAG by writing to the HWACTL register.
So, if you're starting the HWAG asynchronously to the missing teeth, then this could be the problem or part of the problem.
Once you've started the HWAG synchronously to the first missing tooth (detected by the CPU) then the HWAG will use the HWAG Teeth Number register. You set this to N-1 where N is the number of real teeth. So if your wheel is 60-2 then it has 58 real teeth and you set this register to 57. Of course this should be set before the synchronization described above. It's just that once the sync. is done with the help of the CPU the first time, then after that the HWAG will count teeth and compare against the HWAG Teeth number register value to determine when the *next* and subsequent gaps should occur.
When the gap should be there based on the tooth count, the HET Gap Flag signal is set. The HWAG is looking for a PCNT value that is > 2x the normal tooth PCNT value (where the normal value in this case is based on the measurement of the last normal tooth). If the gap is shorter than 2x the last normal tooth value the HWAG generates an interrupt so that the CPU can handle the case.
During the gap - the HWAG will continue to generate angle increment ticks but it does this assuming that the gap is a 2 tooth gap and so its ticks during the gap will be 'off' if you don't have a gap of 2 teeth.
Now the HWAFIL0 and HWAFIL1 registers: These are filters which set a debounce period after the active edge is detected on each pulse input.
You calculate its value based on the Step Width (# of ticks that are generated for each tooth) and the percentage of the tooth width that you want to block off. If you want to filter out glitches during 75% of the tooth period, and your step width is 512, the calculation goes like this: Step Width x (1 - Percent) = HWAFIL0 value, so 512 * (1-0.75) = 128 for the HWAFIL0 value.
The HWAFIL1 is what is applied during the gap. The gap is nominally 3x larger so the value would be 384 for the same 75% of blocking.