Motor Evaluation Kit NEVC-MCTRL-100-t01-1.0.0
Firmware for NEVB-MCTRL-100-01 for trapezoidal control of BLDC motors using Hall-effect sensors
|
SCPI implementation header file. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "src/SCPI_Parser/SCPI_Parser.h"
#include <Arduino.h>
#include <avr/io.h>
#include "main.h"
Go to the source code of this file.
Macros | |
#define | __AVR_ATmega32U4__ 1 |
Define macro for ATmega32U4 micro controller. | |
#define | SCPI_INPUT_BUFFER_LENGTH 64 |
#define | SCPI_ERROR_QUEUE_SIZE 4 |
The SCPI error queue size or the maximum number of error retained in memory. | |
#define | SCPI_IDN1 "NEXPERIA" |
The manufacturer's name for the identification SCPI query. | |
#define | SCPI_IDN2 "NEVB-MCTRL-100-xx" |
The device's model number for the identification SCPI query. | |
#define | SCPI_IDN3 NULL |
The device's serial number for the identification SCPI query. | |
#define | SCPI_IDN4 "NEVC-MCTRL-100-t01-1.0.0" |
The software verion for the identification SCPI query. | |
Functions | |
void | TimersInit (void) |
Initializes and synchronizes Timers. | |
void | ConfigsInit (void) |
Initializes motorConfigs. | |
size_t | SCPI_Write (scpi_t *context, const char *data, size_t len) |
Writes data to the SCPI interface. | |
int | SCPI_Error (scpi_t *context, int_fast16_t err) |
Handles SCPI errors and outputs them to the Serial interface. | |
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) | |
scpi_result_t | SCPI_Reset (scpi_t *context) |
Resets the SCPI context. | |
scpi_result_t | SCPI_Flush (scpi_t *context) |
Flushes the Serial interface buffer. | |
Variables | |
const scpi_command_t | scpi_commands [] |
Array of SCPI commands. | |
scpi_interface_t | scpi_interface |
SCPI interface structure. | |
char | scpi_input_buffer [] |
SCPI input buffer. | |
scpi_error_t | scpi_error_queue_data [] |
SCPI error queue data array. | |
scpi_t | scpi_context |
SCPI context structure. | |
volatile motorconfigs_t | motorConfigs |
Motor Configs. | |
volatile motorflags_t | motorFlags |
Motor control flags placed in I/O space for fast access. | |
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). | |
volatile uint16_t | current |
Current measurement (Register Value). | |
volatile uint16_t | gateVref |
Gate voltage measurement (Register Value) | |
volatile uint8_t | speedInput |
The most recent "speed" input measurement. | |
SCPI implementation header file.
This file contains all the defines for configurations and function prototypes related to the SCPI implementation.
This file depends on the base SCPI parser library v2 (commit #4e87990) by Jan Breuer which was then ported by Scott Feister to the Arduino IDE, SCPI Parser Arduino Library.
Further modifications were made to the base library to allow for memory optimisation and support for the avr-gcc compiler.
Definition in file scpi.h.
#define __AVR_ATmega32U4__ 1 |
#define SCPI_ERROR_QUEUE_SIZE 4 |
#define SCPI_IDN1 "NEXPERIA" |
#define SCPI_IDN2 "NEVB-MCTRL-100-xx" |
#define SCPI_IDN3 NULL |
#define SCPI_IDN4 "NEVC-MCTRL-100-t01-1.0.0" |
#define SCPI_INPUT_BUFFER_LENGTH 64 |
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)
This function processes control messages such as SRQ (Service Request) or other control signals. It outputs relevant information to the Serial interface. Used as a callback in the SCPI interface structure.
context | The SCPI context |
ctrl | The control name/type |
val | The control value |
Definition at line 605 of file scpi.cpp.
int SCPI_Error | ( | scpi_t * | context, |
int_fast16_t | err ) |
Handles SCPI errors and outputs them to the Serial interface.
This function processes and displays SCPI error messages. It is used as a callback in the SCPI interface structure for error handling.
context | The SCPI context |
err | The error code |
Definition at line 581 of file scpi.cpp.
scpi_result_t SCPI_Flush | ( | scpi_t * | context | ) |
Flushes the Serial interface buffer.
This function ensures that all pending Serial data is transmitted. It acts as a callback for the SCPI interface structure.
context | The SCPI context |
Definition at line 565 of file scpi.cpp.
scpi_result_t SCPI_Reset | ( | scpi_t * | context | ) |
Resets the SCPI context.
This function is called to reset the SCPI environment. It outputs a reset message to the Serial interface and is used as a callback in the SCPI interface structure.
context | The SCPI context |
Definition at line 622 of file scpi.cpp.
size_t SCPI_Write | ( | scpi_t * | context, |
const char * | data, | ||
size_t | len ) |
Writes data to the SCPI interface.
This function is responsible for writing data to the Serial interface. It is used as a callback in the SCPI interface structure.
context | The SCPI context |
data | Pointer to the data to be written |
len | Length of the data to be written |
Definition at line 549 of file scpi.cpp.
|
extern |
Initializes and synchronizes Timers.
This function sets the correct pre-scaler and starts all required timers.
Timer 1 is used to trigger the fault multiplexing on overflow. Timer 3 is used, if EMULATE_HALL is set, to trigger the change in hall output on overflow. Timer 4 is used to generate PWM outputs for the gates and trigger the commutation tick counter and check if the motor is spinning on overflow. The overflow event interrupt for Timer 4 is set outside this function at the end of the main initialization function.
Definition at line 405 of file main.ino.
|
extern |
Current measurement (Register Value).
The most recent current measurement is stored in this variable.
The range is 0-1023.
This value is not scaled and represents the raw ADC register value. To obtain the scaled current value in amperes, you can use the formula:
\[ \text{Current (A)} = \frac{\text{REGISTER_VALUE} \times 0.004887586 \times 1000000}{\text{CURRENT_GAIN} \times \text{CURRENT_SENSE_RESISTOR}} \]
Where:
The NEVB-3INV-001-01 comes with a current op-amp with a gain factor of 50 and a current sense resistor of value 2 mΩ. This corresponds to approximately 0.049 amperes (A) per register value.
|
extern |
|
extern |
Gate voltage measurement (Register Value)
The most recent gate voltage measurement is stored in this variable.
The range is 0-1023.
This value is not scaled and represents the raw ADC register value. To obtain the scaled gate voltage in volts, you can use the formula:
\[ \text{Voltage (V)} = \frac{\text{REGISTER_VALUE} \times 0.004887586 \times (\text{GATE_RTOP} + \text{GATE_RBOTTOM})}{\text{GATE_RBOTTOM}} \]
Where:
NEVB-3INV-001-01 has a resistor divider with RTOP of 1 MΩ and RBOTTOM of 71.5 kΩ, so it corresponds to approximately 0.0732 volts (V) per register value.
|
extern |
The number of 'ticks' between two hall sensor changes (store).
This variable is used to store the number of 'ticks' between each hall sensor change. It is set to the value in commutationTicks before it is cleared when the hall sensor change occurs.
One 'tick' is one PWM period. The speed of the motor is inversely proportional to this value.
|
extern |
|
extern |
|
extern |
Array of SCPI commands.
This array contains the definitions of all SCPI commands that the system recognizes. Each command is defined with its pattern, callback function, and associated context. The array is stored in program memory (PROGMEM) to optimize memory usage.
Definition at line 504 of file scpi.cpp.
|
extern |
|
extern |
SCPI error queue data array.
Array for storing SCPI errors. Its size is defined by SCPI_ERROR_QUEUE_SIZE.
|
extern |
SCPI input buffer.
Array for storing incoming SCPI commands. Its size is defined by SCPI_INPUT_BUFFER_LENGTH.
|
extern |
SCPI interface structure.
This structure defines the callbacks for various SCPI interface operations like error handling, writing to an output, control functions, flushing the output, and resetting the interface.
Definition at line 651 of file scpi.cpp.