This problem is killing me. I've been on it for two days now and wondering if I just have stuck with PIC16.
Inputs (all working)
AC0 -> Over Voltage
AC1 -> Normal Voltage
AC2 -> Zero Cross
Logic (not working)
TMRB0 -> Frequency measuring using AC2, event piped through to LUT0
LUT0 (EVENT0=TMRB0, EVENT1=AC1) -> S
LUT1 (AC0) -> R
TMRD Deadband control
The reason for piping TMRB0 through instead of using AC2 event directly is LUT0 does not support falling edge detection. What they say in the datasheet is to invert the logic, which is ridiculous as it doesn't change the edge it's monitoring, and besides which there are three channels driving the logic. I tried and it doesn't work. I also tried inverting the AC2 output with no joy (Event system must bypass the inversion).
TMRB on the other hand supports falling edge so it sounds promising. Go with that...
When over-voltage occurs the latch goes low and TMRD deadband kicks in. This works. TMRB resets the latch at zero-cross (ish) and it starts over. This is good as I've managed.
Ideally I'd like to wait until the voltage has reached a normal level, which comes from AC1. It sounds easy enough to make the logic =1 when AC1=0 and the pulse comes in from TMRB. To test, I set AC1 to use the same voltage point as AC0 - in other words it should be logic 0 immediately or thereabouts so make little difference.
What actually occurs seems to be a hardware bug, let's see it on the scope.
You can see it's took three AC cycles for the device to hit the over-voltage. With AC1 event it then takes 16 cycles (always 16!) before the latch will reset which, because it's based on some type of counting typically results in the device going into uvlo and resetting. I'm unable to resolve this condition no matter the parameters of the LUT, sync options or AC1. I also replaced AC1 with AC0 and the same occurred, so it appears some quasi logic is going on when two LUT-IN-X channels are used for deriving the logic.
Any ideas most welcome!