So my suspects were close! 300uS seems ok. But we'll have to try more tips to find a safe value. Maybe 500uS.
Your theory would work only in low pwm duties. How do we do that in a 9x% pwm?
If we do so, we will also need to measure the time since the pwm went down. Again, we will have wait.
But it'll be much more complicated. You can't delay the PWM output easily, pwm doesn't work like that.
Actually this is the method:
First, we set the maximum PWM value: 20.000uS period - ( ADC time(~30uS) + Delay time(~300uS) ) = 19.673uS
So at max PWM output we will always have the time for measuring.
This is how a PWM cycle works:
The PWM counter starts at 0, output goes high.
When the counter reaches the value in pwm value register, output goes low and the timer compare interruption triggers.
I use the interrupt to start a secondary counter that acts as delay. When the delay counter resets, automatically starts the ADC conversion.
The ADC conversion ends and generates an interrupt. The PWM is about to start, but we can measure the rest of the values. We start another conversion, just for the voltage and ambient temperature.
The counter continues (pwm off time) until reaching the PWM period register.
The counter resets and a new PWM cycle starts.
By now the ADC should have finished the secondary conversions. It disables, waiting for the next trigger from the delay counter.
This method has the advantage of being easily adjustable. We can modify the delay timer as we wish.
It works totally isolated from the main program, so it's much safer. A mistake causing a stuck loop won't leave the pwm calculation unattended, risking at burning your tip.
The max PWM will be 98.3%. It's ok! I can tell you that the stock fw, even the original PTdreamer one, heat slower because they take a lot of measurements and use higher pwm frequency.
Also, as we take measurements every 20mS, it should be pretty stable. What could be the max temperature variation in 20mS? Maybe 5ºC?
The only issue here is the delay. As you can see in the waveforms, it gets perfect after 300uS or even less depending on the tip.
Maybe we could add a second transistor and switch the heater to ground to quickly discharge the output. As long as we wait enough time to not shoot-through...
But again, why that much if we only need to wait!
The Hakko probably has higher inductance, mainly due the use of thicker heating elements and more turns?