| aMotion_SetMode | Index |
Definition:
Parameters:
| channel | - | Motion control channel |
| modeIndex | - | Code for selecting the control mode. |
| flags | - | Control flags. |
Return Value:
Description:
This routine sets the mode code and mode flags for a motion control channel. See the cmdMO_CFG documentation for details on configuring a motion control channel.
There are defined values for each motion control mode.
| aMOTION_MODE_OFF | 0 | PWM, encoders, and PID control disabled |
| aMOTION_MODE_STEP | 1 | Bipolar stepper motor drive mode enabled |
| aMOTION_MODE_PWM | 2 | PWM enabled |
| aMOTION_MODE_PWMENC | 3 | PWM and encoders enabled |
| aMOTION_MODE_A2DPOS | 4 | PID position control from analog input enabled |
| aMOTION_MODE_ENCPOS | 5 | PID position control from encoder input enabled |
| aMOTION_MODE_A2DVEL | 6 | PID velocity control from analog input enabled |
| aMOTION_MODE_ENCVEL | 7 | PID velocity control from encoder input enabled |
| aMOTION_MODE_PWMA2D | 8 | PWM enabled with analog input capture enabled |
There are additional settings that can be used to swap input or output polarity, select mono encoder mode, or select autobraking for back-EMF control. In stepper mode, the flags control coil polarity and drive pattern type. Each setting is controlled with a bit flag. The indices of each bit flag have a defined value.
| aMOTION_PWMFLAG_INVPID | 0 | Negate input to PID loop |
| aMOTION_PWMFLAG_INVPWM | 1 | Negate motor output |
| aMOTION_PWMFLAG_MONOENC | 2 | Select mono encoder mode |
| aMOTION_PWMFLAG_AUTOBRAKE | 3 | Activate brake output during latency period |
| aMOTION_STEPFLAG_INVA | 0 | Negate output to coil A |
| aMOTION_STEPFLAG_INVB | 1 | Negate output to coil B |
| aMOTION_STEPTYPEMASK | 0x0C | Mask for 2-bit stepper motor drive pattern code |
Example:
#include <aMotion.tea>
aMotion_SetMode(0, aMOTION_MODE_PWM, (1 << aMOTION_PWMFLAG_INVPWM));
This would configure motion control channel 0 for PWM mode and invert the PWM output to the motor.
Related: