cancel
Showing results for 
Search instead for 
Did you mean: 

SOLVED!!! One Pulse on TIM15 on STM32F072/STM32072B-EVAL

rgrimes
Associate II
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!
6 REPLIES 6
Posted on September 04, 2014 at 04:30

Looks reasonable, but try clearing/setting all the parameters in the timebase. The repetition count is supported by TIM15, but not TIM2/TIM3

/* 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_TimeBaseStructure.TIM_RepetitionCounter = 0; // Used on TIM15
TIM_TimeBaseInit(TIM15, &TIM_TimeBaseStructure);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rgrimes
Associate II
Posted on September 04, 2014 at 14:22

Good catch, but still, no joy.

Seems there are at least three possible problems:

  1. Pins not set up correctly
  2. TIM15 is not getting triggered
  3. TIM15 is not generating the pulse correctly
I'm certain (looking with logic analyzer) that the trigger signal from TIM3 is being delivered to the correct pin, and it works.  Is there some way to tell whether TIM15 is getting triggered correctly?  Is there a way to tell whether it would generate a pulse correctly?

I have attempted to set the ''trigger generation'' bit TG in EGR like this after the TIM15 is set up:

    TIM15->EGR = 0x40;

but I don't see anything on the output.  While I go about triple-checking the pin setup, am I correct in thinking this should cause one pulse to be emitted?

Thanks!

rgrimes
Associate II
Posted on September 04, 2014 at 20:21

Did a bunch of double-checking, and I still cannot get any output. Checked connections, etc. Checked another board, nothing.

I recreated the example project, and it works fine using TIM2. Then, changed it to TIM15, and broken.

Is it simply that TIM15 won't work that way???

For anyone interested in taking a whack at it, attached is the project.

Ideas?

________________

Attachments :

One_Pulse_TIM2_TIM15.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzwQ&d=%2Fa%2F0X0000000bRI%2Fut47qYfZ.QW59Xza28BXillR.hE2ajpRXH__lBREbwI&asPdf=false
Posted on September 05, 2014 at 09:11

Try to make a ''conventional'' PWM working first on TIM15, then proceed to the triggered version.

Also, note, that TIM15 has the ''break'' unit at the outputs, i.e. the MOE bit in TIM15_BDTR has to be set (similar gotcha as with TIM1/TIM8 on the older STM32 models).

If everything fails, read out and post content of TIM15 registers.

JW
rgrimes
Associate II
Posted on September 05, 2014 at 14:12

Hey!

  TIM15->BDTR |= TIM_BDTR_MOE;

Works!

Thank you, thank you, thank you!!!

FWIW - no where in the reference manual did I see anything about this requirement; indeed, if anything, it seemed only to be applicable if the break feature is being used and enabled - which isn't my intent.  Before writing this, though, I did a quick search and found ''Table 60 - Output control bits for complementary OCx and OCxN channels with break feature'' in RM0091, which states that when MOE is 0, ''Output Disabled (not driven by the timer)''.  Thank the powers that be for the Internet, these forums, and mostly, people like waclawek.jan, clive1, and all the others that really make things run!

Posted on September 05, 2014 at 14:55

Glad it works.

Note, that the code examples in Appendix A in RM0091 do mention it. They stem from the Snippets, which is IMO way more useful than the ''Standard Library'' crap perpetuated by the ''Cube'' crap.

JW