cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100RB TIM super-strange behaviour

eltar
Associate III
Posted on August 21, 2012 at 22:59

I'm hammering my table with my head the whole evening. I can't get the simpliest thing to work. Ok, here's the problem: I need TIM1 to gate TIM3. I've got TIM1 configured as a single-shot master with either TIM_TRGOSource_Enable orTIM_TRGOSource_OC1Ref signal sent to slaves. Then I have TIM3 set as a slave PWM generator. I want TIM3 to immidiately start firing pulses. Pictures will tell the better story:

0690X00000602PbQAI.bmp The blue waveform is TIM1, yellow is TIM3. Notice that TIM3 is now acting withTIM_OCPolarity_High and in PWM1 mode. _

Absolutely the same picture

_ is whenTIM_OCPolarity_Low and PWM2 mode. And this is crazy, because notice that yellow is HIGH _before_ the gate comes to the scene. The same picture with different scale: 0690X00000602PgQAI.bmp TIM3_CH1 goes high immediately after callingTIM_OC1Init(TIM3, &TIM_OCInitStructure); It is the combination of polarity and PWM mode that defines if the output will be HIGH or LOW. Timer have not even started counting, and the output goes high. I believe this is a very bad bug here.Any comments/advices?


#include ''stm32f10x_tim.h''

#include ''stm32f10x_rcc.h''

#include ''stm32f10x_gpio.h''


TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_OCInitTypeDef TIM_OCInitStructure;

TIM_BDTRInitTypeDef TIM_BDTRInitStructure;


void
RCC_Configuration(
void
);

void
GPIO_Configuration(
void
);


void
tim3ch3onePulse()

{

/*!< At this stage the microcontroller clock setting is already configured,

this is done through SystemInit() function which is called from startup

file (startup_stm32f10x_xx.s) before to branch to application main.

To reconfigure the default setting of SystemInit() function, refer to

system_stm32f10x.c file

*/


/* System Clocks Configuration */

RCC_Configuration();


/* GPIO Configuration */

GPIO_Configuration();


/* TIM3 Peripheral Configuration ----------------------------------------*/


/* TIM3 works in Gated mode. */


TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated);

TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0);


/* TIM3 Slave Configuration: PWM1 Mode */

TIM_TimeBaseStructure.TIM_Prescaler = 23;

TIM_TimeBaseStructure.TIM_Period = 50;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;


TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);



TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OCInitStructure.TIM_Pulse = 5;


TIM_OC1Init(TIM3, &TIM_OCInitStructure);


/* TIM1 Peripheral Configuration ----------------------------------------*/

/* Time Base configuration */

TIM_TimeBaseStructure.TIM_Prescaler = 23;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseStructure.TIM_Period = 401;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;


TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);


/* Channel 1 Configuration in PWM mode */

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;

TIM_OCInitStructure.TIM_Pulse = 300;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;

TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;

TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;


TIM_OC1Init(TIM1, &TIM_OCInitStructure);


/* Master Mode selection */

TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Enable);


/* Select the Master Slave Mode */

TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);


TIM_CtrlPWMOutputs(TIM1, ENABLE);


TIM_SelectOnePulseMode(TIM1, TIM_OPMode_Single);


/* TIM enable counter */



/* Main Output Enable */

/* TIM1 counter enable */

TIM_Cmd(TIM1, ENABLE);

TIM_Cmd(TIM3, ENABLE);




while
(1)

{}

}


void
GPIO_Configuration(
void
)

{

GPIO_InitTypeDef GPIO_InitStructure;



/* GPIOA Configuration: TIM1 Channel1 and TIM3 Channel1 as alternate function push-pull */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_8;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_ResetBits(GPIOA, GPIO_Pin_6);

}


void
RCC_Configuration(
void
)

{

/* TIM1, GPIOA and GPIOB clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOA |

RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);


/* TIM3 and TIM4 clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

}

#tim #stm32f100 #timer-gated
0 REPLIES 0