59 SCPI_ResultDouble(context, 0);
99 SCPI_ResultText(context,
"UNKNown");
107 SCPI_ResultText(context, name);
139#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
141#elif (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)
142static scpi_result_t ConfigureMotorSpeedSource(scpi_t *context)
148 if (!SCPI_ParamBool(context, ¶m,
TRUE))
168#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
180 if (!SCPI_ParamDouble(context, ¶m,
TRUE))
187 if ((param < 0.0) | (param > 100.0))
197#elif (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)
204static scpi_result_t ConfigureMotorSpeed(scpi_t *context)
209 if (!SCPI_ParamUInt32(context, ¶m,
TRUE))
240 uint16_t duty = 0xff & OCR4A;
241 duty |= (0x03 & TC4H) << 8;
248 SCPI_ResultDouble(context, 0);
273 if (!SCPI_ParamBool(context, ¶m,
TRUE))
366 SCPI_ResultText(context, name);
389 if (!SCPI_ParamUInt32(context, ¶m,
TRUE))
396 if ((param < 7183) | (param > 100000))
452 if (!SCPI_ParamUInt32(context, ¶m,
TRUE))
459 if ((param < 350) | (param > 1875))
506 {
"*CLS", SCPI_CoreCls, 0},
507 {
"*IDN?", SCPI_CoreIdnQ, 0},
508 {
"*RST", SCPI_CoreRst, 0},
511 {
"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, 0},
512 {
"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, 0},
513 {
"SYSTem:VERSion?", SCPI_SystemVersionQ, 0},
518#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_OPEN_LOOP)
522 {
"CONFigure:MOTOr:SPEED:SOURce", ConfigureMotorSpeedSource, 0},
523 {
"CONFigure:MOTOr:SPEED", ConfigureMotorSpeed, 0},
549size_t SCPI_Write(scpi_t *context,
const char *data,
size_t len)
552 Serial.write(data, len);
584#if (REMOTE_DEBUG_MODE == TRUE)
586 Serial.print(
", \"");
587 Serial.print(SCPI_ErrorTranslate(err));
588 Serial.println(
"\"");
605scpi_result_t
SCPI_Control(scpi_t *context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val)
#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 CURRENT_GAIN
Current Gain for Current Measurement.
#define GATE_RBOTTOM
Bottom resistor value in the gate voltage potential divider.
#define CURRENT_SENSE_RESISTOR
Current Sense Resistor Value.
#define MOTOR_POLES
Number of poles in the motor.
#define SPEED_CONTROLLER_MAX_SPEED
Speed Controller Maximum Speed.
#define GATE_RTOP
Top resistor value in the gate voltage potential divider.
volatile motorflags_t motorFlags
Motor control flags placed in I/O space for fast access.
volatile uint8_t speedInput
The most recent "speed" input measurement.
volatile motorconfigs_t motorConfigs
Motor Configs.
volatile uint16_t current
Current measurement (Register Value).
volatile faultflags_t faultFlags
Fault flags placed in I/O space for fast access.
volatile uint16_t lastCommutationTicks
The number of 'ticks' between two hall sensor changes (store).
void TimersInit(void)
Initializes and synchronizes Timers.
static void ConfigsInit(void)
Initializes motorConfigs.
volatile uint16_t gateVref
Gate voltage measurement (Register Value)
static scpi_result_t MeasureGateVoltage(scpi_t *context)
Measures and returns the gate voltage of the motor.
scpi_interface_t scpi_interface
SCPI interface structure.
scpi_result_t SCPI_Reset(scpi_t *context)
Resets the SCPI context.
scpi_result_t SCPI_Control(scpi_t *context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val)
Handles control messages for the SCPI interface (dummy)
static scpi_result_t MeasureMotorSpeed(scpi_t *context)
Measures the motor speed.
static scpi_result_t GetConfigureMotorDeadTime(scpi_t *context)
Retrieves the configured motor dead time.
static scpi_result_t GetConfigureMotorFrequency(scpi_t *context)
Retrieves the configured motor frequency.
static scpi_result_t GetConfigureMotorDirection(scpi_t *context)
Retrieves the configured direction of the motor.
const scpi_command_t scpi_commands[]
Array of SCPI commands.
static scpi_result_t MeasureMotorCurrent(scpi_t *context)
Measures and returns the motor's current.
static scpi_result_t ConfigureMotorDeadTime(scpi_t *context)
Configures the motor's dead time.
scpi_error_t scpi_error_queue_data[4]
SCPI error queue data array.
size_t SCPI_Write(scpi_t *context, const char *data, size_t len)
Writes data to the SCPI interface.
static scpi_result_t ConfigureMotorDirection(scpi_t *context)
Sets the motor's direction based on the input parameter.
static scpi_result_t ConfigureMotorEnable(scpi_t *context)
Configures the motor's enable state.
char scpi_input_buffer[64]
SCPI input buffer.
int SCPI_Error(scpi_t *context, int_fast16_t err)
Handles SCPI errors and outputs them to the Serial interface.
const scpi_choice_def_t motorDirections[]
Array or enumeration of possible motor directions.
static scpi_result_t GetConfigureMotorEnable(scpi_t *context)
Retrieves the current motor enable state.
scpi_t scpi_context
SCPI context structure.
scpi_result_t SCPI_Flush(scpi_t *context)
Flushes the Serial interface buffer.
static scpi_result_t ConfigureMotorDutyCycleSource(scpi_t *context)
Configures the motor's speed input source.
static scpi_result_t ConfigureMotorFrequency(scpi_t *context)
Configures the motor's operating frequency.
static scpi_result_t MeasureGateDutyCycle(scpi_t *context)
Measures and returns the gate PWM duty cycle.
static scpi_result_t ConfigureMotorDutyCycle(scpi_t *context)
Configures the motor's speed input by changing the duty cycle.
static scpi_result_t MeasureMotorDirection(scpi_t *context)
Measures and reports the current direction of the motor.
SCPI implementation header file.
#define SCPI_INPUT_BUFFER_LENGTH
#define SCPI_ERROR_QUEUE_SIZE
The SCPI error queue size or the maximum number of error retained in memory.
uint8_t motorStopped
Is motor stopped?
uint16_t tim4Top
Corresponding TIM4 top value for TIM4 frequency.
uint8_t speedInputSource
SpeedInput source select (only for remote mode).
uint16_t tim4DeadTime
Corresponding dead time for TIM4 output.
uint32_t tim4Freq
TIM4 or gate switching frequency.
uint8_t desiredDirection
The desired direction of rotation.
uint8_t enable
Is the motor enabled?
uint8_t actualDirection
The actual direction of rotation.