Motor Driver Evaluation Kit NEVB-MTR1-t01-1.0.0
Firmware for NEVB-MTR1-KIT1 for trapezoidal control of BLDC motors using Hall-effect sensors
|
SCPI implementation source file. More...
Go to the source code of this file.
Functions | |
static void | ScpiCoreIdnQ (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Implements the *IDN? (Identification Query) command. | |
static void | ScpiSystemErrorCountQ (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Implements the SYSTem:ERRor:COUNt? (System Error Count Query) command. | |
static void | ScpiSystemErrorNextQ (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Implements the SYSTem:ERRor? (System Error Next Query) command. | |
static void | GetMotorEnable (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Retrieves the current motor enable state. | |
static void | ConfigureMotorEnable (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Configures the motor's enable state. | |
static void | GetConfigureMotorDutyCycleSource (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Retrieves the configured motor's duty cycle source. | |
static void | ConfigureMotorDutyCycle (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Configures the motor's speed input by setting the duty cycle. | |
static void | ConfigureMotorFrequency (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Configures the motor's operating frequency. | |
static void | GetConfigureMotorFrequency (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Retrieves the configured motor frequency. | |
static void | ConfigureMotorDirection (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Sets the motor's direction based on the input parameter. | |
static void | GetConfigureMotorDirection (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Retrieves the configured direction of the motor. | |
static void | MeasureMotorSpeed (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures the motor speed. | |
static void | MeasureMotorCurrentVBus (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and returns the motor's VBUS current. | |
static void | MeasureMotorCurrentPhaseU (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and returns the motor's phase U current. | |
static void | MeasureMotorCurrentPhaseV (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and returns the motor's phase V current. | |
static void | MeasureMotorCurrentPhaseW (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and returns the motor's phase W current. | |
static void | MeasureMotorDirection (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and reports the current direction of the motor. | |
static void | MeasureMotorVoltage (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and returns the VBUS voltage of the motor. | |
static void | MeasureGateDutyCycle (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Measures and returns the gate PWM duty cycle as a percentage. | |
static void | ConfigureMotorDutyCycleSource (SCPI_C commands, SCPI_P parameters, Stream &interface) |
Configures the motor's speed input source. | |
void | ScpiInit (void) |
Initializes the SCPI command parser and registers all supported commands. | |
void | ScpiInput (Stream &interface) |
Processes incoming data from a serial interface for SCPI commands. | |
Variables | |
SCPI_Parser | scpiParser |
Speed input source options array. | |
const SCPI_choice_def_t | motorDirections [2] |
Array defining the possible motor directions for SCPI commands. | |
const SCPI_choice_def_t | inputSources [2] |
Array defining the possible input sources for speed/duty cycle control. | |
SCPI implementation source file.
This file contains the command handlers for the SCPI parser to recognize and execute.
Most of this code was originally written by Diego González Chávez as part of the Vrekrer SCPI Parser project.
It has been merged into the main codebase for customization and linking limitations of the Arduino IDE.
Definition in file scpi.cpp.
|
static |
Sets the motor's direction based on the input parameter.
This function reads a direction parameter ('FORW' or 'REVE') and sets the motor's direction accordingly by manipulating the DIRECTION_COMMAND_PIN
on PORTD
.
In remote mode, the DIRECTION_COMMAND_PIN
is configured as an output. Setting or clearing the pin triggers the relevant software interrupt as it would in normal operation.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters containing the direction choice. |
interface | The serial interface (not used). |
Definition at line 447 of file scpi.cpp.
|
static |
Configures the motor's speed input by setting the duty cycle.
This function reads a double parameter (0.0 to 100.0) from the SCPI command and sets the motor's duty cycle accordingly.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters containing the duty cycle value. |
interface | The serial interface (not used). |
Definition at line 340 of file scpi.cpp.
|
static |
Configures the motor's speed input source.
This function reads a choice parameter ('LOCAL' or 'REMOTE') from the SCPI command and sets the motor's speed input source accordingly, corresponding to SPEED_INPUT_SOURCE_LOCAL
and SPEED_INPUT_SOURCE_REMOTE
.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters containing the input source choice. |
interface | The serial interface (not used). |
Definition at line 270 of file scpi.cpp.
Configures the motor's enable state.
This function reads a boolean parameter (0 or 1) from the SCPI command and sets the motor's enable state accordingly.
In remote mode, the ENABLE_PIN
is configured as an output. The motor is then enabled or disabled by setting or clearing the ENABLE_PIN
on the PORTD
register, which triggers the relevant software interrupt as it would in normal operation.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters containing the boolean enable value. |
interface | The serial interface (not used). |
Definition at line 236 of file scpi.cpp.
|
static |
Configures the motor's operating frequency.
This function sets the motor's operating frequency based on the input parameter. It validates the frequency range (7183 to 100000 Hz), updates the motor configuration, and reinitializes timers after ensuring the motor is stopped.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters containing the frequency value in Hz. |
interface | The serial interface (not used). |
Definition at line 388 of file scpi.cpp.
|
static |
Retrieves the configured direction of the motor.
This function queries the desired direction of the motor and returns a textual representation ('FORW' or 'REVE') based on the motorFlags.desiredDirection
setting.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 482 of file scpi.cpp.
|
static |
Retrieves the configured motor's duty cycle source.
This function queries the currently configured source for the motor's duty cycle (either 'LOCAL' or 'REMOTE') and returns it as a string.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 309 of file scpi.cpp.
|
static |
Retrieves the configured motor frequency.
This function queries the current frequency configuration of the motor and returns it as a double value representing the frequency in Hertz.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 427 of file scpi.cpp.
Retrieves the current motor enable state.
This function queries the current enable state of the motor and returns it as a boolean value (1 for enabled, 0 for disabled).
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 216 of file scpi.cpp.
Measures and returns the gate PWM duty cycle as a percentage.
This function reads the current PWM duty cycle from Timer4's compare register (OCR4A) and calculates the percentage relative to the timer's top value. Interrupts are briefly disabled to ensure atomic reading of the 16-bit duty cycle value.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 628 of file scpi.cpp.
|
static |
Measures and returns the motor's phase U current.
This function reads the ADC value for the phase U current sense, converts it to Amperes using the known gain and sense resistor value. It accounts for the ADC offset (typically around 511 for a centered reading).
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 539 of file scpi.cpp.
|
static |
Measures and returns the motor's phase V current.
This function reads the ADC value for the phase V current sense, converts it to Amperes using the known gain and sense resistor value. It accounts for the ADC offset (typically around 511 for a centered reading).
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 555 of file scpi.cpp.
|
static |
Measures and returns the motor's phase W current.
This function reads the ADC value for the phase W current sense, converts it to Amperes using the known gain and sense resistor value. It accounts for the ADC offset (typically around 511 for a centered reading).
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 571 of file scpi.cpp.
|
static |
Measures and returns the motor's VBUS current.
This function reads the ADC value for the VBUS current sense, converts it to Amperes using the known gain and sense resistor value.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 523 of file scpi.cpp.
Measures and reports the current direction of the motor.
This function checks the motorFlags.actualDirection
and returns a textual representation ('FORW', 'REVE', or 'UNKN') based on the motor's sensed direction.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 587 of file scpi.cpp.
Measures the motor speed.
This function calculates and returns the motor speed in revolutions per minute (RPM). It uses the time difference between the last two commutation events and the configured motor frequency and pole count for the calculation.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 500 of file scpi.cpp.
Measures and returns the VBUS voltage of the motor.
This function reads the ADC value for the VBUS voltage reference and converts it to Volts using the voltage divider resistor values.
commands | The SCPI commands (not used). |
parameters | The SCPI parameters (not used). |
interface | The serial interface to write the response to. |
Definition at line 611 of file scpi.cpp.
Implements the *IDN?
(Identification Query) command.
This function responds to the *IDN?
command by sending the manufacturer, model, serial number (if defined), and firmware revision of the device. The identification string is formatted as: <Manufacturer>,<Model>,<SerialNumber>,<FirmwareRevision>
.
commands | The parsed SCPI commands (not used). |
parameters | The parsed SCPI parameters (not used). |
interface | The serial stream interface to write the response to. |
Definition at line 140 of file scpi.cpp.
void ScpiInit | ( | void | ) |
Initializes the SCPI command parser and registers all supported commands.
This function sets up the SCPI parser instance and registers the core IEEE mandated commands, required SCPI commands, and the custom motor control and measurement commands.
Definition at line 71 of file scpi.cpp.
void ScpiInput | ( | Stream & | interface | ) |
Processes incoming data from a serial interface for SCPI commands.
This function takes a Stream
object (like Serial
) and processes any received data, looking for complete SCPI commands terminated by a newline character. It then passes the command to the SCPI parser for execution.
interface | The serial stream interface to read commands from. |
Definition at line 124 of file scpi.cpp.
Implements the SYSTem:ERRor:COUNt?
(System Error Count Query) command.
This function returns the number of errors currently in the error queue. In this simplified implementation, it returns 1 if there was a last error, and 0 otherwise.
commands | The parsed SCPI commands (not used). |
parameters | The parsed SCPI parameters (not used). |
interface | The serial stream interface to write the response to. |
Definition at line 165 of file scpi.cpp.
Implements the SYSTem:ERRor?
(System Error Next Query) command.
This function returns the oldest error from the error queue and clears it. In this implementation, it returns a textual description of the last recorded error and then clears the last_error
flag.
commands | The parsed SCPI commands (not used). |
parameters | The parsed SCPI parameters (not used). |
interface | The serial stream interface to write the response to. |
Definition at line 181 of file scpi.cpp.
const SCPI_choice_def_t inputSources[2] |
Array defining the possible input sources for speed/duty cycle control.
Number of speed input source options.
This array is used by the SCPI parser to interpret and represent the source of the motor's speed or duty cycle control ('LOCA' for local, 'REMO' for remote). Each entry associates a textual representation with a numerical value (e.g., SPEED_INPUT_SOURCE_LOCAL
, SPEED_INPUT_SOURCE_REMOTE
).
Definition at line 667 of file scpi.cpp.
const SCPI_choice_def_t motorDirections[2] |
Array defining the possible motor directions for SCPI commands.
Number of motor direction options.
This array is used by the SCPI parser to interpret and represent the motor's direction ('FORW' for forward, 'REVE' for reverse). Each entry in the array associates a textual representation with a numerical value defined elsewhere (e.g., DIRECTION_FORWARD
, DIRECTION_REVERSE
).
Definition at line 654 of file scpi.cpp.
SCPI_Parser scpiParser |