Homing stepper motor at start up and limit distance of travel?

Hello, I’m new to this and I was wondering if someone could help with my code?

I’m currently making a back gauge for a small press brake (sheet metal folder). Basically it is a backstop that moves a specific distance when the desired length is entered on a keypad. I found a some code from brainy-bits.com that is perfect for the job but it lacked two things.

  1. I need it to home to a limit switch when it is switched on
  2. After it has homed it’s only able to travel a specific distance range and if a number is entered above that range it will not allow it to move.

I have managed to get the homing sorted I think but I am stuck on how to limit its travel distance? I need it to be able to only move say 470mm otherwise it will crash. I had thought about adding a second limit switch with an interrupt in the code but I’m unsure if this would confuse its actual distance its travelled and I would end up having to reset it all.

I have attached the modified code I’m using. Hope someone can help

Thanks, Oliver

Press_brake_home3.ino (8.67 KB)

Can’t you just count the pulses that you are generating during the homing phase?

Sorry I’m not too sure what you mean? Do you mean counting the pulses as it moves to its home position on start up or the number of pulses after it has homed? And only allowing it to pulse a specific amount of times?

Thanks, Oliver

The number of steps after it has homed.

...R

Ok, I thought that’s what was meant. I had thought possibly of doing something like that but unsure of how to do it.

The code is currently allowing me to move between 0 and 999mm (I only want it to move between 0 and 470mm) and remembering what position its currently in and displays current position on the screen. So say I move to 300mm then I entered 200mm it would move back to 200mm from zero point. How would I write the code so it would only allow me to move so many turns from the zero point no mater what its current position is?

thank

plan_b_racing:
How would I write the code so it would only allow me to move so many turns from the zero point no mater what its current position is?

Something like this pseudo code

if (positionRequiredByUser > maxPosition) {
   moveTo(maxPosition);
}
else {
   moveTo(positionRequiredByUser);
}

Operating within limits is very common in computer programming.

...R

That’s great. How and were would I need to implement this in my code? As I said I’m new to this and still finding my way.

plan_b_racing:
That’s great. How and were would I need to implement this in my code? As I said I’m new to this and still finding my way.

Sorry but that's like asking "where did I put my piece of string?" So much depends on context.

The best thing is for you to create a program that represents your best attempt. If it does not work then post your program and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

...R

Ok, will do.