cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f40x discovery TIM9 and TIM12 PWM input capture

philsax
Associate II
Posted on April 23, 2014 at 15:33

hi all,   I'm new in the forum and I am experiencing a problem of ISR , which doesn't  happen for TIM12 while, with same ch1 configuration register and same pwm signal input,  set the ISR calling for TIM9, as expected.  I am quite surprised of this behaviour and I have checked the TIM9 and TIM12 register configuration  but I cant found any difference .  I am about to check if there is any errata which may affect the TIM12 functionality: not yet done at the moment.  do you have any suggestion?  I am new to stm32 device and maybe someone can give me some tips on what to check and debug(keil V5)  .  

22 REPLIES 22
Posted on April 23, 2014 at 16:05

STM32F401C ?

Does TIM12 have the functionality required? Some of the timers are not full functioned, and the 401C has a subset of the 407
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
philsax
Associate II
Posted on April 23, 2014 at 16:36

Is the (ST )  stm32f407VG,  the discovery board.   

some code...

===============================================================

/* enable the clock for the two timers */

.......

    else if (p_TimNum == TIM9)

    {

        RCC -> APB2ENR |= (1UL << 16);                        /* Enable clock on timer 9*/

    }

    else if (p_TimNum == TIM12)

    {

        RCC -> APB1ENR |= (1UL << 6);   /* Enable clock on timer 12 */

   }

......

......

/ *  the GPIO PE5 PWM input  set up for TIM9  */

  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;                                /* Enable GPIOE clock  */

                GPIOE -> MODER |= ((uint32_t)(2UL << 10));                          /* set pin PE_5 as alternate function */                            

                GPIOE -> OTYPER &= ~((uint32_t)(1UL << 5));                         /* set pin PE_5 push-pull output */

               GPIOE -> OSPEEDR |= ((uint32_t)(3UL << 10));                        /* set pin PE_5 high speed */

                GPIOE -> PUPDR |= ((uint32_t)(2UL << 10));                          /* set pin PE_5 pull-up */

                GPIOE -> AFR[0] |= ((uint32_t)(3UL << 20));                         /* set AF3, timer9 */

/* the PE6 GPIO PWM input set up for TIM12 */                RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN;                               /* Enable GPIOE clock  */

                GPIOE -> MODER |= ((uint32_t)(2UL << 12));                     /* set pin PE_6 as alternate function */                            

                GPIOE -> OTYPER &= ~((uint32_t)(1UL << 6));                     /* set pin PE_6 push-pull output */

                GPIOE -> OSPEEDR |= ((uint32_t)(3UL << 12));                     /* set pin PE_6 high speed */

                GPIOE -> PUPDR |= ((uint32_t)(2UL << 12));                     /* set pin PE_6 pull-up */

                GPIOE -> AFR[0] |= ((uint32_t)(9UL << 24));                     /* set alternate function AF9, timer12 */

==============================================================

I am now debugging and when supply the PWM input to TIM9 I can view the CCR1 and CCR2 register with a valid count: when I do it in turn for TIM12 I see CCR1 and

CCR2 stuck at zero...  A part from ISR results, I should view the TIM12 counter running..  

If needed I'll give further details.

Thank you Clive.

Posted on April 23, 2014 at 18:02

There is no relationship between PE6 and TIM12.

You'd need to use PB14 (TIM12_CH1) or PB14 (TIM12_CH2)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
philsax
Associate II
Posted on April 23, 2014 at 18:30

many Thanks Clive,  

I was not aware I couldn't use ANY  gpio pin  as alternate function...In the meanwhile  I have done some test and new version, with PB14, as you suggested.

Thetimer 12  issues only the first ISR request, after startup,  andthen no more ISR are given.   The CCR1 and CCR2   are setwith some value , though not  the one expected as the same TIM9reg's counts,  supplied with the same signal...

Thank you , I think I'm now on the right track,   

Posted on April 23, 2014 at 18:40

I was not aware I couldn't use ANY  gpio pin  as alternate function...

The pin multiplexing provides some flexibility, but isn't a cross-bar switch implementation.

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
philsax
Associate II
Posted on April 24, 2014 at 10:33

Hi,

Iam stil

l

working on PWM input capture,

doingsome SW

debugand

test

a

on

discovery,

STM32F407VG

(lqfp-

100

pin package).

Inthe target project

,I need

ed

Two inde

pendentinput

triggersource, which,

Inthe CPU

pcb

I have realized,

I mapped

toGPIO_PE5 and GPIO_PE6 that c

ould

be routed to TIM9 as alternate

functionpin configuration.

Ihave mapped them both to TIM9 because, a

smentioned

bystm32f40x datasheet :

“…

.whereasTIM9 and TIM12 have

twoindependent

channelsfor input

capture/outputcompare, PWM or one-pulse mode output.�

Butthe two channels, as I realized later, have no a full set ofindependent

register:as there is only ONE TIM9_SMCR, the

'slavemode configuration register', we are allowed to

chooseonly ONE Trigger source selection among the available

sources

as shown below :

–

------------------------

(

Bits6:4

TS:

Triggerselection

Thisbitfield selects the trigger input to be used to synchronize thecounter.

000:Internal Trigger 0 (ITR0)

001:Internal Trigger 1 (ITR1)

010:Internal Trigger 2 (ITR2)

011:Internal Trigger 3 (ITR3)

100:TI1 Edge Detector (TI1F_ED)

101:Filtered Timer Input 1 (TI1FP1)

110:Filtered Timer Input 2 (TI2FP2)

111:Reserved.

–

-----------------------

Unfortunately,I can't map GPIO_PE6 to TIM12 or a different avalable timer

onmy STM32F407IGT6 (lqfp-176 pin package) for my project targetdevice.

Isthere a alternate method or configuration that can allow me torealize two

PWMinput measure on the above mentioned GPIO? I hope to

avoidre-enginering the CPU pcb..

Posted on April 24, 2014 at 10:47

For PWM capturing, you don't need the input signal to be a *trigger*, you only need it to be a source for two capture/compare units.

Why do you want the input signal to be a *trigger* (i.e. to route it through the multiplexer controlled by

TIM9_SMCR

.TS)?

JW

philsax
Associate II
Posted on April 24, 2014 at 12:41

Whythen , on reference manual, chapt. 19.3.6, about

inputPWM capture, among the register configuration, in the point 5 and 6

ofthe suggested procedure, they suggest to select TS ?

19.3.6PWM input mode (only for TIM9/12)

…

..

5.Select the valid trigger input: write the TS bits to ‘101’ in theTIMx_SMCR register

(TI1FP1selected).

6.Configure the slave mode controller in reset mode: write the SMS bitsto ‘100’ in the

TIMx_SMCRregister.

…

.

Howshould I set an alternate configuration to the actual up and

running( only ch1 on TIM9 ) TS = 101 ? if I leave the

TS= 000 results TIM4 as master trigger of my slave timer... how

canI 'unselect' the trigger input? Is it possible?

Basedon datasheet example and on register

description,I am not sure on how to configure

SMCRfor two channel PWM input capture.

Posted on April 24, 2014 at 13:20

Oh, I see. The timer chapters in the manual are written rather badly, instead of concisely explaining the structure and internal working of constituent modules, most of the subchapters contain examples which should rather go to appnote(s), and even those are not very instructive.

Using one of the edges to reset the counter results in convenient, 0-based values to be captured; but the same can be achieved by using a free-running timer and performing some basic arithmetics between the two captured values.

An additional ''merit'' in using the reset/slave is that it resets the prescaler, but that matters only if the prescaler is different from zero and the resulting benefit is dubious given the prescaler's current value is not captured.

But, back to your problem, can't you simply capture the two PWM values not simultaneously, but one at a time, on the same TIM9, by reconfiguring it to capture first from CH1, then from CH2, and repeat?

JW