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
miracaydogan
Associate II
Posted on June 13, 2016 at 07:20

I use True Studio and just dont know

reading syntax

of the stm32f4 standart peripheral library . I mean how to write a code to read a register :\ 

Posted on June 13, 2016 at 11:03

SPL does not appear to have a dedicated function or macro for this particular purpose, but I don't use SPL.

However, have a look into [SPL's directory]\Libraries\CMSIS\Device\ST\STM32xxxx directory, there are stm32yyyyxx.h headers there, which contain everything you need for direct register access: defines for addresses of every peripheral, struct typedefs for registers of that peripheral, and defines for bits/fields within those registers. So, #include the appropriate stm32yyyyxx.h header (you most probably have that included already, directly or indirectly), and then you can write something like

if (TIM1->CR1 & TIM_CR1_DIR) {

  // counting down

} else {

  // counting up

}

JW
miracaydogan
Associate II
Posted on June 14, 2016 at 09:46

Thank you all, especially Jan, last code helped me to solve the problem, I have started project with SPL . So i cant change it anymore . maybe i can try HAL Library at next project .