Question
SOLVED!!! One Pulse on TIM15 on STM32F072/STM32072B-EVAL
Posted on September 03, 2014 at 23:55
Hi,
I'm trying to modify the standard One Pulse example to use TIM15 to generate a delay, programmable width pulse, triggered by an external input. For the external input, I am using TIM3 routed to the appropriate pin (PA3) which is TIM15_CH2. I am looking at TIM15_CH1. The TIM3 output is working, generating an ~45 Hz trigger signal. However, I cannot get anything on the output of TIM15_CH1 (on PA2). Here is my code for TIM15:
static void TIM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* TIM15 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);
/* GPIOA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* TIM15_CH1 pin (PA.02) and TIM15_CH2 pin (PA.03) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM pins to AF0 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_0);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_0);
/* --------------------------------------------------------------------------
TIM15 configuration: One Pulse mode
The external signal is connected to TIM15_CH2 pin (PA03),
The Rising edge is used as active edge,
The One Pulse signal is output on TIM15_CH1 pin (PA02)
The TIM_Pulse defines the delay value
The (TIM_Period - TIM_Pulse) defines the One Pulse value.
--------------------------------------------------------------------------- */
/* Compute the prescaler value */
PrescalerValue = (uint16_t) ((SystemCoreClock ) / 24000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);
/* TIM15 PWM2 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 16383;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM15, &TIM_OCInitStructure);
/* TIM configuration in Input Capture Mode */
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM15, &TIM_ICInitStructure);
/* One Pulse Mode selection */
TIM_SelectOnePulseMode(TIM15, TIM_OPMode_Single);
/* Input Trigger selection */
TIM_SelectInputTrigger(TIM15, TIM_TS_TI2FP2);
/* Slave Mode selection: Trigger Mode */
TIM_SelectSlaveMode(TIM15, TIM_SlaveMode_Trigger);
TIM_Cmd(TIM15, ENABLE);
}
It seems I am missing something - probably trivial! Any ideas?
Thanks!