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 24, 2014 at 13:29

The PWM Input Capture mode typically uses two channels and resets the counter to make measurements of duty and period.

You can use the straight-up Input Capture mode, and configure each channel to latch it's own value (instead of tying them together). Provided the speed isn't too high you can measure duty/period of both channels in software. Not sure if TIM9/TIM12 support both edges.

The diagrams for TIM9/TIM12 are awful, as I recall the bits to select the trigger source and other muxes are totally missing. At least as described at the register level, and not useable in reality.
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 17:10

Hiclive,  the TIM9 supports both edges, though ,  withcapture input mode I can only get one counter, as duty or period, butnot both, isn't it?  In my project I am not sure I can't makeassumption on the signal input  period  and measure a dutypulse is not enought to compute the PWM value.    

Aboutthe 

waclawek.jan

suggestion: is not simple matter to switch between channels

toget both the input PWM : if I do it automatically in ISR, and onechannel suddenly stop to supply

PWMsignal, the switch is stuck on this 'unavailable' signal waiting forISR call...

Ishould use a timer-driven to switch betwen channels measure but Ishould make

assumptinon the minimum frequency supplied to get at least 1 measure...

Not simple to overcome this 'nearly' independent channels...

Posted on April 24, 2014 at 17:23

Each timer has a single counting element (time base), there is a latch for each channel (time stamp).

You can time-stamp the events, and compute delta measurements, I'm not sure how this gets to be materially different from what PWM Input mode achieves with a little more software effort, and interrupt loading. ie if you can use PWM Input Capture mode now for one signal, you can use Input Capture for two signals.

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 18:22

Hi,

related to your suggestion, to use two independent capture channel,   when you talk about  to get the duty and period for each channel, do you mean I have to set the channel for both edges and read the GPIO pin to set the appropriate counter (pos/neg)  during ISR?   Are there different procedure to get  the PWM value  ? could you give me some more details?  

thank you

Posted on April 24, 2014 at 19:24

Service both edges, read the time-stamp in the CCRx, check the GPIO, and use that and historic measurements from prior service of the channel. Compute rising edge to rising edge period, compute rising edge to falling edge.

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 30, 2014 at 12:18

Hiall,   I have followed the useful suggestion and I have donesome work and test

tobuild a input capture, both edges,  to realize the PWM inputmeasurement, without

triggerinput.

Ifirst try with each single edge, rise and fall,  to test thetimer hardware behaviour 

onthe configuration used :  I could get the period correctly,without Overcapture error, 

asexpected. 

But,When I have changed  only the CCER register to select bothedges,  I couldn't be able 

toget properly  the falling edge ISR  ( I think that this wasthe failure I experienced) , because 

Igot Overcapture errors and the falling edge counter was not in therange expected  .

Istill got rise edge counter correctly, because the periodmeasurement, based on rise edges, was OK . 

I'llgive you the time stamp value of TIM9 register as shown by my KEILuVISION v5.x  

peripheraldebugging view: 

SMCR = 0x00

CR1 =      0x81

DIER = 0x02

CCRM1 = 0x31

EGR = 0x00

CCER = 0x0B

maybe I missed something ...  ( I hope )

HAS ANYONE EVER USED TIM9/12 IN INPUT CAPTURE FOR BOTH EDGES?..

any suggestion will be appreciated

thanks

philsax
Associate II
Posted on April 30, 2014 at 12:45

I make some excuse on the text 'shrinked' above:  I have done cut/paste of the text 

from an external editor, other than the  forum editor, because  some time 

the page reports errors in sending the form and and crashes, loosing the text

filled up .. 

bye

Posted on April 30, 2014 at 12:51

The falling edge is apparently too close to the rising edge.

This is the caveat of the single-channel measurement: the edges can't be too close to each other. Clive has warned you in https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/DispForm.aspx?ID=41119&RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fstm32f40x%20discovery%20TIM9%20and%20TIM12%20PWM%20input%20capture : ''

Provided the speed isn't too high

...''

Don't have unrealistic expectations and if you can't use either this nor the ''one-at-a-time'' method, you have to rewire the board.

JW

philsax
Associate II
Posted on April 30, 2014 at 16:17

Hi,

I am testing with a  50%  duty cycle   and a period of 500uSec,  with a clock timer with

no prescaler value.    I  don't think the  two edges  are too close...  but maybe I don't understand the warning you gave me.

Now, I am  toggling  rise to fall edge and vice-versa, during ISR .  I have no Overcapture, the ISR get the CCRx   counter value and saves it  for PWM computation, but the falling edge seem to get a CCRx  value not updated...   I am working on this issue.    

bye

philsax
Associate II
Posted on May 10, 2014 at 09:55

Hi,

I made some further test on switching the input channel,

(using TIM1 to trig the switching time). I could measure the

two PWM channel, but, when I supply both inputs I was only able

to get only one correct channel : the start-time configuration one.

The other was instable: if I disconnect the other input signal,

the measure was correct.

As info, when I got the previous result, among the TIM pwm

channel configuration,  I add a full peripheral pin

reconfiguration:  set the peripheral input pin unused as

general purpose output, no-pullup-pulldown, open drain...  

No useful results.

I tried also to insert a peripheral reset

between input channel reconfiguration, but I was no more able

to get valid measure for any channels.

About reset: What is the correct procedure to reset a TIM peripheral?

(I tried to set/reset even with delay in between ) the  I mean

the time and sequence to apply and remove the reset signal

to the peripheral reset register, and if there are further  

Things to do to put the peripheral in start-up condition and

fully reconfigurable...

Do you ever experiment peripheral reset and reconfiguration issue?

thank you