cancel
Showing results for 
Search instead for 
Did you mean: 

How to know PWM counter counts up or down? (in center aligned mode)

miracaydogan
Associate II
Posted on June 09, 2016 at 11:57

Hello masters ,

Is there any kind of way or register that PWM counter is counting up or down in center aligned mode? I need to control the system depends on up counting. So i have to check timer counts up or down . 

#discovery #output #pwm #stm32f4
12 REPLIES 12
Uwe Bonnes
Principal III
Posted on June 09, 2016 at 12:07

Read the PWM counter and store in one variable.

Read again the PWM counter until the value differs from the stored value. From both values coun can desipher the counter direction.

miracaydogan
Associate II
Posted on June 09, 2016 at 12:13

I have read but couldn't find any readable register to check  

Posted on June 09, 2016 at 14:23

Quoting from RM, ''Center-aligned mode (up/down counting)'' subchapter of any of timers' chapter (except the basic ones which don't have this mode):

In this mode, the direction bit (DIR from TIMx_CR1 register) cannot be written. It is updated

by hardware and gives the current direction of the counter.

Can this be any cleaner?

JW

Walid FTITI_O
Senior II
Posted on June 09, 2016 at 15:39

Hi Marc,

The counting direction of the counter is indicated by the DIR bit-fields in TIMx-CR1 register.

-Hannibal-

miracaydogan
Associate II
Posted on June 10, 2016 at 08:22

Thank you all ! But i cant read that register to control my sytstem . Do you know how is it?

Posted on June 10, 2016 at 08:56

> But i cant read that register

Why?

JW

miracaydogan
Associate II
Posted on June 10, 2016 at 09:20

I dont know how to read the register :\

Posted on June 10, 2016 at 10:21

How did you program the timer, then?

If you use some of the ''libraries'' (SPL or Cube), resort to the documentation of that ''library''.

JW

[EDIT] if you use Cube, then look at macro
ankushkhare89
Associate II
Posted on June 10, 2016 at 11:29

By having a closer look at the registers.

Which IDE are you using ?