[Solved] Motor’s Built-in Encoder Home Indicator Doesn’t Seem to Work

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
I am playing around with an optical encoder built into a linear drive motor. There is a wire that is described as "Home indicator, TTL, Active high".

I have connected it to PA4 on my Nucleo-F446RE (STM32), have set it to "GPIO_input" and have set the GPIO to "Pull down". I am trying to read the pin to check when it is high to see where "home" is, but am not getting any results. I assume it is high whenever the code is restarted, so whichever position it is in when the code starts, the home position is there. Is that assumption by any chance incorrect?

I am using a global interrupt timer, and have a simple if statement that changes a variable when the home position is activated. This code is put into the timer interrupt callback timer:

C:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
    counter = __HAL_TIM_GET_COUNTER(htim);
    count = counter;

    if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == GPIO_PIN_SET)
        {
          home_indicator_state = 1;
          HAL_GPIO_WritePin(LED_GPIO_PORT, LED_PIN, GPIO_PIN_SET);
        }


}
 

Ya’akov

Joined Jan 27, 2019
9,165
Welcome to AAC.

You don’t provide any make/model information for the motor so I can’t look for a datasheet but think logically for a moment. Can the motor sense that you have started your program? If the motor produces the HOME signal, how can the program determine where the motor will decide is home?

Home is going to be some particular position of the motor and you probably have to move the motor slowly until it finds that spot to calibrate it. It is probably on one end of the run, but it could be something else. Still, you will have to seek until you find it. Than the program will know it is in an absolute position of HOME and can calibrate its idea of where the motor is.

But the way, “actively high” doesn’t make any sense. Active High means that when the condition is true, the logic level is high, that is, when it is it is high when it is active. Think of it this way, an active low output would be at a logical low when it was true, so active means the condition indicated is true regardless of the logic level. So, never -ly, just active.
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
Welcome to AAC.

You don’t provide any make/model information for the motor so I can’t look for a datasheet but think logically for a moment. Can the motor sense that you have started your program? If the motor produces the HOME signal, how can the program determine where the motor will decide is home?

Home is going to be some particular position of the motor and you probably have to move the motor slowly until it finds that spot to calibrate it. It is probably on one end of the run, but it could be something else. Still, you will have to seek until you find it. Than the program will know it is in an absolute position of HOME and can calibrate its idea of where the motor is.

But the way, “actively high” doesn’t make any sense. Active High means that when the condition is true, the logic level is high, that is, when it is it is high when it is active. Think of it this way, an active low output would be at a logical low when it was true, so active means the condition indicated is true regardless of the logic level. So, never -ly, just active.
Hi Ya'akov,

Thank you for you reply.

My apologies, the linear drive motor is the SDLM-025-095-01-05 (Link to datasheet). Maybe I misworded my thoughts, I believe that when the motor is connected to source, then the home position is whatever the position is at that point, since it then turns the pin high, right? To be able to always know where "HOME" is, it should then have some sort of internal memory to store it.

In the program I just read the pin, but that seems rather pointless if I cannot change the home position myself... I have tried moving the encoder so slightly but I never reach the home position. Maybe the motor itself has to be powered on? Because now I am only using the encoder. I have checked my setup and everything seems correct, so it should work, yet it doesn't...

Thank you for the explanation, but unfortunately I cannot edit the title ;(
 

Ya’akov

Joined Jan 27, 2019
9,165
I edited the title of the thread for you. It might get more attention.

Unfortunately, the datasheet is not heavy on detail, but the very sparse “Tech Support” section of their website offers this in definition of terms:
Home: Reference position for all absolute positioning movements. Usually defined by a home limit switch and/or encoder marker.
So, as I expected, it appears that there is a marker at the encoder’s end of run. I would surmise it is in the retracted position though it could be in the extended. At one end of the run that line will be high unless it is not working.

Home is an absolute location, not a relative one. If the end of run will not be your home, you will need to add a limit switch that is located in your desired home position.
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
I edited the title of the thread for you. It might get more attention.

Unfortunately, the datasheet is not heavy on detail, but the very sparse “Tech Support” section of their website offers this in definition of terms:


So, as I expected, it appears that there is a marker at the encoder’s end of run. I would surmise it is in the retracted position though it could be in the extended. At one end of the run that line will be high unless it is not working.

Home is an absolute location, not a relative one. If the end of run will not be your home, you will need to add a limit switch that is located in your desired home position.
Thank you for the title change. I took an oscilloscope and confirmed that you were correct - at the very end I get a 5V jump :)
 

MaxHeadRoom

Joined Jul 18, 2013
28,688
That appears to be a standard type quadrature encoder, also with the complementary outputs for the A-B quadrature signals.
No one-per-rev zero pulse included though. !
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
My problem now is that the code does not register the jump from 0v to 5v. I have it set up as I wrote in my question - GPIO_Input with pull-down. I cannot seem to figure it out and thus I believe there is a logical flaw in my thinking as the problem is quite straightforward.
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
my apologies if I misunderstand your question, I am not a pro at this (yet). What do you mean by whether the interface is suitable?
 

MaxHeadRoom

Joined Jul 18, 2013
28,688
The normal use of the Z - marker pulse in machine axis control is to use a Limit switch detection at the limit of the axis end , as .Ya'akov mentions.
The practice of zeroing, is to rapid the axis to until the limit is detected, then reverse Very slowly until the Z marker is seen. Zero or Home, is then registered.
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
The normal use of the Z - marker pulse in machine axis control is to use a Limit switch detection at the limit of the axis end , as .Ya'akov mentions.
The practice of zeroing, is to rapid the axis to until the limit is detected, then reverse Very slowly until the Z marker is seen. Zero or Home, is then registered.
Thank you for your reply. As I mentioned in a previous reply, I manage to visually see the output in an oscilloscope when the encoder is in the minimum position, so that is quite clear now :) The problem I am having now that I cannot solve, is that in my code when I try and read the pin I have connected the wire to, I never get a high signal... It is a simple if statement that checks the pin state.
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
As a diagnostic, write a tiny test program that doesn’t use the interrupt and just loops checking the pin.
I have done exactly that - no interrupts, just in the main while. Unfortunately I still get no results... My while code:
C:
  while (1)
  {
      if(HAL_GPIO_ReadPin (GPIOA, GPIO_PIN_4) == GPIO_PIN_SET)
           {
              HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
           }
  }
and the configuration of the "Home indicator" wire is:
C:
  /*Configure GPIO pin : PA4 */
  GPIO_InitStruct.Pin = GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
I am trying to do something extremely simple: I have a wire connected to PIN4 on my Nucleo-F446RE. I checked with an oscilloscope and the wire outputs a jump from 0V to 5V at one point. Unfortunately in my code, I never trigger the if statement that lights up and LED (PIN5) when the PIN4 is high. I have checked and the LED code works fine.

I have setup pin4 as such:
C:
 /*Configure GPIO pin : PA4 */
  GPIO_InitStruct.Pin = GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
and my simple if statement:
Code:
  while (1)
  {
      if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_4) == GPIO_PIN_SET)
           {
              HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
           }
  }
STM.jpg
 

Thread Starter

ponas.jonas

Joined Feb 28, 2023
36
SOLUTION FOUND!

Apparently PA4 was not the correct PIN. On the NUCLEO board the pin had "A4" written on it, which surprise surprise is not GPIOA PIN4 :) By looking at the schematic, it seems that the correct pin for "A4" is GPIOC PIN1. Thank you for all the replies and help, I learnt in the process :)

1678880192735.png
 
Top