Ok, bit of a brain dump to try and get thoughts in order. First, this is what I think we should be aiming for:
To achieve this the PwnGeneration::Run() function needs to be called earlier than it currently is so that it can have the new dutycyles calculated prior to the timer reload at the mid pulse point. Testing so far indicates that there is a 64us window in which this can be done.
I'm not comfortable running the PwmGeneration::Run() function from the ADC injected conversion complete ISR. This is already slaved from another ISR in code, would add too much dependence on other modules and would also need the resolver timer to be running in all other encoder modes.
There is a spare capture/compare unit on the PWM timer. It should be possible to use this to generate another interrupt at whatever point in the PWM period that we want (and then use this to call PwmGeneration::Run()). The problem is that at higher PWM frequencies there would be multiple interrupts for each control loop execution. I think we can get round this by reading the repetition counter in the ISR to decide whether to call PwmGeneration::Run() to execute the control loop. This still leaves one problem, the Run() function would need to complete within a single PWM period at the highest frequency, or 56us (in order to ensure that we do not start to miss interrupts). This should be possible if some of the slower bits (such as Mtpa()) are moved to the 1/10/100ms tasks.
If done this should get the measurement to output latency down from 180us to around 60us, a factor of three improvement, which will make a big improvement to control loop stability but it's a lot of changes to the codebase.
Is it worth it?