Hey @Marc_O,
You are using very very high values of dead_zone.
Dead zone of 0.2 means that 20% of your duty cycle you have both both mosfets open. This means the largest voltage you can set to the motor is 20% less than your supply voltage.
And 0.4 means its 40%. So if you are using dead zone of 0.4 and you have a power supply of 24V you can only set 0.6*24 = 14.4V
I’ve looked into the IRFS7530 mosfets (datasheet ), they have the rise-up and fall-down time of about 200ns = 0.2micros.
Which means that on 40kHz, the 2% dead zone (0.02) would make for 0.25micros of dead time for rise-up and fall-down. This is too close to the mosfet values and that is probably why you have seen the heating.
dead_time = dead_zone/freq_pwm/2 = 0.02/40000/2 = 0.25us
For example, as a conservative value to be safe, you should have a dead time for both rising and falling of about 1us. And on 40kHz you would need dead_zone of:
dead_zone = dead_time*freq_pwm*2 = 1e-6*40000*2 = 0.08
So 8%, which is a lot actually.
So once when you lower the frequency to 20kHz:
dead_zone = dead_time*freq_pwm*2 = 1e-6*20000*2 = 0.04
Which is a bit better.