First implementation of DC motor support

This commit is contained in:
Benjamin Vedder 2015-04-12 18:23:17 +02:00
parent 2ccb52514e
commit bc0415c1bb
5 changed files with 511 additions and 386 deletions

View File

@ -169,6 +169,7 @@ void commands_process_packet(unsigned char *data, unsigned char len) {
ind = 0;
mcconf.pwm_mode = data[ind++];
mcconf.comm_mode = data[ind++];
mcconf.motor_type = data[ind++];
mcconf.l_current_max = (float)buffer_get_int32(data, &ind) / 1000.0;
mcconf.l_current_min = (float)buffer_get_int32(data, &ind) / 1000.0;
@ -229,6 +230,7 @@ void commands_process_packet(unsigned char *data, unsigned char len) {
send_buffer[ind++] = mcconf.pwm_mode;
send_buffer[ind++] = mcconf.comm_mode;
send_buffer[ind++] = mcconf.motor_type;
buffer_append_int32(send_buffer, (int32_t)(mcconf.l_current_max * 1000.0), &ind);
buffer_append_int32(send_buffer, (int32_t)(mcconf.l_current_min * 1000.0), &ind);

View File

@ -36,6 +36,9 @@
#endif
// Parameters that can be overridden
#ifndef MC_DEFAULT_MOTOR_TYPE
#define MC_DEFAULT_MOTOR_TYPE MOTOR_TYPE_BLDC
#endif
#ifndef MCPWM_PWM_MODE
#define MCPWM_PWM_MODE PWM_MODE_SYNCHRONOUS // Default PWM mode
#endif
@ -244,6 +247,7 @@ void conf_general_read_mc_configuration(mc_configuration *conf) {
if (!is_ok) {
conf->pwm_mode = MCPWM_PWM_MODE;
conf->comm_mode = MCPWM_COMM_MODE;
conf->motor_type = MC_DEFAULT_MOTOR_TYPE;
conf->l_current_max = MCPWM_CURRENT_MAX;
conf->l_current_min = MCPWM_CURRENT_MIN;

View File

@ -48,6 +48,11 @@ typedef enum {
COMM_MODE_DELAY
} mc_comm_mode;
typedef enum {
MOTOR_TYPE_BLDC = 0,
MOTOR_TYPE_DC,
} mc_motor_type;
typedef enum {
FAULT_CODE_NONE = 0,
FAULT_CODE_OVER_VOLTAGE,
@ -80,6 +85,7 @@ typedef struct {
// Switching and drive
mc_pwm_mode pwm_mode;
mc_comm_mode comm_mode;
mc_motor_type motor_type;
// Limits
float l_current_max;
float l_current_min;

884
mcpwm.c

File diff suppressed because it is too large Load Diff

View File

@ -92,6 +92,7 @@ extern volatile int mcpwm_vzero;
*/
#define MCPWM_SWITCH_FREQUENCY_MIN 3000 // The lowest switching frequency in Hz
#define MCPWM_SWITCH_FREQUENCY_MAX 35000 // The highest switching frequency in Hz
#define MCPWM_SWITCH_FREQUENCY_DC_MOTOR 25000 // The DC motor switching frequency
#define MCPWM_DEAD_TIME_CYCLES 80 // Dead time
#define MCPWM_RPM_TIMER_FREQ 1000000.0 // Frequency of the RPM measurement timer
#define MCPWM_MIN_DUTY_CYCLE 0.005 // Minimum duty cycle