Author Topic: Inverse of dead band observed in PWM, STM8S003F3  (Read 608 times)

0 Members and 1 Guest are viewing this topic.

Offline Vindhyachal.taknikiTopic starter

  • Frequent Contributor
  • **
  • Posts: 488
Inverse of dead band observed in PWM, STM8S003F3
« on: May 10, 2020, 02:04:48 pm »
1. I have written below code for PWM generation for STM8S003F3. Two pwm pins are used inverted with dead time.
2. But I observed this graph on CRO of two pins is this. I was expecting one pin to turn off before another turn on i.e deabband.. But reverse is happening here.
More I increase deadband it has reverse effect. What I am doing wrong here?

Code: [Select]
void all_tasks_manager(void)
{     
    uint8_t key;
    uint8_t start = 0U;

    float32_t arr,ccr,y;
    uint16_t temp1,temp2;   
   
    g_segment_display = 0U;
    SEG_1_DISABLE();
    SEG_2_DISABLE();
    segment_register_update(5);  // display ht
    g_segment_display = 1U;
   
   
   
/* TIM1 Peripheral Configuration */
    TIM1_DeInit();   

/* Time Base configuration
    TIM1_Prescaler = 0
    TIM1_CounterMode = TIM1_COUNTERMODE_UP
    TIM1_Period = 65535
    TIM1_RepetitionCounter = 0
*/
    TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 1067,0);   

   
/* Channel 1, 2 and 3 Configuration in PWM mode */
/*?
        TIM1_OCMode = TIM1_OCMODE_PWM2
    TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
    TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
    TIM1_Pulse = CCR1_Val
    TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
    TIM1_OCNPolarity = TIM1_OCNPOLARITY_LOW       
    TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
    TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
*/
    TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
               CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_RESET,
               TIM1_OCNIDLESTATE_RESET);   

/* Automatic Output enable, Break, dead time and lock configuration */
/*
    TIM1_OSSIState = TIM1_OSSISTATE_ENABLE
    TIM1_LockLevel = TIM1_LOCKLEVEL_1
    TIM1_DeadTime = 117
    TIM1_Break = TIM1_BREAK_ENABLE
    TIM1_BreakPolarity = TIM1_BREAKPOLARITY_HIGH
    TIM1_AutomaticOutput = TIM1_AUTOMATICOUTPUT_ENABLE
*/
        TIM1_BDTRConfig( TIM1_OSSISTATE_DISABLE,  TIM1_LOCKLEVEL_OFF, 5, TIM1_BREAK_ENABLE,
                   TIM1_BREAKPOLARITY_HIGH, TIM1_AUTOMATICOUTPUT_ENABLE);

/* TIM1 counter enable */
    TIM1_Cmd(ENABLE);

/* Main Output Enable */
    TIM1_CtrlPWMOutputs(DISABLE);
    TIM1_Cmd(DISABLE);


    temp1 = (uint16_t)851;
    temp2 = (uint16_t)425;
   

    TIM1->CCR1H = (uint8_t)(temp2 >> 8);
    TIM1->CCR1L = (uint8_t)(temp2);

    TIM1->ARRH = (uint8_t)(temp1 >> 8);
    TIM1->ARRL = (uint8_t)(temp1);                   
 
    TIM1_CtrlPWMOutputs(ENABLE); 
    TIM1_Cmd(ENABLE);   
 
    while(1)
    {


    }
   
}
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 8776
  • Country: fi
Re: Inverse of dead band observed in PWM, STM8S003F3
« Reply #1 on: May 10, 2020, 02:32:53 pm »
If "TIM1_OCPOLARITY_LOW" means configuring the pin polarity as "active-low", then this means everything is working as it should: the signals are "on" at 0V, "off" at 5V, and you have the proper dead bands.

If you need active-high polarity instead, change this setting.
 

Offline Vindhyachal.taknikiTopic starter

  • Frequent Contributor
  • **
  • Posts: 488
Re: Inverse of dead band observed in PWM, STM8S003F3
« Reply #2 on: May 11, 2020, 02:31:44 pm »
Meaning I have to change this:

TIM1_OCPolarity = TIM1_OCPOLARITY_LOW
TIM1_OCNPolarity = TIM1_OCNPOLARITY_LOW   

to:

TIM1_OCPolarity = TIM1_OCPOLARITY_HIGH
TIM1_OCNPolarity = TIM1_OCNPOLARITY_HIGH


Will check tomorrow in actual setup.   
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf