cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474 HAL_TIM_Encoder_Start_DMA Question

KKerr.2
Associate II

Hello STM32 MCU Community,

I was looking for clarification on the HAL_TIM_Encoder_Start_DMA function as I want to do a DMA transfer of an encoder's count register to a buffer. From the STM32G474 reference manual, I thought I would need to use another timer to trigger a DMA but was curious when I saw the HAL_TIM_Encoder_Start_DMA command. I've looked at the the description of this command and I'm confused about what parameter pData1 and pData2 represent. The descriptions are "the destination Buffer address for IC1" and I2C for pData2. Looking through the reference manual I believe these are the configurations for channel 1 and channel 2 but I wasn't completed sure. Below is some background of what I am trying to accomplish.

Background:

I am doing a prototype for an HMI project and have a Nucleo-G474, Display Module, and encoder. I have gotten the Nucleo to interface to the Display Module and am able to write to the display and see the effect. I also have been able to connect to an encoder using the TIM2 peripheral and verified that the count register is being updated as I spin the encoder. My next step was to display the value in the count register on the display but I wanted to use a different method than polling. I thought a DMA transfer from the encoder to a buffer that the display uses to update the value would be really slick but I'm not sure how to implement this. I have read the reference manual and believe I need to create an output from Tim2 which feeds into another timer which then would trigger a DMA transfer when TIM_UP occurs but I'm not clear on how to configure CUBEMX + my code to get me there. When I saw that there was a hal function for starting the encoder in DMA mode, I was hoping this may be a simplified method compared to what it sounds like I may need to do.

I'm fresh when it comes to embedded SW and would appreciate any guidance the community could provide.

Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions

There is no Update event upon direction change, only overflow/underflow (unless it's some new feature specifically on 'G4).

You can enable capture (and its respective interrupt) on any channel of the same timer while still using encoder mode.

JW

View solution in original post

4 REPLIES 4

You are overcomplicating things. A count (number, not aristocrate) in register is just as good as in memory.

JW

KKerr.2
Associate II

Hi JW,

Thanks for reviewing and your answer. I'd still like to make the process more automated than polling so I think I would need to implement an interrupt to detect a change in the encoder. Could you confirm my understanding on this as well?

  • the encoder would not generate an update when turned unless the reload value is exceeded / direction is change
  • In order to have an interrupt when the encoder is turned, I would need to configure the Encoder's timer to output a clock and feed that to another timer
  • That new timer could have a ARR of 1 (or something low) and that would fire an interrupt when the count exceeded ARR and in my interrupt subroutine I could include code to read the count register?

Thank you,

There is no Update event upon direction change, only overflow/underflow (unless it's some new feature specifically on 'G4).

You can enable capture (and its respective interrupt) on any channel of the same timer while still using encoder mode.

JW

KKerr.2
Associate II

Hi JW,

Thanks for guidance I ended up having the encoder generate an output clock to feed another timer and that timer used the encoder clock output as the trigger source for input capture. I then enabled the input capture (IC) interrupt and added the callback. I've been able to test the code and works really nicely.

Thank you