cancel
Showing results for 
Search instead for 
Did you mean: 

Quadrature encoders on STM32L4

Abdelmalek BELLOULA
Associate III
Posted on December 24, 2016 at 22:50

Hi,

I use a Stm32 Nucleo L476 board and I am trying to interface a quadrature encoder to TIM4 in the Encoder Mode using STM Cube

My problem is that i don't know how to read the value of the timer using the functions of the TIM HAL module driver (stm32l4xx_hal_tim.c)  Thank you

#encoder-mode #stm32l4xx #quadrature-encoders
4 REPLIES 4
Nesrine M_O
Lead II
Posted on December 26, 2016 at 14:11

Hi

mika.belloula

‌,

'My problem is that i don't know how to read the value of the timer using the functions of the TIM HAL module driver (stm32l4xx_hal_tim.c)'

To have idea about how to use the timer HAL driver,I recommend you to start with timer examples under the STM32L4 firmware package :

STM32Cube_FW_L4_V1.6.0\Projects\STM32L476RG-Nucleo\Examples\TIM

-Nesrine-

Abdelmalek BELLOULA
Associate III
Posted on December 26, 2016 at 19:34

Hello

Thank you Nesrine- for your advice

I saw the examples of the timer, unfortunately for me l did not the example of the timer in quadrature mode

Maybe I have misplaced the problem

I would just like to read the value of the counter using the functions of the HAL library 'stm32l4xx_hal_tim.c' but I do not find a function that allows me this in this mode of operation.

If not is what I have to do by counting the number of interuption generated by the signals coming from the sensor or should I use the HAL_TIM_ReadCapturedValue function, in this case I have two channels for the timer

Sorry for my english

thank you

Posted on December 26, 2016 at 20:39

The timer only has a single counting element, TIM4->CNT or TIM_GetCounter(htim->Instance)

The channel compare latches TIM4->CCR1 and CCR2 do not play a role.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 26, 2016 at 22:54

Hi,

Thank you so much , Clive One

Now I understood that my real problem is that I misunderstood the notation ♯ define __HAL_TIM_GET_COUNTER (__ HANDLE__) \

   

((__HANDLE __) -> Instance-> CNT) in the file stm32l4xx_hal_tim.h

Thank you once again