Hello,
Check the value within the ICSTRM register at address 0x003A, and compare with the value stored at flash address 0xFFAF. The two values should be identical, assuming the initialisation code sets the ICSTRM register using this flash value. If the two values are different during debug, this might account for the differences you are observing.
For the PWM frequency that you require, a trim frequency of 31.25 kHz would seem to be a better choice. This will require a modulo value of 39999 with a bus frequency of 4.000 MHz. This may simplify the calculation of the required channel value for a given duty cycle.
Regards,
Mac