cancel
Showing results for 
Search instead for 
Did you mean: 

generate one pulse

kong0073
Associate II
Posted on July 08, 2011 at 06:18

I am trying to generate a single pulse using the TIM_SelectOnePulseMode() function in STM32f10x_tim.c source file. But I am not able to get the pulse. why?

I am using TIM4 CH2... Any advice?

int main(void)

{

    TIM_Cmd(TIM4, DISABLE);

    RCC_Configuration();

    GPIO_Configuration();

    PrescalerValue = (SystemCoreClock / 24000000) - 1;

   

    TIM_TimeBaseStructure.TIM_Period = 65535

    TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

    TIM_OCInitStructure.TIM_Pulse = 16383

    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OC2Init(TIM4, &TIM_OCInitStructure);

    TIM_Cmd(TIM4, ENABLE);

    TIM_SelectOnePulseMode(TIM4, TIM_OPMode_Repetitive);

    return 0;

}

void RCC_Configuration(void)

{

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);

    RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE);

}

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

}

#timer-one-shot #one-pulse #stm32 #tim4
16 REPLIES 16
rosarium
Associate II
Posted on July 11, 2011 at 10:10

why are you doing remapping for TIM2 ch1.

Remove the following line from GPIO_Configuration.

GPIO_PinRemapConfig(GPIO_FullRemap_TIM2, ENABLE);

Posted on July 11, 2011 at 14:27

ok, now I have changed to TIM2 CH1 (PA0)  which coincides with the wakeup.

 

 

I have enabled my AFIO and re-mapped my TIM2 CH1, but I am still not getting it. Why?

 

You're moving the goal posts, and not reading the documentation.

Please refer to the part documentation to understand which Pins and Peripheral outputs require default or remapped settings to get the signal you want. As PA0 supports TIM2_CH1 as a default, why would this need remapping.

PD13 requires remapping for TIM4_CH2 to be used as an output. By default it's coming out of PB7

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00251732.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lv9
Associate II
Posted on May 29, 2012 at 07:06

Let me bring this post back to live, please. Using the STM32VLDISCOVERY, this post was just what i needed - to automatically generate a pulse when an input pulse arrives, and to control delay and pulse duration. The code and the sample file supplied here don't work for me, and I can't seem to find out why. I've soldered a wire to the 3.3v pin of the discovery board, touching the input pin with it, and see nothing on the output pin with a scope. Any help, guys? Thanks!

alexcourtemanche19
Associate
Posted on July 25, 2012 at 22:14

I also would like to know the answer to this problem. This is exactly what I need to do and I can't find a proper solution anywhere.

Posted on July 25, 2012 at 22:49

STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\TIM\OnePulse

This example shows how to use the TIM peripheral to generate a One pulse Mode
after a Rising edge of an external signal is received in Timer Input pin.
TIM2CLK = SystemCoreClock, we want to get TIM2 counter clock at 24 MHz:
- Prescaler = (TIM2CLK / TIM2 counter clock) - 1
SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
and Connectivity line devices and to 24 MHz for Low-Density Value line,
Medium-Density Value line and High-Density devices.
The Autoreload value is 65535 (TIM4->ARR), so the maximum frequency value to
trigger the TIM4 input is 24000000/65535 = 300 Hz.
The TIM4 is configured as follows:
The One Pulse mode is used, the external signal is connected to TIM4 CH2 pin (PB.07),
the rising edge is used as active edge, the One Pulse signal is output
on TIM4_CH1 (PB.06).
The TIM_Pulse defines the delay value, the delay value is fixed to:
delay = CCR1/TIM4 counter clock = 16383 / 24000000 = 66 us.
The (TIM_Period - TIM_Pulse) defines the One Pulse value, the pulse value is fixed to:
One Pulse value = (TIM_Period - TIM_Pulse)/TIM4 counter clock
= (65535 - 16383) / 24000000 = 2.048 ms.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
irose
Associate
Posted on May 01, 2013 at 20:32

I am not sure if this directly relates to his particular issue but I did notice that there seems to be a missing test condition in the TIM_SelectOnePulseMode function.

The code in the library looked like this.

void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode)

{

  /* Check the parameters */

  assert_param(IS_TIM_ALL_PERIPH(TIMx));

  assert_param(IS_TIM_OPM_MODE(TIM_OPMode));

  /* Reset the OPM Bit */

  TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_OPM);

  /* Configure the OPM Mode */

  TIMx->CR1 |= TIM_OPMode;

}

This function clears then sets the mode. Correct me if i am wrong, but shouldn't this look more like this.

void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode)

{

  /* Check the parameters */

  assert_param(IS_TIM_ALL_PERIPH(TIMx));

  assert_param(IS_TIM_OPM_MODE(TIM_OPMode));

  if(TIM_OPMode != ENABLE)

  {

  /* Reset the OPM Bit */

  TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_OPM);

  }

  else

  {

/* Configure the OPM Mode */

  TIMx->CR1 |= TIM_CR1_OPM;

  }

  }

Posted on May 01, 2013 at 21:40

TIM_OPMode can be zero.

The clearing, then setting (or not) OPM, may suit the TIM's internal state machine, it's documented to clear the CEN bit. Your code may not have this side effect depending on the initial condition.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..