cancel
Showing results for 
Search instead for 
Did you mean: 

how to get complementary output at timer CH1 and CH1N ?

mehmet.karakaya
Associate III
Posted on October 16, 2012 at 18:50

hello forum,

 

 

the processor is STM32F103

 

 

I have an H bridge for DC motor

 

I want complementary outputs of CH1 and CH1N

 

I setup the timer 1 as following

 

  TIM_TimeBaseStructure.TIM_Prescaler = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseStructure.TIM_Period = 7200;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;

  TIM_OCInitStructure.TIM_Pulse = 2000;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;

  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;

  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;

  TIM_OC1Init(TIM1, &TIM_OCInitStructure);

  TIM_OC2Init(TIM1, &TIM_OCInitStructure);

  TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;

  TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;

  TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;

  TIM_BDTRInitStructure.TIM_DeadTime = 0xCA;

  TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;

  TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;

  TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;

  TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);

then I call below functions to start PWM

 

however I cant get complemantary output at CH1 and CH1N

 

I get the same polarity of both CH1 and CH1N ( CH1N is the same as CH1 )

 

 

how can I get complementary outputs ? 

 

thank you

    TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);

    TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);

    TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);

    TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_ForcedAction_Active);

    TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);

    TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);

#tim-stepper-h-bridge #timer-dead-time #timer-complementary-outputs
4 REPLIES 4
Posted on October 16, 2012 at 19:15

7200-1 surely?

This is how ST does it in their examples

/* Channel 1, 2 and 3 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = Channel1Pulse;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Channel3Pulse;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mehmet.karakaya
Associate III
Posted on October 17, 2012 at 22:08

0690X00000602mfQAA.jpg

hello thank for the answer

 

 

I changed the initializing code according to your example

 

 

and I call folowing functions to start PWM

 

TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM2);

TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);

TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);

yes I got complementary signals at CH1 and CH1N

 

however dead time generator insert dead time at wrong places

 

I draw  the osciloscope image above

 

as you can see ON times of mosfets collide ( the dark lines )

 

I want dead times like as shown in the dashed lines

 

 

what I must change in the code ?

Posted on October 17, 2012 at 22:52

PWM motor control isn't my thing, but perhaps

TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on October 18, 2012 at 15:54

Because you have OCxN active low the dead time won't work.  During the deadtime gap both signals are driven to the inactive level....low for OCx and high for OCxN, so the H-Bridge stays on.  OCx and OCxN polarity should match when driving a bridge, unless you have an inverter on one side.

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;

should be:

TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;

Jack Peacock