cancel
Showing results for 
Search instead for 
Did you mean: 

What timers to use for Hall and Optical sensors coming from a motor

yo3hcv
Associate II

Hello,

I'm not very familiar with M0 from ST nor with this complex timers. We want to get the speed and direction of a particulat motor that we NOT drive (just observe). The sensors are HALL and OPTICAL (not sure for moment)

For HALL interface I see that TIM3 is the perfect choice, through CH1,2,3 (for example PC6,PC7,PC8). This is correct, can we get both speed and direction?

For OPTICAL encoder seems that TMR2 can be the choice in "Encoder" mode.

1 ACCEPTED SOLUTION

Accepted Solutions

For a quad encoder, when using TIM2_CH1 and TIM2_CH2, the timer keeps the current value of pulses seen by incrementing/decrementing its counter depending on the pulse patterns. The timer is setup in encoder mode with a timer period equal to the number of pulses per rotation. Then, you can simply read TIM2->CNT (or use the HAL macro __HAL_TIM_GET_COUNTER(TIM2) ) at any time to get the current pulse count. When you have an absolute zero position indicator (index), you might look at the G4 series (and maybe more) which timers may have a 3rd input for handling the index (zero) by timer hardware.

You might also check AN4013 Application note STM32 cross-series timer overview.

View solution in original post

5 REPLIES 5
yo3hcv
Associate II

Continuation:

The problem is that I cannot see TIM2_CH1, only TIM2_CH1_ETR.

Is this ok, can we get speed and direction with this timer?

Thanks in advance,

TIM2_CH1_ETR pin internally connects the CH1 and the ETR node of the timer, so if you don't intend to use ETR, you can use it normally as CH1.

In prototyping stage, it may be a good idea to get something like a Nucleo board and do some proof-of-concept experiments with it, before you start designing your own board.

JW

KnarfB
Principal III

What MCU are talking about? How are you going to program it (register level, HAL, STM32CubeIDE)?

Note that there are many different sensors. Some are measuring hall effect but output ABI (quad encoder).

It also depends on the target rotation speed and precision requirements of your measurements.

In simple scenarios two GPIO EXTI interrupt handlers on any pair of pins may be sufficient for encoder.

yo3hcv
Associate II

Thank you for TIM2_CH1_ETR suggestion, perhaps is written in datasheet but I haven't found this yet.

We plan to use STM32F072 family, bare-metal C + ST libs (ie. no OS)

Encoders woud give 1024 ppr but not sure yet.

Of course, any EXT INT can handle but since the TMRx are so well engineered for motor control, we said to use them :)

In fact that's why we choose ST. We'd like to test some other things and that's why we like to design our own small proto board.

Because I'm not familiar with this TMR's I'd like to know if is possible to get speed and direction for both hall and optical and especially what would be the best HW wiring diagram. All in context of using TMR peripherals for lowest SW overhead.

Thank you in advance,

For a quad encoder, when using TIM2_CH1 and TIM2_CH2, the timer keeps the current value of pulses seen by incrementing/decrementing its counter depending on the pulse patterns. The timer is setup in encoder mode with a timer period equal to the number of pulses per rotation. Then, you can simply read TIM2->CNT (or use the HAL macro __HAL_TIM_GET_COUNTER(TIM2) ) at any time to get the current pulse count. When you have an absolute zero position indicator (index), you might look at the G4 series (and maybe more) which timers may have a 3rd input for handling the index (zero) by timer hardware.

You might also check AN4013 Application note STM32 cross-series timer overview.