Why is it separate duty and cycle when configure duty cycle in IAR for S6J32XX?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RoCo_4660301
Level 1
Level 1
5 replies posted 5 questions asked First reply posted

I'm trying to configure the PWM using the IAR example for S6J3200, but i don't understand what are they meaning by duty and cycle when setting the duty cycle.

Here the example code:

int main(void) {

    int tmr;

    // Finalize initialization to default settings.

    // (this will do IRQ and NMI initialization and global IRQ/NMI enable)

    Start_Init();

    /* PWM - configuration */

    stc_pwm_config_t stcPwmConfig = { .enPrescaler                 = PwmDiv1,         /* Clock further divided by 1 */

                                                               .bRestartEnable              = TRUE,             /* Enable restart */

                                                               .bPulseOutputMaskEnable      = FALSE,            /* normal polarity */

                                                               .enTriggerInputEdgeSelection = PwmSoftwareOnly,  /* Trigger with Software */

                                                               .bOutputPolarityInverse      = FALSE,            /* normal polarity */

                                                               .bOneShotOperation           = FALSE,            /* run cyclic */

                                                               .pfnTriggerCallback          = &PWMTriggerCallback,      /* use callback for interrupt */

                                                               .pfnDutyMatchCallback        = &PWMDutyMatchCallback,    /* use callback for interrupt */

                                                               .pfnUnderflowCallback        = &PWMUnderflowCallback};   /* use callback for interrupt */

    /* PWM - cycle configuration */

    stc_pwm_cycle_config_t stcPwmCycleConfig = { .u16Cycle           = 0xEA60,            /* PWM Cycle 60MHz-1ms cycle */

                                                                                  .u16Duty             = 0x7530,            /* PWM Duty  60MHz-1ms cycle*/

                                                                                  .u16StartDelay    = 0x0000,            /* Start Delay Value */

                                                                                  .u16AdcTriggerValue = 0x0000};           /* ADC Trigger Value */

    /* PORT - port pin configuration */

    stc_port_pin_config_t stc_port_pin_config = { .enOutputFunction      = PortOutputResourceG,

                                                  .enOutputDrive         = PortOutputDriveA,

                                                  .enPullResistor        = PortPullResistorNone,

                                                  .enInputLevel          = PortInputLevelCmosA,

                                                  .bInputEnable          = FALSE,

                                                  .bNoiseFilterEnable    = TRUE,

                                                  .enGpioDirection       = PortGpioOutput,

                                                  .enGpioInitOutputLevel = PortGpioLow};

    /* Configure the single port */

    Port_SetPinConfig(6, 0, &stc_port_pin_config);

    /* Init Timer with above configuration */

    Bt_Pwm_Init ((stc_btn_pwm_t*)&BT00_PWM, &stcPwmConfig);

   

    /* Start PWM by software trigger */

    Bt_Pwm_Start ((stc_btn_pwm_t*)&BT00_PWM, &stcPwmCycleConfig, TRUE);

    // Endless main loop

    for (;;)

    {

        /* Get timer data */

        tmr = BT00_PWM_TMR;

        // Clear hardware watchdog

        ClearWatchdog();

    }

}

Using IAR Workbench v8.50.1

0 Likes
1 Solution
Ashish
Moderator
Moderator
Moderator
25 likes received 50 solutions authored 100 replies posted

Hi ,

My understanding is the first line ("Cycle") denotes the full cycle count , or the period. The second lie ("duty") refers to the duty factor, or the T_on time. So, here the duty cycle should be T_on/ Cycle = 0x7530/0xEA60 = 0.5 = 50%.

Can you kindly check this and confirm? Change .u16Duty to 0x3A98 and see if you get 25% duty cycle or not?

Thanks,

Ashish

View solution in original post

0 Likes
1 Reply
Ashish
Moderator
Moderator
Moderator
25 likes received 50 solutions authored 100 replies posted

Hi ,

My understanding is the first line ("Cycle") denotes the full cycle count , or the period. The second lie ("duty") refers to the duty factor, or the T_on time. So, here the duty cycle should be T_on/ Cycle = 0x7530/0xEA60 = 0.5 = 50%.

Can you kindly check this and confirm? Change .u16Duty to 0x3A98 and see if you get 25% duty cycle or not?

Thanks,

Ashish

0 Likes