I’m a few years late and haven’t read the whole thread in detail, but this is incredible I’ve been trying to do deadtime compensation in the driver setPwm and failing badly, but this works beautifully.
I also tried putting it inside the SVPWM section of setPhaseVoltage where the offset center voltage is known rather than using driver->voltage_limit/2, but I couldn’t tell any difference.
In my case, the ideal dtcomp is power supply voltage * deadtime%. Not x2 like yours, but still seems oddly coincidental. And it seems to need the voltage command offset by dtcomp*1.25 to keep the current amplitude unchanged. These images are without modifying the commanded voltage, so compensated amplitude is much higher.