PWM without interrupt

Hi,

in my example i used RZA1H and i have a problem when i set the dutycycle at 100%.

I attached my code below :

void Bsp_Dspl_BacklightInitPwm(uint32_t freqHz)
{
uint8_t i;
for(i = 0; i < MAX_NUM_PRESCALER_PWM; ++i)
{
if(((BSP_PERIPHERAL0_CLK / prescaler[i].pscValue) / freqHz) < U16_MAX_VAL)
{
break;
}
}
bsp_pwm.prescaler = prescaler[i].pscSelect;
bsp_pwm.clock_edge = HalMTU_eRisingEdge;
bsp_pwm.counter_clear_source = HalMTU_eTCNT_HalMTU_tCCLR_CH1_2_TGRB_CMP_MATCH;
bsp_pwm.period = (BSP_PERIPHERAL0_CLK / prescaler[i].pscValue) / freqHz;
bsp_pwm.mode = HalMTU_ePWM_Mode1;

/* Stop */
rza_io_reg_write_8(&MTU2.TSTR, 0x00U, MTU2_TSTR_CST2_SHIFT, MTU2_TSTR_CST2);
/* Disable write-protected register */
rza_io_reg_write_8(&MTU2.TRWER, 0x01U, MTU2_TRWER_RWE_SHIFT, MTU2_TRWER_RWE);
/* Reset counter channel 2 */
MTU2.TCNT_2 = 0x0000U;

/* Set TCR register */
/* prescaler */
rza_io_reg_write_8(&MTU2.TCR_2, bsp_pwm.prescaler, MTU2_TCR_n_TPSC_SHIFT, MTU2_TCR_n_TPSC);
/* Clock edge */
rza_io_reg_write_8(&MTU2.TCR_2, bsp_pwm.clock_edge, MTU2_TCR_n_CKEG_SHIFT, MTU2_TCR_n_CKEG);
/* Counter clear source */
rza_io_reg_write_8(&MTU2.TCR_2, bsp_pwm.counter_clear_source, MTU2_TCR_n_CCLR_SHIFT, MTU2_TCR_n_CCLR);

/* Set TGR register */
//rza_io_reg_write_16(&MTU2.TGRA_2, 0x0000U, MTU2_TGRA_n_D_SHIFT, MTU2_TGRA_n_D);
rza_io_reg_write_16(&MTU2.TGRA_2, bsp_pwm.period, MTU2_TGRA_n_D_SHIFT, MTU2_TGRA_n_D);
rza_io_reg_write_16(&MTU2.TGRB_2, bsp_pwm.period, MTU2_TGRB_n_D_SHIFT, MTU2_TGRB_n_D);

/* Set TMDR register */
/* Set mode operation timer */
rza_io_reg_write_8(&MTU2.TMDR_2, bsp_pwm.mode, MTU2_TMDR_n_MD_SHIFT, MTU2_TMDR_n_MD);

/* Set TIOR register */
rza_io_reg_write_8(&MTU2.TIOR_2, 0x01U, MTU2_TIOR_2_IOA_SHIFT, MTU2_TIOR_2_IOA);
rza_io_reg_write_8(&MTU2.TIOR_2, 0x02U, MTU2_TIOR_2_IOB_SHIFT, MTU2_TIOR_2_IOB);

/* Set TSR register */
rza_io_reg_write_8(&MTU2.TSR_2, 0x01U, MTU2_TSR_2_TCFU_SHIFT, MTU2_TSR_2_TCFU);
rza_io_reg_write_8(&MTU2.TSR_2, 0x01U, MTU2_TSR_2_TCFD_SHIFT, MTU2_TSR_2_TCFD);

/* Enable write-protected register */
rza_io_reg_write_8(&MTU2.TRWER, 0x00U, MTU2_TRWER_RWE_SHIFT, MTU2_TRWER_RWE);
/* Start count */
/* Set TSTR register */
rza_io_reg_write_8(&MTU2.TSTR, 0x01U, MTU2_TSTR_CST2_SHIFT, MTU2_TSTR_CST2);
}


void Bsp_Dspl_BacklightSetPwm(uint8_t dutyCycle)
{
uint16_t dummy_read;
UNUSED_VARIABLE(dummy_read);
/* Disable write-protected register */
//rza_io_reg_write_8(&MTU2.TRWER, 0x01U, MTU2_TRWER_RWE_SHIFT, MTU2_TRWER_RWE);
bsp_pwm.dutycycle = ((uint32_t)bsp_pwm.period * dutyCycle) / 100U;
rza_io_reg_write_16(&MTU2.TGRB_2, bsp_pwm.period, MTU2_TGRB_n_D_SHIFT, MTU2_TGRB_n_D);
rza_io_reg_write_16(&MTU2.TGRA_2, bsp_pwm.dutycycle, MTU2_TGRA_n_D_SHIFT, MTU2_TGRA_n_D);
if (0x01U == ((rza_io_reg_read_8(&MTU2.TSR_2, MTU2_TSR_n_TGFA_SHIFT, MTU2_TSR_n_TGFA)) & 0x01U))
{
dummy_read = rza_io_reg_read_8(&MTU2.TSR_2, MTU2_TSR_n_TGFA_SHIFT, MTU2_TSR_n_TGFA);
rza_io_reg_write_8(&MTU2.TSR_2, 0x00, MTU2_TSR_n_TGFA_SHIFT, MTU2_TSR_n_TGFA);
dummy_read = rza_io_reg_read_8(&MTU2.TSR_2, MTU2_TSR_n_TGFA_SHIFT, MTU2_TSR_n_TGFA);
}
/* Enable write-protected register */
//rza_io_reg_write_8(&MTU2.TRWER, 0x00U, MTU2_TRWER_RWE_SHIFT, MTU2_TRWER_RWE);
}

 

Someone note problems into my code?

thanks you very much in advanced

Este