53#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
55#elif (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)
56static void ConfigureMotorSpeedSource(
SCPI_C commands,
SCPI_P parameters, Stream &interface);
57static void GetMotorSpeedSource(
SCPI_C commands,
SCPI_P parameters, Stream &interface);
58static void ConfigureMotorSpeed(
SCPI_C commands,
SCPI_P parameters, Stream &interface);
87#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
92 scpiParser.RegisterCommand(F(
":SPEED:SOURce"), &ConfigureMotorSpeedSource);
93 scpiParser.RegisterCommand(F(
":SPEED:SOURce?"), &GetMotorSpeedSource);
94 scpiParser.RegisterCommand(F(
":SPEED"), &ConfigureMotorSpeed);
143 interface.print(F(
","));
145 interface.print(F(
","));
149 interface.print(F(
","));
186 interface.println(F(
"Buffer overflow error"));
189 interface.println(F(
"Communication timeout error"));
192 interface.println(F(
"Unknown command received"));
195 interface.println(F(
"No Error"));
198 interface.println(F(
"Missing or invalid parameter"));
201 interface.println(F(
"Unknown error"));
218 interface.println(motorFlags.enable);
269#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
271#elif (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)
272static void ConfigureMotorSpeedSource(
SCPI_C commands,
SCPI_P parameters, Stream &interface)
298#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
310#elif (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)
321static void GetMotorSpeedSource(
SCPI_C commands,
SCPI_P parameters, Stream &interface)
326 interface.println(name);
329#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
343 if (!
ScpiParamDouble(parameters, param) || param < 0.0 || param > 100.0)
351#elif (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)
363static void ConfigureMotorSpeed(
SCPI_C commands,
SCPI_P parameters, Stream &interface)
396 if (!
ScpiParamUInt32(parameters, param) || param < 7183 || param > 100000)
407 while (faultFlags.motorStopped ==
FALSE)
486 interface.println(name);
504 interface.println(0.0);
591 interface.println(F(
"UNKN"));
597 interface.println(name);
630 if (motorFlags.enable ==
TRUE)
634 uint16_t duty = 0xff & OCR4A;
635 duty |= (0x03 & TC4H) << 8;
638 interface.println((
double)duty / (
double)
motorConfigs.tim4Top * 100.0);
642 interface.println(0.0);
Motor config header file.
#define TIM4_TOP(tim4Freq)
#define DIRECTION_FORWARD
Forward direction flag value.
#define DIRECTION_COMMAND_PIN
Pin where direction command input is located.
#define SPEED_INPUT_SOURCE_LOCAL
Speed input source - Local or speed input pin.
#define SPEED_CONTROLLER_MAX_INPUT
Maximum Speed Reference Input.
#define DIRECTION_REVERSE
Reverse direction flag value.
#define ENABLE_PIN
Enable input pin.
#define SPEED_INPUT_SOURCE_REMOTE
Speed input source - Remote input.
#define TRUE
TRUE constant value, defined to be compatible with comparisons.
#define FALSE
FALSE constant value.
#define DIRECTION_UNKNOWN
Unknown direction flag value.
#define IBUS_GAIN
Hi-side Current (IBUS) Gain for Current Measurement.
#define IPHASE_SENSE_RESISTOR
Hi-side Current (IBUS) Sense Resistor Value.
#define IBUS_SENSE_RESISTOR
Hi-side Current (IBUS) Sense Resistor Value.
#define VBUS_RBOTTOM
Bottom resistor value in the VBUS voltage potential divider.
#define MOTOR_POLES
Number of poles in the motor.
#define SPEED_CONTROLLER_MAX_SPEED
Speed Controller Maximum Speed.
#define IPHASE_GAIN
In-line Phase Current Gain for Current Measurement.
#define VBUS_RTOP
Top resistor value in the VBUS voltage potential divider.
volatile uint16_t vbusVref
VBUS voltage measurement (Register Value)
volatile uint8_t speedInput
The most recent "speed" input measurement.
volatile uint16_t ibus
Hi-side Current (IBUS) measurement (Register Value).
volatile motorconfigs_t motorConfigs
Motor Configs.
volatile int16_t iphaseW
In-line Phase W current current measurement (Register Value).
volatile uint16_t lastCommutationTicks
The number of 'ticks' between two hall sensor changes (store).
void TimersInit(void)
Initializes and synchronizes Timers.
volatile int16_t iphaseU
In-line Phase U current current measurement (Register Value).
volatile int16_t iphaseV
In-line Phase V current current measurement (Register Value).
static void GetConfigureMotorDirection(SCPI_C commands, SCPI_P parameters, Stream &interface)
Retrieves the configured direction of the motor.
static void GetConfigureMotorDutyCycleSource(SCPI_C commands, SCPI_P parameters, Stream &interface)
Retrieves the configured motor's duty cycle source.
static void MeasureMotorCurrentPhaseV(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and returns the motor's phase V current.
static void ScpiSystemErrorNextQ(SCPI_C commands, SCPI_P parameters, Stream &interface)
Implements the SYSTem:ERRor? (System Error Next Query) command.
static void MeasureMotorSpeed(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures the motor speed.
static void MeasureMotorDirection(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and reports the current direction of the motor.
static void ScpiSystemErrorCountQ(SCPI_C commands, SCPI_P parameters, Stream &interface)
Implements the SYSTem:ERRor:COUNt? (System Error Count Query) command.
static void MeasureMotorCurrentPhaseU(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and returns the motor's phase U current.
static void MeasureMotorCurrentVBus(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and returns the motor's VBUS current.
static void ConfigureMotorEnable(SCPI_C commands, SCPI_P parameters, Stream &interface)
Configures the motor's enable state.
static void ScpiCoreIdnQ(SCPI_C commands, SCPI_P parameters, Stream &interface)
Implements the *IDN? (Identification Query) command.
static void GetConfigureMotorFrequency(SCPI_C commands, SCPI_P parameters, Stream &interface)
Retrieves the configured motor frequency.
static void ConfigureMotorDutyCycleSource(SCPI_C commands, SCPI_P parameters, Stream &interface)
Configures the motor's speed input source.
static void GetMotorEnable(SCPI_C commands, SCPI_P parameters, Stream &interface)
Retrieves the current motor enable state.
static void ConfigureMotorDutyCycle(SCPI_C commands, SCPI_P parameters, Stream &interface)
Configures the motor's speed input by setting the duty cycle.
static void MeasureMotorCurrentPhaseW(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and returns the motor's phase W current.
static void ConfigureMotorDirection(SCPI_C commands, SCPI_P parameters, Stream &interface)
Sets the motor's direction based on the input parameter.
static void MeasureMotorVoltage(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and returns the VBUS voltage of the motor.
void ScpiInput(Stream &interface)
Processes incoming data from a serial interface for SCPI commands.
void ScpiInit(void)
Initializes the SCPI command parser and registers all supported commands.
const SCPI_choice_def_t inputSources[2]
Array defining the possible input sources for speed/duty cycle control.
SCPI_Parser scpiParser
Speed input source options array.
static void MeasureGateDutyCycle(SCPI_C commands, SCPI_P parameters, Stream &interface)
Measures and returns the gate PWM duty cycle as a percentage.
static void ConfigureMotorFrequency(SCPI_C commands, SCPI_P parameters, Stream &interface)
Configures the motor's operating frequency.
const SCPI_choice_def_t motorDirections[2]
Array defining the possible motor directions for SCPI commands.
SCPI implementation header file.
#define INPUT_SOURCE_OPTIONS
Motor direction options array.
#define MOTOR_DIRECTION_OPTIONS
Motor direction options array.
SCPI parser configuration header file.
#define SCPI_IDN4
Firmware version identification string for the *IDN? command.
#define SCPI_IDN1
Manufacturer identification string for the *IDN? command.
#define SCPI_IDN2
Model number identification string for the *IDN? command.
#define SCPI_IDN3
Revision level identification string for the *IDN? command (optional).
uint8_t ScpiParamChoice(SCPI_P ¶meters, const SCPI_choice_def_t *options, size_t optionsSize, uint8_t ¶m)
Extracts a choice parameter from the SCPI parameter list and maps it to a numerical tag.
uint8_t ScpiParamBool(SCPI_P ¶meters, bool ¶m)
Extracts a boolean parameter ('ON', '1', 'OFF', or '0') from the SCPI parameter list.
uint8_t ScpiParamUInt32(SCPI_P ¶meters, uint32_t ¶m)
Extracts an unsigned 32-bit integer parameter from the SCPI parameter list.
uint8_t ScpiParamDouble(SCPI_P ¶meters, double ¶m)
Extracts a double-precision floating-point parameter from the SCPI parameter list.
uint8_t ScpiChoiceToName(const SCPI_choice_def_t *options, size_t optionsSize, int8_t value, String &name)
Converts a numerical choice tag back to its string representation.
@ MissingOrInvalidParameter
A required parameter was missing or an invalid parameter was provided.
@ BufferOverflow
The message buffer was exceeded during message reception.
@ NoError
No error occurred.
@ Timeout
A timeout occurred before receiving the expected termination characters.
@ UnknownCommand
An unknown command was received that could not be matched to a known handler.
SCPI_Parameters SCPI_P
Alias for SCPI_Parameters.
SCPI_Commands SCPI_C
Alias for SCPI_Commands.