It is well said in TRM that TBPRD register must be one less that PWM period. So if I want to make 40kHz PWM (assuming 90MHz operation) I would set TBPRD as 2250 - 1 = 2249 and if I would like to make 400kHz PWM I would set the TBPRD to 225-1 = 224
Also if I would want to make 400kHz PWM with 50% DC I would need to set CMPA as 225 / 2 = 112.5, So therefore I set CMPA as (225/2) - 1 = 111 and CMPAHR as 0.5 * 65536=32768 and would get nice PWM.
However I noticed that when I want to make 40kHz PWM with 50% DC I would need to put 2250/2 = 1125 into CMPB not 1124.
So this is now confusing. When do I need to consider proper period for duty cycle and when I need to subtract 1 for duty cycle?