I have a 40:1 dividing head and a 90:1 rotary table, so can I put in the values
#define stepperDiv 8000.0 // for 40:1 dividing head - could I change stepperDiv to dhDiv, or dividingheadDiv?
#define rotaryDiv 18000.0 // for 90:1 rotary table
Thanks again!
Duncan
Duncan, nothing wrong with Chucks soultion.
A #define in C is simply a way to write understandable self-documenting code. Statements on a line commencing # is an instruction to C's precompiler and does not generate any CPU instructions. So whenever
stepperDiv is in the code, it will be replaced by 8000 or 18000 depending on the value when executable code is generated.
But where do these numbers come from is what you need to ask on your path to enlightenment!
Most stepper motors take 200 pulses (steps) per revolution but this is not always the case. You do the maths but you will see why they are referred to 1.8 degree steppers if you divide 360 by 200. Some steppers are 0.9 degrees.
So if you have a 90:1 worm drive, it is going to take 90 turns of the motor to turn the table 1 revolution or 200 x 90 pulses = 18,000
So with your 40:1 worm drive 1 revolution will require 40 x 200 pulses = 8,000 pulses.
The other parameter that comes into play is if your stepper controller is microstepping. The Gecko 251x is a popular example. It is a 10x microstepping controller so it takes 2000 pulses to turn the stepper motor one revolution.
So if you were using one of these stepper controllers, you would need to multiply these values x 10 to get
90:1 180000
40:1 80000
So back to the C world, by convention #defines are shown as upper case to make it clear they are not variables. I would prefer to set defines like this:
#define STEPPER_STEPS 200 //200 steps per revolution drive
#define WORM_DRIVE 40 // 40:1 worm drive
#define MICRO_STEPS 10 // 10 x microstepping ( 1 if no microstepping)
#define STEPS_PER_REV STEPPER_STEPS * WORM_DRIVE * MICRO_STEPS
So now all you have to do is fill out the variables and C does the calculations for you. Just use
STEPS_PER_REV instead of
stepperDiv and when you revisit the code or share it with somebody later it is 100% clear what is going on.
One day you will understand my code if you play with C long enough. It is complex, but clear and concise. The very first version I posted does it all in 200 lines of code. Then I got carried away..... The flip side is the user does not need to change any code.....