#include "conf_general.h"
#include "datatypes.h"
#include <stdbool.h>
Go to the source code of this file.
#define MCPWM_CMD_STOP_TIME 0 |
#define MCPWM_DEAD_TIME_CYCLES 100 |
#define MCPWM_DETECT_STOP_TIME 500 |
#define MCPWM_PID_TIME_K 0.001 |
#define MCPWM_RPM_TIMER_FREQ 1000000.0 |
#define MCPWM_SWITCH_FREQUENCY_DC_MOTOR 25000 |
#define MCPWM_SWITCH_FREQUENCY_MAX 40000 |
#define MCPWM_SWITCH_FREQUENCY_MIN 3000 |
void mcpwm_adc_inj_int_handler |
( |
void |
| ) |
|
void mcpwm_adc_int_handler |
( |
void * |
p, |
|
|
uint32_t |
flags |
|
) |
| |
void mcpwm_brake_now |
( |
void |
| ) |
|
Stop the motor and use braking.
float mcpwm_get_amp_hours |
( |
bool |
reset | ) |
|
Get the amount of amp hours drawn from the input source.
- Parameters
-
reset | If true, the counter will be reset after this call. |
- Returns
- The amount of amp hours drawn.
float mcpwm_get_amp_hours_charged |
( |
bool |
reset | ) |
|
Get the amount of amp hours fed back into the input source.
- Parameters
-
reset | If true, the counter will be reset after this call. |
- Returns
- The amount of amp hours fed back.
int mcpwm_get_comm_step |
( |
void |
| ) |
|
Get the electrical position (or commutation step) of the motor.
- Returns
- The current commutation step. Range [1 6]
float mcpwm_get_detect_pos |
( |
void |
| ) |
|
float mcpwm_get_duty_cycle_now |
( |
void |
| ) |
|
float mcpwm_get_duty_cycle_set |
( |
void |
| ) |
|
int mcpwm_get_hall_detect_result |
( |
int8_t * |
table | ) |
|
Get the current detected hall sensor table
- Parameters
-
table | Pointer to a table where the result should be stored |
- Returns
- 0: OK -1: Invalid hall sensor output -2: WS2811 enabled -3: Encoder enabled
float mcpwm_get_kv |
( |
void |
| ) |
|
Calculate the KV (RPM per volt) value for the motor. This function has to be used while the motor is moving. Note that the return value has to be divided by half the number of motor poles.
- Returns
- The KV value.
float mcpwm_get_kv_filtered |
( |
void |
| ) |
|
Calculate the FIR-filtered KV (RPM per volt) value for the motor. This function has to be used while the motor is moving. Note that the return value has to be divided by half the number of motor poles.
- Returns
- The filtered KV value.
float mcpwm_get_last_adc_isr_duration |
( |
void |
| ) |
|
float mcpwm_get_last_inj_adc_isr_duration |
( |
void |
| ) |
|
float mcpwm_get_min_rpm |
( |
void |
| ) |
|
Get the minimum allowed RPM in sensorless mode.
- Returns
- The minimum allowed RPM.
float mcpwm_get_rpm |
( |
void |
| ) |
|
Calculate the current RPM of the motor. This is a signed value and the sign depends on the direction the motor is rotating in. Note that this value has to be divided by half the number of motor poles.
- Returns
- The RPM value.
float mcpwm_get_switching_frequency_now |
( |
void |
| ) |
|
Get the current switching frequency.
- Returns
- The switching frequency in Hz.
int mcpwm_get_tachometer_abs_value |
( |
bool |
reset | ) |
|
Read the absolute number of steps the motor has rotated.
- Parameters
-
reset | If true, the tachometer counter will be reset after this call. |
- Returns
- The tachometer value in motor steps. The number of motor revolutions will be this number divided by (3 * MOTOR_POLE_NUMBER).
int mcpwm_get_tachometer_value |
( |
bool |
reset | ) |
|
Read the number of steps the motor has rotated. This number is signed and will return a negative number when the motor is rotating backwards.
- Parameters
-
reset | If true, the tachometer counter will be reset after this call. |
- Returns
- The tachometer value in motor steps. The number of motor revolutions will be this number divided by (3 * MOTOR_POLE_NUMBER).
float mcpwm_get_tot_current |
( |
void |
| ) |
|
Get the motor current. The sign of this value will represent whether the motor is drawing (positive) or generating (negative) current.
- Returns
- The motor current.
float mcpwm_get_tot_current_directional |
( |
void |
| ) |
|
Get the motor current. The sign of this value represents the direction in which the motor generates torque.
- Returns
- The motor current.
float mcpwm_get_tot_current_directional_filtered |
( |
void |
| ) |
|
Get the filtered motor current. The sign of this value represents the direction in which the motor generates torque.
- Returns
- The filtered motor current.
float mcpwm_get_tot_current_filtered |
( |
void |
| ) |
|
Get the FIR-filtered motor current. The sign of this value will represent whether the motor is drawing (positive) or generating (negative) current.
- Returns
- The filtered motor current.
float mcpwm_get_tot_current_in |
( |
void |
| ) |
|
Get the input current to the motor controller.
- Returns
- The input current.
float mcpwm_get_tot_current_in_filtered |
( |
void |
| ) |
|
Get the FIR-filtered input current to the motor controller.
- Returns
- The filtered input current.
float mcpwm_get_watt_hours |
( |
bool |
reset | ) |
|
Get the amount of watt hours drawn from the input source.
- Parameters
-
reset | If true, the counter will be reset after this call. |
- Returns
- The amount of watt hours drawn.
float mcpwm_get_watt_hours_charged |
( |
bool |
reset | ) |
|
Get the amount of watt hours fed back into the input source.
- Parameters
-
reset | If true, the counter will be reset after this call. |
- Returns
- The amount of watt hours fed back.
void mcpwm_init_hall_table |
( |
int8_t * |
table | ) |
|
Initialize the hall sensor lookup table
- Parameters
-
table | The commutations corresponding to the hall sensor states in the forward direction- |
Lock the control by disabling all control commands.
void mcpwm_lock_override_once |
( |
void |
| ) |
|
Allow just one motor control command in the locked state.
int mcpwm_read_hall_phase |
( |
void |
| ) |
|
Read the current phase of the motor using hall effect sensors
- Returns
- The phase read.
float mcpwm_read_reset_avg_cycle_integrator |
( |
void |
| ) |
|
float mcpwm_read_reset_avg_input_current |
( |
void |
| ) |
|
float mcpwm_read_reset_avg_motor_current |
( |
void |
| ) |
|
void mcpwm_release_motor |
( |
void |
| ) |
|
Disconnect the motor and let it turn freely.
void mcpwm_reset_hall_detect_table |
( |
void |
| ) |
|
Reset the hall sensor detection table
void mcpwm_set_brake_current |
( |
float |
current | ) |
|
Brake the motor with a desired current. Absolute values less than conf.cc_min_current will release the motor.
- Parameters
-
current | The current to use. Positive and negative values give the same effect. |
Set the commutation mode for sensorless commutation.
- Parameters
-
mode | COMM_MODE_INTEGRATE: More robust, but requires many parameters. COMM_MODE_DELAY: Like most hobby ESCs. Requires less parameters, but has worse startup and is less robust. |
void mcpwm_set_current |
( |
float |
current | ) |
|
Use current control and specify a goal current to use. The sign determines the direction of the torque. Absolute values less than conf.cc_min_current will release the motor.
- Parameters
-
current | The current to use. |
void mcpwm_set_detect |
( |
void |
| ) |
|
void mcpwm_set_duty |
( |
float |
dutyCycle | ) |
|
Use duty cycle control. Absolute values less than MCPWM_MIN_DUTY_CYCLE will stop the motor.
- Parameters
-
dutyCycle | The duty cycle to use. |
void mcpwm_set_min_rpm |
( |
float |
rpm | ) |
|
Set the minimum allowed RPM in sensorless mode. This will affect startup performance. WARNING: Setting this too high can break stuff.
- Parameters
-
rpm | The minimum allowed RPM. |
void mcpwm_set_pid_pos |
( |
float |
pos | ) |
|
Use PID position control. Note that this only works when encoder support is enabled.
- Parameters
-
pos | The desired position of the motor in degrees. |
void mcpwm_set_pid_speed |
( |
float |
rpm | ) |
|
Use PID rpm control. Note that this value has to be multiplied by half of the number of motor poles.
- Parameters
-
rpm | The electrical RPM goal value to use. |
void mcpwm_unlock |
( |
void |
| ) |
|
Unlock all control commands.
volatile int ADC_curr_norm_value[] |
volatile uint16_t ADC_Value[] |
volatile float mcpwm_detect_currents[] |
volatile float mcpwm_detect_currents_diff[] |
volatile float mcpwm_detect_voltages[] |