Problem with g_timer0.p_api->periodSet(g_timer0.p_ctrl, 3500, TIMER_UNIT_PERIOD_USEC)

Hello
I am a new member in this group.
I use IAR Embedded Workbench for Renesas Synergy with SSP 1.5 and i have
a problem to use this fonction :

g_timer0.p_api->periodSet(g_timer0.p_ctrl, 3500, TIMER_UNIT_PERIOD_USEC);

It works correctly but when i change the delay over 8.7 ms, the delay is wrong, i think it's because the API change the internal clock of the timer to have bigger delay but not correctly
Anybody know this problem please ?
Thank you for your help
  • Which Synergy device are you using?
    Which timer? Timer on GPT or or Timer on AGT?
    Which mode of operation: period timer or pwm?

    Regards,
    Richard
  • Does the function return an error like SSP_ERR_INVALID_ARGUMENT?
  • In reply to FrankL:

    Hello,
    I encounter a similar problem with R_GPT in PWM mode and with ssp1.5.0-rc1 and e2studio v6.2.1.

    Indeed, if I choose a frequency, in output I see the half of the value of this frequency ...
    I tried to stop the timer before calling PeriodSet no effect ...
    Worse, the DutyCycle is not variable, it always remains at 50% ...
    This worked very well on older versions (e2studio 5 and ssp v1.33)

    I use GCC ARM Embedded Toolchain Version: 4.9.3.20150529 for Device: R7FS7G27G3A01CFP

    My code :

    memcpy(&_pwmcfg, g_PWM_DCDC.p_cfg, sizeof(timer_cfg_t));
    _pwmcfg.duty_cycle=20;
    _pwmcfg.period=100;

    _err = g_PWM_DCDC.p_api->open(g_PWM_DCDC.p_ctrl, &_pwmcfg);
    uart_resultsend(_err);
    _err =g_PWM_DCDC.p_api->periodSet(g_PWM_DCDC.p_ctrl, _freqpwmdcdc, TIMER_UNIT_FREQUENCY_KHZ);
    uart_resultsend(_err);
    _err=g_PWM_DCDC.p_api->dutyCycleSet(g_PWM_DCDC.p_ctrl, 20, TIMER_PWM_UNIT_PERCENT, 0);
    uart_resultsend(_err);
    g_PWM_DCDC.p_api->start(g_PWM_DCDC.p_ctrl);

    On the output, frequency = 50KHz, and DT=50%...

    Thanks for your help.
    Eric
  • In reply to Richard:

    Hello Richard, FrankL and Eric

    Thank you for your answers, i just understand what is the problem.
    I use AGT timer (16 bit) and with the clock PCLOCKB (7500000 Hz) so when i call
    g_timer0.p_api->periodSet(g_timer0.p_ctrl, 10000, TIMER_UNIT_PERIOD_USEC) it return SSP_ERR_INVALID_ARGUMENT
    So to get bigger time i only have to change the PCLOCKB to LOCO (32768 Hz)
    My error was that i believe that the clock change automatically to make the good delay.
    Thank you for your help
  • In reply to Eliec:

    Hello Eliec,

    Glad you found your problem.
    But this is not my case, each command issued returns well SSP_SUCCESS, the PWM works on the right output, but the frequency is the half of that desired, and moreover; I can not change the duty cycle ...
    I have already used PWM on RGPT 1 on the same S7A3 but with older versions of e2Studio and ssp ...
    I do not see any information about this on the release note of sspv1.5.0-rc1, nor on the user manual.
    I use PLL = 240MHz; (XTAL = 24MHz) and PBCLK = 60MHz.
    I first tried with the graphical configurator of the SSP, the problem was already present.

    If anyone can explain to me? Thank you in advance.
  • In reply to Eric:

    Eric,

    I have test the API you are trying to use on an S7G2 device with SSP1.5.0 rc1 (I assume you are using S7G2 from the clock frequencies you refer to)

    I do not see any issue.  The PWM frequency is set correctly and the duty cycle % is set accordingly.

    I am using GPT0 (GTIOCA0 - P5.12) as GPT1 TCIO pins are used for JTAG and RMII functionality on the S7G2-SK.

    I have tested with the GPT clock - PLCKD - set to 60 & 120MHz

     

    The very simple test code changes the period frequency between 20kHz and 50kHz in a while (1) loop and maintains that duty cycle at 20%

    The video shows that this is working.

     

    Can you try this simple code and see what the results are?

     

    Regards,

    Richard

     

    /* HAL-only entry function */
    #include "hal_data.h"

    ssp_err_t _err;

    timer_size_t _freqpwmdcdc;

    void hal_entry(void)
    {
        /* TODO: add your own code here */
        _err = g_timer0.p_api->open(g_timer0.p_ctrl, g_timer0.p_cfg);
        if(SSP_SUCCESS != _err)
        {
            __BKPT(1);
        }

        while(1)
        {
            R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_SECONDS);

            _err = g_timer0.p_api->periodSet(g_timer0.p_ctrl, 50, TIMER_UNIT_FREQUENCY_KHZ);
            if(SSP_SUCCESS != _err)
            {
                __BKPT(1);
            }

            _err= g_timer0.p_api->dutyCycleSet(g_timer0.p_ctrl, 20, TIMER_PWM_UNIT_PERCENT, 0);
            if(SSP_SUCCESS != _err)
            {
                __BKPT(1);
            }


            R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_SECONDS);

            _err = g_timer0.p_api->periodSet(g_timer0.p_ctrl, 20, TIMER_UNIT_FREQUENCY_KHZ);
            if(SSP_SUCCESS != _err)
            {
                __BKPT(1);
            }

            _err= g_timer0.p_api->dutyCycleSet(g_timer0.p_ctrl, 20, TIMER_PWM_UNIT_PERCENT, 0);
            if(SSP_SUCCESS != _err)
            {
                __BKPT(1);
            }

        }
    }

     

     

     

  • In reply to Richard:

    Wow thank you Richard,

    I'm a stupid boy!

    By checking the graphical configuraton of my PWM, I have just seen that the mode field was placed on "Periodic" instead of "PWM" !!

    I accidentally changed this parameter in the graphical setting using the mouse wheel ...

    I should have thought twice before posting this message ...

    Now it's better !

    Sorry... and thanks for your help.

    Eric