Skip to content

Configuration Settings

clough42 edited this page Oct 7, 2020 · 2 revisions

Configure the Electronic Leadscrew firmware for your hardware by editing the Configuration.h file before compiling and programming the LaunchPad device.

Configuration Settings

All of the possible configuration items are already present in the Configuration.h, but many are commented out by default. Any line that begins with // is a comment and will be ignored. In some cases, there are two options (i.e. metric or imperial). You would typically uncomment (remove the //) of the setting you wish to use, and comment out (add //) to the one you do not wish to use. In most cases, if you leave out a setting, or define both, it will generate an error when you try to compile and program the LaunchPad.

Leadscrew

You need to define what type of leadscrew you have in your lathe. The firmware supports both imperial and metric leadscrews. Uncomment one of the following. You cannot define both.

#define LEADSCREW_TPI 12

If you have an imperial leadscrew, this is the pitch of the leadscrew, in threads per inch. It is a whole number. Fractions are not allowed.

#define LEADSCREW_HMM 200

If you have a metric leadscrew, this is the pitch of the leadscrew threads, in hundredths of a millimeter. For example, if you have a 2.5mm pitch metric leadscrew, set this to '250'.

Stepper/Servo

You need to define the number of steps and microsteps for your stepper or servo motor, so the firmware can calculate the correct drive ratios. This is defined as steps and microsteps. A typical stepper motor has a resolution of 200 steps per revolution, and a typical driver configuration would be 8 microsteps per step. This means that the driver will require 1600 total step pulses (8 * 200) to turn the motor one revolution. If the drive ratio between your motor and leadscrew is not 1:1, use the microsteps value to compensate. For example, if you have a 1000-step servo (common) and your drive ratio is 3:1, set STEPPER_RESOLUTION to 1000 and STEPPER_MICROSTEPS to 3. As long as the multiple of these two values is the number of pulses it takes to rotate the leadscrew one revolution, it should work.

Steps and Microsteps

These settings define the resolution of your leadscrew drive motor.

#define STEPPER_MICROSTEPS 8

Set this to the number of microsteps configured in the stepper/servo driver.

#define STEPPER_RESOLUTION 200

Set this to the number of steps required to rotate your motor one revolution.

Direction and Enable

These settings define the polarity of your stepper or servo control signals.

// #define INVERT_STEP_PIN true

Uncomment this line if you need to invert the signal to your step pin. The default is not to invert.

// #define INVERT_DIRECTION_PIN true

Uncomment this line to reverse the rotation of your stepper or servo, if it turns the wrong direction. The default is not to invert.

#define INVERT_ENABLE_PIN true

Comment out this line if the enable logic is reversed for your stepper or servo driver. The default is to invert.

#define INVERT_ALARM_PIN true

Comment out this line if the alarm feedback to the electronic leadscrew if the firmware is detecting a fault when the driver has not faulted. This is for future expansion, and is not currently active.

#define USE_ALARM_PIN

Comment out this line to disable alarm feedback. This is for future expansion, and is not currently active.

Encoder

These settings define the resolution of your encoder so the firmware knows the number of edges it will receive per revolution. This is the number of quadrature edges, and not the physical resolution of the encoder. For example, a typical encoder might have a resolution of 1024 physical divisions, but the optical sensor generates four edges per division, so you should set the resolution to 4096.

#define ENCODER_RESOLUTION 4096

Set this to the number of edges (typically the resolution x 4) generated per revolution of the encoder.

#define ENCODER_USE_EQEP1 //#define ENCODER_USE_EQEP2

Normally, the encoder is connected to the EQEP1 input on the LaunchPad. If for some reason you want (or need) to connect to EQEP2 instead, comment out ENCODER_USE_EQEP1 and uncomment ENCODER_USE_EQEP2. This is almost never necessary.

Calculations

When the project was new, a few people were concerned about using floating point math for the gear ratio calculations, so the firmware includes the option of using integral math instead. There is no reason to change this unless you really know what you're doing. The floating point math is the default and has received the most testing.

#define USE_FLOATING_POINT

Uncomment this line if you really want to use integral math instead.

Hardware

When the project was young, there was a v1 of the interface PC board that used a different EEPROM chip. This setting allows you to reconfigure the firmware to use this old hardware. This will only apply to people who built their own circuit boards. The V1 boards were never offered for sale. If you purchased a board from Clough42, you have V2. The version number is silkscreened on the top of the board if you want to be sure.

#define HARDWARE_VERSION 2

Set this to 1 if you have a board you made to the original specs.

Features

These are optional features or behaviors that you can enable for your ELS.

//#define IGNORE_ALL_KEYS_WHEN_RUNNING

The firmware normally ignores mode and direction change button presses when the spindle is running (RPM is not zero) but you can still change the feed or pitch. If you want to instead lock all button inputs while the spindle is running, uncomment this line.

CPU/Timing

These settings are used for internal timing of the interrupt handlers and calculations based on clock cycles. You would only need to touch these if you are running on a different CPU or are trying to tune something specific. Most users should not touch these settings.

#define STEPPER_CYCLE_US 5

This is the length of the cycle for the step generator state machine, in microseconds. This defines the minimum pulse width of the step pulses. Two cycles are required per pulse (one cycle high and one cycle low). Setting this to a faster (lower) value may make the pulses too fast for some stepper or servo drivers, and could also result in the ISR starving the UI thread. Setting it to a slower (larger) value will limit the maximum step rate and could steps to be buffered so the leadscrew loses sync and keeps running after the spindle stops. Leave this at the default.

#define UI_REFRESH_RATE_HZ 100

This is the refresh rate for the UI. In reality, this is used to calculate the delay between refresh cycles, so the actual refresh will be slower than this. This refresh rate will affect the input filtering, so it's best to leave it at the default.

#define RPM_CALC_RATE_HZ 10

This defines the rate at which the RPM is recalculated. This is critically related to the UI refresh rate, the maximum frequency of the encoder edges and the number of bits in a hardware counter register, so it's best to leave this at the default.

#define CPU_CLOCK_MHZ 100 #define CPU_CLOCK_HZ (CPU_CLOCK_MHZ * 1000000)

These define the microprocessor clock speed, and are used for timing calculations.