Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: RaymondC on August 15, 2020, 10:43:08 PM

Title: Basic stepper motor configuration and motion
Post by: RaymondC on August 15, 2020, 10:43:08 PM
Hello,

I have a good deal of experience with Parker-Hannifin PLCs and servo motors but am brand new to ladder logic and stepper motors. I am using a BRX PLC and a SureStep stepper motor.

I have some basic questions.

#1 What is the "best practices" way to execute a set of setup commands? These are the sort of things that need to run first and only once. Included in these commands would be configuring my stepper motor which I believe is done via AXCONFIG. Should I be checking axis bits like .Configured after my setup routine to make sure the setup succeeded?

#2 How to home the motor to a starting position? I assume this requires a limit switch? And how to run this command such that it runs only once at the start?

#3 What is the best way to implement a simple motion loop? In a separate program? For example: rotate from home position by 90 degrees, pause for 1 second, return to home position, pause another second and repeat endlessly while some input is on. I think I use the AXPOSTRAP command. If the motor is configured as rotary then would a move to position 90 rotate by 90 degrees? How to properly configure the timers to implement the 1 second delays after confirming the moves are completed?

Thank you.

Ray
Title: Re: Basic stepper motor configuration and motion
Post by: Garyhlucas on August 16, 2020, 09:11:25 AM
Ray,
If you haven?t used Stage logic before I think you?ll find this will work really well for you. If a move is performed in a stage you simply use the move complete bit to trigger a timer that jumps you out of that stage.  Stage logic is very effective at reducing scan times as stages that are off don?t get scanned. 

I am using a BRX to control a drilling machine with a long X axis and two Z axis to do drilling of two parts at the same time. I have already implemented jogging to pick up X and Z origins and the motion commands are easy to use.  I am using a PLC rather than a CNC because this machine has a ton of I/O and I need to start spindles while others are already working to eliminate large delays in switching which spindle is being used. Also the programs will be recipes where the PLC calculates all the drilling positions rather than CNC G-code that have to be programmed manually.
Title: Re: Basic stepper motor configuration and motion
Post by: RaymondC on August 16, 2020, 09:58:32 AM
Yea, I plan to use stages in a separate program to control the motion loop.

For the setup commands, I was think of using a subroutine called from $Main with the $FirstScan trigger.
Title: Re: Basic stepper motor configuration and motion
Post by: RBPLC on August 16, 2020, 10:11:39 AM
The below video is a pretty good primer in stage programming if you haven't seen it. Initialization commands are often put in the $FirstScan directly.

https://www.youtube.com/watch?v=v3JWWTaN4o8

Title: Re: Basic stepper motor configuration and motion
Post by: RaymondC on August 17, 2020, 12:53:25 PM
Good video. Thanks.

What do you mean by "Initialization commands are often put in the $FirstScan directly." Do you mean using the $FirstScan flag to individually trigger each initialization command? If so, I was considering a separate subroutine simply so that a single $FirstScan trigger would run the complete set of initialization commands.
Title: Re: Basic stepper motor configuration and motion
Post by: franji1 on August 17, 2020, 01:41:48 PM
Good video. Thanks.

What do you mean by "Initialization commands are often put in the $FirstScan directly." Do you mean using the $FirstScan flag to individually trigger each initialization command? If so, I was considering a separate subroutine simply so that a single $FirstScan trigger would run the complete set of initialization commands.

There is a Status BIT (ST0) that has the nickname $FirstScan, but there is also a similar named TASK code block (but not a PROGRAM code block - slight difference) called $tFirstScan.  So in $tFirstScan you can just do a RUN (no contact needed) of the PROGRAM to setup/initialize your axis.  Or from $Main you can have the ST0 bit drive the RUN.  The first one is more "modularized" - where you would stick all your STR ST0 in $Main, but just tie it to the power rail in $tFirstScan (no contact needed unless there are other "conditions" that you may or may not do on first scan).
Title: Re: Basic stepper motor configuration and motion
Post by: RaymondC on August 17, 2020, 04:46:12 PM
I didn't know there was a $FirstScan Task code block. Perfect!

Thank you.
Title: Re: Basic stepper motor configuration and motion
Post by: franji1 on August 17, 2020, 05:05:49 PM
I didn't know there was a $FirstScan Task code block. Perfect!

Thank you.

It's called $tFirstScan to distinguish it from $FirstScan ($t => System Task).

There's other $ystem Tasks:
$tTopOfScan for logic that you stick at the top of your ladder logic BEFORE anything else runs, e.g. scaling analog inputs
$tBottomOfScan for logic that you stick at the bottom of your ladder logic AFTER everything else runs, e.g. scaling analog outputs
et. al.