cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder Z pulse Problem?

AAbde.7
Associate

Hello Everyone!

Wanted to ask because I have a problem with getting the z pulse, or index channel to work on my encoder. I am using an encoder on a motor, and a nucleo board, and programming everything on stm32cubeide.

What is the correct way of doing this?

What I did:

- first I got the channels a and b to work, so now i get the counter value

code in main.c:

volatile uint32_t counter = 0;

volatile int16_t count = 0;

volatile int16_t position = 0;

//int16_t index = 0;

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

   counter = __HAL_TIM_GET_COUNTER(htim);

   count = (int16_t)counter;

   position = count/4;

}

int main(void)

{

HAL_TIM_Encoder_Start_IT(&htim1,TIM_CHANNEL_ALL);

 while (1)

 {

    void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);

 }

- then i activated an interrupt

- then went to the stm32f7xx_it file and added this:

volatile int16_t counter;

 if (HAL_GPIO_ReadPin(GPIOE, 13) == GPIO_PIN_SET) {counter = 0;}

Is this how to do that?

4 REPLIES 4
LCE
Principal

If you set up TIM1-> SMCR correctly to the wanted encoder mode (and everything else), you could actually:

a) simply read TIM1->CNT when you need the position

b) reset TIM1->CNT = 0 in the Z-pulse ISR

I don't see the need for callback stuff.

Unfortunately the timer cannot handle the Z-pulse as a 3rd input to reset the timer's counter - or am I wrong?

AAbde.7
Associate

wait so it cannot handle it? What would be the way to do this then?

The way you do it, with an interrupt.

I just mean that the STM32 timer peripheral has no option for this 3rd encoder input / Z pulse.

Timers in STM32G4xx do have an Index Input option for encoder mode, and generally feature many extended features related to encoders.

JW