Inverse of dead band observed in PWM, STM8S003F3

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
560
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:
Code:
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)
    {


    }
    
}


x.jpeg
 

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
560
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.
 
Top