mirror of https://github.com/rusefi/bldc.git
Merge pull request #1 from vedderb/master
FW 1.13: Hw 4.8 support, new CC implementation for nunchuk, refactori…
This commit is contained in:
commit
55d660cdb3
1
Makefile
1
Makefile
|
@ -155,6 +155,7 @@ INCDIR = $(PORTINC) $(KERNINC) \
|
||||||
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
|
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
|
||||||
$(CHIBIOS)/os/various \
|
$(CHIBIOS)/os/various \
|
||||||
mcconf \
|
mcconf \
|
||||||
|
appconf \
|
||||||
$(HWINC) \
|
$(HWINC) \
|
||||||
$(APPINC) \
|
$(APPINC) \
|
||||||
$(NRFINC)
|
$(NRFINC)
|
||||||
|
|
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 Benjamin Vedder benjamin@vedder.se
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPCONF_DEFAULT_H_
|
||||||
|
#define APPCONF_DEFAULT_H_
|
||||||
|
|
||||||
|
// Default app configuration
|
||||||
|
#ifndef APPCONF_CONTROLLER_ID
|
||||||
|
#define APPCONF_CONTROLLER_ID 0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_TIMEOUT_MSEC
|
||||||
|
#define APPCONF_TIMEOUT_MSEC 1000
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_TIMEOUT_BRAKE_CURRENT
|
||||||
|
#define APPCONF_TIMEOUT_BRAKE_CURRENT 0.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_SEND_CAN_STATUS
|
||||||
|
#define APPCONF_SEND_CAN_STATUS false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_SEND_CAN_STATUS_RATE_HZ
|
||||||
|
#define APPCONF_SEND_CAN_STATUS_RATE_HZ 500
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The default app is UART in case the UART port is used for
|
||||||
|
// firmware updates.
|
||||||
|
#ifndef APPCONF_APP_TO_USE
|
||||||
|
#define APPCONF_APP_TO_USE APP_UART
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// PPM app
|
||||||
|
#ifndef APPCONF_PPM_CTRL_TYPE
|
||||||
|
#define APPCONF_PPM_CTRL_TYPE PPM_CTRL_TYPE_NONE
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_PID_MAX_ERPM
|
||||||
|
#define APPCONF_PPM_PID_MAX_ERPM 15000
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_HYST
|
||||||
|
#define APPCONF_PPM_HYST 0.15
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_PULSE_START
|
||||||
|
#define APPCONF_PPM_PULSE_START 1.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_PULSE_END
|
||||||
|
#define APPCONF_PPM_PULSE_END 2.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_MEDIAN_FILTER
|
||||||
|
#define APPCONF_PPM_MEDIAN_FILTER true
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_SAFE_START
|
||||||
|
#define APPCONF_PPM_SAFE_START true
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_RPM_LIM_START
|
||||||
|
#define APPCONF_PPM_RPM_LIM_START 150000
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_RPM_LIM_END
|
||||||
|
#define APPCONF_PPM_RPM_LIM_END 200000
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_MULTI_ESC
|
||||||
|
#define APPCONF_PPM_MULTI_ESC false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_TC
|
||||||
|
#define APPCONF_PPM_TC false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_PPM_TC_MAX_DIFF
|
||||||
|
#define APPCONF_PPM_TC_MAX_DIFF 3000.0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ADC app configureation
|
||||||
|
#ifndef APPCONF_ADC_CTRL_TYPE
|
||||||
|
#define APPCONF_ADC_CTRL_TYPE ADC_CTRL_TYPE_NONE
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_HYST
|
||||||
|
#define APPCONF_ADC_HYST 0.15
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_VOLTAGE_START
|
||||||
|
#define APPCONF_ADC_VOLTAGE_START 0.9
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_VOLTAGE_END
|
||||||
|
#define APPCONF_ADC_VOLTAGE_END 3.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_USE_FILTER
|
||||||
|
#define APPCONF_ADC_USE_FILTER true
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_SAFE_START
|
||||||
|
#define APPCONF_ADC_SAFE_START true
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_CC_BUTTON_INVERTED
|
||||||
|
#define APPCONF_ADC_CC_BUTTON_INVERTED false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_REV_BUTTON_INVERTED
|
||||||
|
#define APPCONF_ADC_REV_BUTTON_INVERTED false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_VOLTAGE_INVERTED
|
||||||
|
#define APPCONF_ADC_VOLTAGE_INVERTED false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_RPM_LIM_START
|
||||||
|
#define APPCONF_ADC_RPM_LIM_START 150000.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_RPM_LIM_END
|
||||||
|
#define APPCONF_ADC_RPM_LIM_END 200000.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_MULTI_ESC
|
||||||
|
#define APPCONF_ADC_MULTI_ESC false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_TC
|
||||||
|
#define APPCONF_ADC_TC false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_TC_MAX_DIFF
|
||||||
|
#define APPCONF_ADC_TC_MAX_DIFF 3000.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_ADC_UPDATE_RATE_HZ
|
||||||
|
#define APPCONF_ADC_UPDATE_RATE_HZ 500
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// UART app
|
||||||
|
#ifndef APPCONF_UART_BAUDRATE
|
||||||
|
#define APPCONF_UART_BAUDRATE 115200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Nunchuk app
|
||||||
|
#ifndef APPCONF_CHUK_CTRL_TYPE
|
||||||
|
#define APPCONF_CHUK_CTRL_TYPE CHUK_CTRL_TYPE_CURRENT
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_HYST
|
||||||
|
#define APPCONF_CHUK_HYST 0.15
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_RPM_LIM_START
|
||||||
|
#define APPCONF_CHUK_RPM_LIM_START 150000.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_RPM_LIM_END
|
||||||
|
#define APPCONF_CHUK_RPM_LIM_END 200000.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_RAMP_TIME_POS
|
||||||
|
#define APPCONF_CHUK_RAMP_TIME_POS 0.9
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_RAMP_TIME_NEG
|
||||||
|
#define APPCONF_CHUK_RAMP_TIME_NEG 0.3
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_STICK_ERPM_PER_S_IN_CC
|
||||||
|
#define APPCONF_STICK_ERPM_PER_S_IN_CC 3000.0
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_MULTI_ESC
|
||||||
|
#define APPCONF_CHUK_MULTI_ESC false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_TC
|
||||||
|
#define APPCONF_CHUK_TC false
|
||||||
|
#endif
|
||||||
|
#ifndef APPCONF_CHUK_TC_MAX_DIFF
|
||||||
|
#define APPCONF_CHUK_TC_MAX_DIFF 3000.0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* APPCONF_DEFAULT_H_ */
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 Benjamin Vedder benjamin@vedder.se
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* appconf_example_ppm.h
|
||||||
|
*
|
||||||
|
* Created on: 9 sep 2015
|
||||||
|
* Author: benjamin
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef APPCONF_APPCONF_EXAMPLE_PPM_H_
|
||||||
|
#define APPCONF_APPCONF_EXAMPLE_PPM_H_
|
||||||
|
|
||||||
|
// Override app configuration parameters such that the PPM app becomes default
|
||||||
|
#define APPCONF_APP_TO_USE APP_PPM
|
||||||
|
#define APPCONF_PPM_CTRL_TYPE PPM_CTRL_TYPE_CURRENT_NOREV_BRAKE
|
||||||
|
|
||||||
|
#endif /* APPCONF_APPCONF_EXAMPLE_PPM_H_ */
|
|
@ -231,6 +231,7 @@ static msg_t output_thread(void *arg) {
|
||||||
|
|
||||||
// If c is pressed and no throttle is used, maintain the current speed with PID control
|
// If c is pressed and no throttle is used, maintain the current speed with PID control
|
||||||
static bool was_pid = false;
|
static bool was_pid = false;
|
||||||
|
const volatile mc_configuration *mcconf = mcpwm_get_configuration();
|
||||||
|
|
||||||
// Filter RPM to avoid glitches
|
// Filter RPM to avoid glitches
|
||||||
static float filter_buffer[RPM_FILTER_SAMPLES];
|
static float filter_buffer[RPM_FILTER_SAMPLES];
|
||||||
|
@ -246,18 +247,40 @@ static msg_t output_thread(void *arg) {
|
||||||
}
|
}
|
||||||
rpm_filtered /= RPM_FILTER_SAMPLES;
|
rpm_filtered /= RPM_FILTER_SAMPLES;
|
||||||
|
|
||||||
if (chuck_d.bt_c && out_val == 0.0) {
|
if (chuck_d.bt_c) {
|
||||||
static float pid_rpm = 0.0;
|
static float pid_rpm = 0.0;
|
||||||
|
|
||||||
if (!was_pid) {
|
if (!was_pid) {
|
||||||
was_pid = true;
|
|
||||||
pid_rpm = rpm_filtered;
|
pid_rpm = rpm_filtered;
|
||||||
|
|
||||||
|
if ((is_reverse && pid_rpm > 0.0) || (!is_reverse && pid_rpm < 0.0)) {
|
||||||
|
if (fabsf(pid_rpm) > mcconf->s_pid_min_erpm) {
|
||||||
|
// Abort if the speed is too high in the opposite direction
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
pid_rpm = 0.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((is_reverse && pid_rpm < 0.0) || (!is_reverse && pid_rpm > 0.0)) {
|
was_pid = true;
|
||||||
mcpwm_set_pid_speed(pid_rpm);
|
} else {
|
||||||
|
if (is_reverse) {
|
||||||
|
if (pid_rpm > 0.0) {
|
||||||
|
pid_rpm = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_rpm -= (out_val * config.stick_erpm_per_s_in_cc) / ((float)OUTPUT_ITERATION_TIME_MS * 1000.0);
|
||||||
|
} else {
|
||||||
|
if (pid_rpm < 0.0) {
|
||||||
|
pid_rpm = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_rpm += (out_val * config.stick_erpm_per_s_in_cc) / ((float)OUTPUT_ITERATION_TIME_MS * 1000.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mcpwm_set_pid_speed(pid_rpm);
|
||||||
|
|
||||||
// Send the same duty cycle to the other controllers
|
// Send the same duty cycle to the other controllers
|
||||||
if (config.multi_esc) {
|
if (config.multi_esc) {
|
||||||
float duty = mcpwm_get_duty_cycle_now();
|
float duty = mcpwm_get_duty_cycle_now();
|
||||||
|
@ -281,7 +304,6 @@ static msg_t output_thread(void *arg) {
|
||||||
was_pid = false;
|
was_pid = false;
|
||||||
|
|
||||||
float current = 0;
|
float current = 0;
|
||||||
const volatile mc_configuration *mcconf = mcpwm_get_configuration();
|
|
||||||
|
|
||||||
if (out_val >= 0.0) {
|
if (out_val >= 0.0) {
|
||||||
current = out_val * mcconf->l_current_max;
|
current = out_val * mcconf->l_current_max;
|
||||||
|
|
28
commands.c
28
commands.c
|
@ -276,7 +276,7 @@ void commands_process_packet(unsigned char *data, unsigned int len) {
|
||||||
mcconf.s_pid_kp = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
mcconf.s_pid_kp = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
||||||
mcconf.s_pid_ki = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
mcconf.s_pid_ki = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
||||||
mcconf.s_pid_kd = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
mcconf.s_pid_kd = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
||||||
mcconf.s_pid_min_rpm = (float)buffer_get_int32(data, &ind) / 1000.0;
|
mcconf.s_pid_min_erpm = (float)buffer_get_int32(data, &ind) / 1000.0;
|
||||||
|
|
||||||
mcconf.p_pid_kp = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
mcconf.p_pid_kp = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
||||||
mcconf.p_pid_ki = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
mcconf.p_pid_ki = (float)buffer_get_int32(data, &ind) / 1000000.0;
|
||||||
|
@ -348,7 +348,7 @@ void commands_process_packet(unsigned char *data, unsigned int len) {
|
||||||
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_kp * 1000000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_kp * 1000000.0), &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_ki * 1000000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_ki * 1000000.0), &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_kd * 1000000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_kd * 1000000.0), &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_min_rpm * 1000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(mcconf.s_pid_min_erpm * 1000.0), &ind);
|
||||||
|
|
||||||
buffer_append_int32(send_buffer, (int32_t)(mcconf.p_pid_kp * 1000000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(mcconf.p_pid_kp * 1000000.0), &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(mcconf.p_pid_ki * 1000000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(mcconf.p_pid_ki * 1000000.0), &ind);
|
||||||
|
@ -411,14 +411,15 @@ void commands_process_packet(unsigned char *data, unsigned int len) {
|
||||||
appconf.app_uart_baudrate = buffer_get_uint32(data, &ind);
|
appconf.app_uart_baudrate = buffer_get_uint32(data, &ind);
|
||||||
|
|
||||||
appconf.app_chuk_conf.ctrl_type = data[ind++];
|
appconf.app_chuk_conf.ctrl_type = data[ind++];
|
||||||
appconf.app_chuk_conf.hyst = (float)buffer_get_int32(data, &ind) / 1000.0;
|
appconf.app_chuk_conf.hyst = buffer_get_float32(data, 1000.0, &ind);
|
||||||
appconf.app_chuk_conf.rpm_lim_start = (float)buffer_get_int32(data, &ind) / 1000.0;
|
appconf.app_chuk_conf.rpm_lim_start = buffer_get_float32(data, 1000.0, &ind);
|
||||||
appconf.app_chuk_conf.rpm_lim_end = (float)buffer_get_int32(data, &ind) / 1000.0;
|
appconf.app_chuk_conf.rpm_lim_end = buffer_get_float32(data, 1000.0, &ind);
|
||||||
appconf.app_chuk_conf.ramp_time_pos = (float)buffer_get_int32(data, &ind) / 1000.0;
|
appconf.app_chuk_conf.ramp_time_pos = buffer_get_float32(data, 1000.0, &ind);
|
||||||
appconf.app_chuk_conf.ramp_time_neg = (float)buffer_get_int32(data, &ind) / 1000.0;
|
appconf.app_chuk_conf.ramp_time_neg = buffer_get_float32(data, 1000.0, &ind);
|
||||||
|
appconf.app_chuk_conf.stick_erpm_per_s_in_cc = buffer_get_float32(data, 1000.0, &ind);
|
||||||
appconf.app_chuk_conf.multi_esc = data[ind++];
|
appconf.app_chuk_conf.multi_esc = data[ind++];
|
||||||
appconf.app_chuk_conf.tc = data[ind++];
|
appconf.app_chuk_conf.tc = data[ind++];
|
||||||
appconf.app_chuk_conf.tc_max_diff = (float)buffer_get_int32(data, &ind) / 1000.0;
|
appconf.app_chuk_conf.tc_max_diff = buffer_get_float32(data, 1000.0, &ind);
|
||||||
|
|
||||||
conf_general_store_app_configuration(&appconf);
|
conf_general_store_app_configuration(&appconf);
|
||||||
app_set_configuration(&appconf);
|
app_set_configuration(&appconf);
|
||||||
|
@ -474,11 +475,12 @@ void commands_process_packet(unsigned char *data, unsigned int len) {
|
||||||
buffer_append_uint32(send_buffer, appconf.app_uart_baudrate, &ind);
|
buffer_append_uint32(send_buffer, appconf.app_uart_baudrate, &ind);
|
||||||
|
|
||||||
send_buffer[ind++] = appconf.app_chuk_conf.ctrl_type;
|
send_buffer[ind++] = appconf.app_chuk_conf.ctrl_type;
|
||||||
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.hyst * 1000.0), &ind);
|
buffer_append_float32(send_buffer, appconf.app_chuk_conf.hyst, 1000.0, &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.rpm_lim_start * 1000.0), &ind);
|
buffer_append_float32(send_buffer, appconf.app_chuk_conf.rpm_lim_start, 1000.0, &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.rpm_lim_end * 1000.0), &ind);
|
buffer_append_float32(send_buffer, appconf.app_chuk_conf.rpm_lim_end, 1000.0, &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.ramp_time_pos * 1000.0), &ind);
|
buffer_append_float32(send_buffer, appconf.app_chuk_conf.ramp_time_pos, 1000.0, &ind);
|
||||||
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.ramp_time_neg * 1000.0), &ind);
|
buffer_append_float32(send_buffer, appconf.app_chuk_conf.ramp_time_neg, 1000.0, &ind);
|
||||||
|
buffer_append_float32(send_buffer, appconf.app_chuk_conf.stick_erpm_per_s_in_cc, 1000.0, &ind);
|
||||||
send_buffer[ind++] = appconf.app_chuk_conf.multi_esc;
|
send_buffer[ind++] = appconf.app_chuk_conf.multi_esc;
|
||||||
send_buffer[ind++] = appconf.app_chuk_conf.tc;
|
send_buffer[ind++] = appconf.app_chuk_conf.tc;
|
||||||
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.tc_max_diff * 1000.0), &ind);
|
buffer_append_int32(send_buffer, (int32_t)(appconf.app_chuk_conf.tc_max_diff * 1000.0), &ind);
|
||||||
|
|
329
conf_general.c
329
conf_general.c
|
@ -14,126 +14,20 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// Default configuration file
|
// User defined default motor configuration file
|
||||||
#ifdef MCCONF_OUTRUNNER1
|
#ifdef MCCONF_DEFAULT_USER
|
||||||
#include "mcconf_outrunner1.h"
|
#include MCCONF_DEFAULT_USER
|
||||||
#elif defined MCCONF_OUTRUNNER2
|
|
||||||
#include "mcconf_outrunner2.h"
|
|
||||||
#elif defined MCCONF_STEN
|
|
||||||
#include "mcconf_sten.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Parameters that can be overridden
|
// User defined default app configuration file
|
||||||
#ifndef MC_DEFAULT_MOTOR_TYPE
|
#ifdef APPCONF_DEFAULT_USER
|
||||||
#define MC_DEFAULT_MOTOR_TYPE MOTOR_TYPE_BLDC
|
#include APPCONF_DEFAULT_USER
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_PWM_MODE
|
|
||||||
#define MCPWM_PWM_MODE PWM_MODE_SYNCHRONOUS // Default PWM mode
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_MIN_VOLTAGE
|
|
||||||
#define MCPWM_MIN_VOLTAGE 8.0 // Minimum input voltage
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_MAX_VOLTAGE
|
|
||||||
#define MCPWM_MAX_VOLTAGE 50.0 // Maximum input voltage
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_BATTERY_CUT_START
|
|
||||||
#define MCPWM_BATTERY_CUT_START 10.0 // Start limiting the positive current at this voltage
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_BATTERY_CUT_END
|
|
||||||
#define MCPWM_BATTERY_CUT_END 8.0 // Limit the positive current completely at this voltage
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_RPM_MAX
|
|
||||||
#define MCPWM_RPM_MAX 100000.0 // The motor speed limit (Upper)
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_RPM_MIN
|
|
||||||
#define MCPWM_RPM_MIN -100000.0 // The motor speed limit (Lower)
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_CURRENT_STARTUP_BOOST
|
|
||||||
#define MCPWM_CURRENT_STARTUP_BOOST 0.01 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE)
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_RPM_LIMIT_NEG_TORQUE
|
|
||||||
#define MCPWM_RPM_LIMIT_NEG_TORQUE true // Use negative torque to limit the RPM
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_CURR_MAX_RPM_FBRAKE
|
|
||||||
#define MCPWM_CURR_MAX_RPM_FBRAKE 300 // Maximum electrical RPM to use full brake at
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_CURR_MAX_RPM_FBRAKE_CC
|
|
||||||
#define MCPWM_CURR_MAX_RPM_FBRAKE_CC 1500 // Maximum electrical RPM to use full brake at with current control
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_SLOW_ABS_OVERCURRENT
|
|
||||||
#define MCPWM_SLOW_ABS_OVERCURRENT false // Use the filtered (and hence slower) current for the overcurrent fault detection
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_COMM_MODE
|
|
||||||
#define MCPWM_COMM_MODE COMM_MODE_INTEGRATE // The commutation mode to use
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_CYCLE_INT_LIMIT_HIGH_FAC
|
|
||||||
#define MCPWM_CYCLE_INT_LIMIT_HIGH_FAC 0.8 // Flux integrator limit percentage at MCPWM_CYCLE_INT_START_RPM_BR ERPM
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_CYCLE_INT_START_RPM_BR
|
|
||||||
#define MCPWM_CYCLE_INT_START_RPM_BR 80000.0 // RPM border between the START and LOW interval
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_FAULT_STOP_TIME
|
|
||||||
#define MCPWM_FAULT_STOP_TIME 3000 // Ignore commands for this duration in msec when faults occur
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_LIM_TEMP_FET_START
|
|
||||||
#define MCPWM_LIM_TEMP_FET_START 80.0 // MOSFET temperature where current limiting should begin
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_LIM_TEMP_FET_END
|
|
||||||
#define MCPWM_LIM_TEMP_FET_END 100.0 // MOSFET temperature where everything should be shut off
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_LIM_TEMP_MOTOR_START
|
|
||||||
#define MCPWM_LIM_TEMP_MOTOR_START 80.0 // MOTOR temperature where current limiting should begin
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_LIM_TEMP_MOTOR_END
|
|
||||||
#define MCPWM_LIM_TEMP_MOTOR_END 100.0 // MOTOR temperature where everything should be shut off
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_MAX_FB_CURR_DIR_CHANGE
|
|
||||||
#define MCPWM_MAX_FB_CURR_DIR_CHANGE 10.0 // Maximum current during full brake during which a direction change is allowed
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_MIN_DUTY
|
|
||||||
#define MCPWM_MIN_DUTY 0.005 // Minimum duty cycle
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_MAX_DUTY
|
|
||||||
#define MCPWM_MAX_DUTY 0.95 // Maximum duty cycle
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_RAMP_STEP
|
|
||||||
#define MCPWM_RAMP_STEP 0.02 // Ramping step (1000 times/sec) at maximum duty cycle
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_RAMP_STEP_RPM_LIMIT
|
|
||||||
#define MCPWM_RAMP_STEP_RPM_LIMIT 0.0005 // Ramping step when limiting the RPM
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_CURRENT_LIMIT_GAIN
|
|
||||||
#define MCPWM_CURRENT_LIMIT_GAIN 0.5 // The error gain of the current limiting algorithm
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_ERPM
|
|
||||||
#define MCPWM_HALL_ERPM 2000.0 // ERPM above which sensorless commutation is used in hybrid mode
|
|
||||||
#endif
|
|
||||||
// Default hall sensor table
|
|
||||||
#ifndef MCPWM_HALL_TAB_0
|
|
||||||
#define MCPWM_HALL_TAB_0 -1
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_1
|
|
||||||
#define MCPWM_HALL_TAB_1 1
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_2
|
|
||||||
#define MCPWM_HALL_TAB_2 3
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_3
|
|
||||||
#define MCPWM_HALL_TAB_3 2
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_4
|
|
||||||
#define MCPWM_HALL_TAB_4 5
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_5
|
|
||||||
#define MCPWM_HALL_TAB_5 6
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_6
|
|
||||||
#define MCPWM_HALL_TAB_6 4
|
|
||||||
#endif
|
|
||||||
#ifndef MCPWM_HALL_TAB_7
|
|
||||||
#define MCPWM_HALL_TAB_7 -1
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Default configuration parameters that can be overridden
|
||||||
|
#include "mcconf_default.h"
|
||||||
|
#include "appconf_default.h"
|
||||||
|
|
||||||
// EEPROM settings
|
// EEPROM settings
|
||||||
#define EEPROM_BASE_MCCONF 1000
|
#define EEPROM_BASE_MCCONF 1000
|
||||||
#define EEPROM_BASE_APPCONF 2000
|
#define EEPROM_BASE_APPCONF 2000
|
||||||
|
@ -154,9 +48,9 @@ void conf_general_init(void) {
|
||||||
VirtAddVarTab[ind++] = EEPROM_BASE_APPCONF + i;
|
VirtAddVarTab[ind++] = EEPROM_BASE_APPCONF + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FLASH_Unlock();
|
||||||
FLASH_ClearFlag(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
|
FLASH_ClearFlag(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
|
||||||
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||||
FLASH_Unlock();
|
|
||||||
EE_Init();
|
EE_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,56 +78,55 @@ void conf_general_read_app_configuration(app_configuration *conf) {
|
||||||
// Set the default configuration
|
// Set the default configuration
|
||||||
if (!is_ok) {
|
if (!is_ok) {
|
||||||
memset(conf, 0, sizeof(app_configuration));
|
memset(conf, 0, sizeof(app_configuration));
|
||||||
conf->controller_id = 0;
|
conf->controller_id = APPCONF_CONTROLLER_ID;
|
||||||
conf->timeout_msec = 1000;
|
conf->timeout_msec = APPCONF_TIMEOUT_MSEC;
|
||||||
conf->timeout_brake_current = 0.0;
|
conf->timeout_brake_current = APPCONF_TIMEOUT_BRAKE_CURRENT;
|
||||||
conf->send_can_status = false;
|
conf->send_can_status = APPCONF_SEND_CAN_STATUS;
|
||||||
conf->send_can_status_rate_hz = 500;
|
conf->send_can_status_rate_hz = APPCONF_SEND_CAN_STATUS_RATE_HZ;
|
||||||
|
|
||||||
// The default app is UART in case the UART port is used for
|
conf->app_to_use = APPCONF_APP_TO_USE;
|
||||||
// firmware updates.
|
|
||||||
conf->app_to_use = APP_UART;
|
|
||||||
|
|
||||||
conf->app_ppm_conf.ctrl_type = PPM_CTRL_TYPE_NONE;
|
conf->app_ppm_conf.ctrl_type = APPCONF_PPM_CTRL_TYPE;
|
||||||
conf->app_ppm_conf.pid_max_erpm = 15000;
|
conf->app_ppm_conf.pid_max_erpm = APPCONF_PPM_PID_MAX_ERPM;
|
||||||
conf->app_ppm_conf.hyst = 0.15;
|
conf->app_ppm_conf.hyst = APPCONF_PPM_HYST;
|
||||||
conf->app_ppm_conf.pulse_start = 1.0;
|
conf->app_ppm_conf.pulse_start = APPCONF_PPM_PULSE_START;
|
||||||
conf->app_ppm_conf.pulse_end = 2.0;
|
conf->app_ppm_conf.pulse_end = APPCONF_PPM_PULSE_END;
|
||||||
conf->app_ppm_conf.median_filter = false;
|
conf->app_ppm_conf.median_filter = APPCONF_PPM_MEDIAN_FILTER;
|
||||||
conf->app_ppm_conf.safe_start = true;
|
conf->app_ppm_conf.safe_start = APPCONF_PPM_SAFE_START;
|
||||||
conf->app_ppm_conf.rpm_lim_start = 150000.0;
|
conf->app_ppm_conf.rpm_lim_start = APPCONF_PPM_RPM_LIM_START;
|
||||||
conf->app_ppm_conf.rpm_lim_end = 200000.0;
|
conf->app_ppm_conf.rpm_lim_end = APPCONF_PPM_RPM_LIM_END;
|
||||||
conf->app_ppm_conf.multi_esc = false;
|
conf->app_ppm_conf.multi_esc = APPCONF_PPM_MULTI_ESC;
|
||||||
conf->app_ppm_conf.tc = false;
|
conf->app_ppm_conf.tc = APPCONF_PPM_TC;
|
||||||
conf->app_ppm_conf.tc_max_diff = 3000.0;
|
conf->app_ppm_conf.tc_max_diff = APPCONF_PPM_TC_MAX_DIFF;
|
||||||
|
|
||||||
conf->app_adc_conf.ctrl_type = ADC_CTRL_TYPE_NONE;
|
conf->app_adc_conf.ctrl_type = APPCONF_ADC_CTRL_TYPE;
|
||||||
conf->app_adc_conf.hyst = 0.15;
|
conf->app_adc_conf.hyst = APPCONF_ADC_HYST;
|
||||||
conf->app_adc_conf.voltage_start = 0.9;
|
conf->app_adc_conf.voltage_start = APPCONF_ADC_VOLTAGE_START;
|
||||||
conf->app_adc_conf.voltage_end = 3.0;
|
conf->app_adc_conf.voltage_end = APPCONF_ADC_VOLTAGE_END;
|
||||||
conf->app_adc_conf.use_filter = true;
|
conf->app_adc_conf.use_filter = APPCONF_ADC_USE_FILTER;
|
||||||
conf->app_adc_conf.safe_start = true;
|
conf->app_adc_conf.safe_start = APPCONF_ADC_SAFE_START;
|
||||||
conf->app_adc_conf.cc_button_inverted = false;
|
conf->app_adc_conf.cc_button_inverted = APPCONF_ADC_CC_BUTTON_INVERTED;
|
||||||
conf->app_adc_conf.rev_button_inverted = false;
|
conf->app_adc_conf.rev_button_inverted = APPCONF_ADC_REV_BUTTON_INVERTED;
|
||||||
conf->app_adc_conf.voltage_inverted = false;
|
conf->app_adc_conf.voltage_inverted = APPCONF_ADC_VOLTAGE_INVERTED;
|
||||||
conf->app_adc_conf.rpm_lim_start = 150000;
|
conf->app_adc_conf.rpm_lim_start = APPCONF_ADC_RPM_LIM_START;
|
||||||
conf->app_adc_conf.rpm_lim_end = 200000;
|
conf->app_adc_conf.rpm_lim_end = APPCONF_ADC_RPM_LIM_END;
|
||||||
conf->app_adc_conf.multi_esc = false;
|
conf->app_adc_conf.multi_esc = APPCONF_ADC_MULTI_ESC;
|
||||||
conf->app_adc_conf.tc = false;
|
conf->app_adc_conf.tc = APPCONF_ADC_TC;
|
||||||
conf->app_adc_conf.tc_max_diff = 3000.0;
|
conf->app_adc_conf.tc_max_diff = APPCONF_ADC_TC_MAX_DIFF;
|
||||||
conf->app_adc_conf.update_rate_hz = 500;
|
conf->app_adc_conf.update_rate_hz = APPCONF_ADC_UPDATE_RATE_HZ;
|
||||||
|
|
||||||
conf->app_uart_baudrate = 115200;
|
conf->app_uart_baudrate = APPCONF_UART_BAUDRATE;
|
||||||
|
|
||||||
conf->app_chuk_conf.ctrl_type = CHUK_CTRL_TYPE_CURRENT;
|
conf->app_chuk_conf.ctrl_type = APPCONF_CHUK_CTRL_TYPE;
|
||||||
conf->app_chuk_conf.hyst = 0.15;
|
conf->app_chuk_conf.hyst = APPCONF_CHUK_HYST;
|
||||||
conf->app_chuk_conf.rpm_lim_start = 150000.0;
|
conf->app_chuk_conf.rpm_lim_start = APPCONF_CHUK_RPM_LIM_START;
|
||||||
conf->app_chuk_conf.rpm_lim_end = 250000.0;
|
conf->app_chuk_conf.rpm_lim_end = APPCONF_CHUK_RPM_LIM_END;
|
||||||
conf->app_chuk_conf.ramp_time_pos = 0.9;
|
conf->app_chuk_conf.ramp_time_pos = APPCONF_CHUK_RAMP_TIME_POS;
|
||||||
conf->app_chuk_conf.ramp_time_neg = 0.3;
|
conf->app_chuk_conf.ramp_time_neg = APPCONF_CHUK_RAMP_TIME_NEG;
|
||||||
conf->app_chuk_conf.multi_esc = true;
|
conf->app_chuk_conf.stick_erpm_per_s_in_cc = APPCONF_STICK_ERPM_PER_S_IN_CC;
|
||||||
conf->app_chuk_conf.tc = false;
|
conf->app_chuk_conf.multi_esc = APPCONF_CHUK_MULTI_ESC;
|
||||||
conf->app_chuk_conf.tc_max_diff = 3000.0;
|
conf->app_chuk_conf.tc = APPCONF_CHUK_TC;
|
||||||
|
conf->app_chuk_conf.tc_max_diff = APPCONF_CHUK_TC_MAX_DIFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,74 +188,74 @@ void conf_general_read_mc_configuration(mc_configuration *conf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_ok) {
|
if (!is_ok) {
|
||||||
conf->pwm_mode = MCPWM_PWM_MODE;
|
conf->pwm_mode = MCCONF_PWM_MODE;
|
||||||
conf->comm_mode = MCPWM_COMM_MODE;
|
conf->comm_mode = MCCONF_COMM_MODE;
|
||||||
conf->motor_type = MC_DEFAULT_MOTOR_TYPE;
|
conf->motor_type = MCCONF_DEFAULT_MOTOR_TYPE;
|
||||||
conf->sensor_mode = MCPWM_SENSOR_MODE;
|
conf->sensor_mode = MCCONF_SENSOR_MODE;
|
||||||
|
|
||||||
conf->l_current_max = MCPWM_CURRENT_MAX;
|
conf->l_current_max = MCCONF_L_CURRENT_MAX;
|
||||||
conf->l_current_min = MCPWM_CURRENT_MIN;
|
conf->l_current_min = MCCONF_L_CURRENT_MIN;
|
||||||
conf->l_in_current_max = MCPWM_IN_CURRENT_MAX;
|
conf->l_in_current_max = MCCONF_L_IN_CURRENT_MAX;
|
||||||
conf->l_in_current_min = MCPWM_IN_CURRENT_MIN;
|
conf->l_in_current_min = MCCONF_L_IN_CURRENT_MIN;
|
||||||
conf->l_abs_current_max = MCPWM_MAX_ABS_CURRENT;
|
conf->l_abs_current_max = MCCONF_L_MAX_ABS_CURRENT;
|
||||||
conf->l_min_erpm = MCPWM_RPM_MIN;
|
conf->l_min_erpm = MCCONF_L_RPM_MIN;
|
||||||
conf->l_max_erpm = MCPWM_RPM_MAX;
|
conf->l_max_erpm = MCCONF_L_RPM_MAX;
|
||||||
conf->l_max_erpm_fbrake = MCPWM_CURR_MAX_RPM_FBRAKE;
|
conf->l_max_erpm_fbrake = MCCONF_L_CURR_MAX_RPM_FBRAKE;
|
||||||
conf->l_max_erpm_fbrake_cc = MCPWM_CURR_MAX_RPM_FBRAKE_CC;
|
conf->l_max_erpm_fbrake_cc = MCCONF_L_CURR_MAX_RPM_FBRAKE_CC;
|
||||||
conf->l_min_vin = MCPWM_MIN_VOLTAGE;
|
conf->l_min_vin = MCCONF_L_MIN_VOLTAGE;
|
||||||
conf->l_max_vin = MCPWM_MAX_VOLTAGE;
|
conf->l_max_vin = MCCONF_L_MAX_VOLTAGE;
|
||||||
conf->l_battery_cut_start = MCPWM_BATTERY_CUT_START;
|
conf->l_battery_cut_start = MCCONF_L_BATTERY_CUT_START;
|
||||||
conf->l_battery_cut_end = MCPWM_BATTERY_CUT_END;
|
conf->l_battery_cut_end = MCCONF_L_BATTERY_CUT_END;
|
||||||
conf->l_slow_abs_current = MCPWM_SLOW_ABS_OVERCURRENT;
|
conf->l_slow_abs_current = MCCONF_L_SLOW_ABS_OVERCURRENT;
|
||||||
conf->l_rpm_lim_neg_torque = MCPWM_RPM_LIMIT_NEG_TORQUE;
|
conf->l_rpm_lim_neg_torque = MCCONF_L_RPM_LIMIT_NEG_TORQUE;
|
||||||
conf->l_temp_fet_start = MCPWM_LIM_TEMP_FET_START;
|
conf->l_temp_fet_start = MCCONF_L_LIM_TEMP_FET_START;
|
||||||
conf->l_temp_fet_end = MCPWM_LIM_TEMP_FET_END;
|
conf->l_temp_fet_end = MCCONF_L_LIM_TEMP_FET_END;
|
||||||
conf->l_temp_motor_start = MCPWM_LIM_TEMP_MOTOR_START;
|
conf->l_temp_motor_start = MCCONF_L_LIM_TEMP_MOTOR_START;
|
||||||
conf->l_temp_motor_end = MCPWM_LIM_TEMP_MOTOR_END;
|
conf->l_temp_motor_end = MCCONF_L_LIM_TEMP_MOTOR_END;
|
||||||
conf->l_min_duty = MCPWM_MIN_DUTY;
|
conf->l_min_duty = MCCONF_L_MIN_DUTY;
|
||||||
conf->l_max_duty = MCPWM_MAX_DUTY;
|
conf->l_max_duty = MCCONF_L_MAX_DUTY;
|
||||||
|
|
||||||
conf->lo_current_max = conf->l_current_max;
|
conf->lo_current_max = conf->l_current_max;
|
||||||
conf->lo_current_min = conf->l_current_min;
|
conf->lo_current_min = conf->l_current_min;
|
||||||
conf->lo_in_current_max = conf->l_in_current_max;
|
conf->lo_in_current_max = conf->l_in_current_max;
|
||||||
conf->lo_in_current_min = conf->l_in_current_min;
|
conf->lo_in_current_min = conf->l_in_current_min;
|
||||||
|
|
||||||
conf->sl_min_erpm = MCPWM_MIN_RPM;
|
conf->sl_min_erpm = MCCONF_SL_MIN_RPM;
|
||||||
conf->sl_max_fullbreak_current_dir_change = MCPWM_MAX_FB_CURR_DIR_CHANGE;
|
conf->sl_max_fullbreak_current_dir_change = MCCONF_SL_MAX_FB_CURR_DIR_CHANGE;
|
||||||
conf->sl_min_erpm_cycle_int_limit = MCPWM_CYCLE_INT_LIMIT_MIN_RPM;
|
conf->sl_min_erpm_cycle_int_limit = MCCONF_SL_MIN_ERPM_CYCLE_INT_LIMIT;
|
||||||
conf->sl_cycle_int_limit = MCPWM_CYCLE_INT_LIMIT;
|
conf->sl_cycle_int_limit = MCCONF_SL_CYCLE_INT_LIMIT;
|
||||||
conf->sl_phase_advance_at_br = MCPWM_CYCLE_INT_LIMIT_HIGH_FAC;
|
conf->sl_phase_advance_at_br = MCCONF_SL_PHASE_ADVANCE_AT_BR;
|
||||||
conf->sl_cycle_int_rpm_br = MCPWM_CYCLE_INT_START_RPM_BR;
|
conf->sl_cycle_int_rpm_br = MCCONF_SL_CYCLE_INT_BR;
|
||||||
conf->sl_bemf_coupling_k = MCPWM_BEMF_INPUT_COUPLING_K;
|
conf->sl_bemf_coupling_k = MCCONF_SL_BEMF_COUPLING_K;
|
||||||
|
|
||||||
conf->hall_table[0] = MCPWM_HALL_TAB_0;
|
conf->hall_table[0] = MCCONF_HALL_TAB_0;
|
||||||
conf->hall_table[1] = MCPWM_HALL_TAB_1;
|
conf->hall_table[1] = MCCONF_HALL_TAB_1;
|
||||||
conf->hall_table[2] = MCPWM_HALL_TAB_2;
|
conf->hall_table[2] = MCCONF_HALL_TAB_2;
|
||||||
conf->hall_table[3] = MCPWM_HALL_TAB_3;
|
conf->hall_table[3] = MCCONF_HALL_TAB_3;
|
||||||
conf->hall_table[4] = MCPWM_HALL_TAB_4;
|
conf->hall_table[4] = MCCONF_HALL_TAB_4;
|
||||||
conf->hall_table[5] = MCPWM_HALL_TAB_5;
|
conf->hall_table[5] = MCCONF_HALL_TAB_5;
|
||||||
conf->hall_table[6] = MCPWM_HALL_TAB_6;
|
conf->hall_table[6] = MCCONF_HALL_TAB_6;
|
||||||
conf->hall_table[7] = MCPWM_HALL_TAB_7;
|
conf->hall_table[7] = MCCONF_HALL_TAB_7;
|
||||||
conf->hall_sl_erpm = MCPWM_HALL_ERPM;
|
conf->hall_sl_erpm = MCCONF_HALL_ERPM;
|
||||||
|
|
||||||
conf->s_pid_kp = MCPWM_PID_KP;
|
conf->s_pid_kp = MCCONF_S_PID_KP;
|
||||||
conf->s_pid_ki = MCPWM_PID_KI;
|
conf->s_pid_ki = MCCONF_S_PID_KI;
|
||||||
conf->s_pid_kd = MCPWM_PID_KD;
|
conf->s_pid_kd = MCCONF_S_PID_KD;
|
||||||
conf->s_pid_min_rpm = MCPWM_PID_MIN_RPM;
|
conf->s_pid_min_erpm = MCCONF_S_PID_MIN_RPM;
|
||||||
|
|
||||||
conf->p_pid_kp = MCPWM_P_PID_KP;
|
conf->p_pid_kp = MCCONF_P_PID_KP;
|
||||||
conf->p_pid_ki = MCPWM_P_PID_KI;
|
conf->p_pid_ki = MCCONF_P_PID_KI;
|
||||||
conf->p_pid_kd = MCPWM_P_PID_KD;
|
conf->p_pid_kd = MCCONF_P_PID_KD;
|
||||||
|
|
||||||
conf->cc_startup_boost_duty = MCPWM_CURRENT_STARTUP_BOOST;
|
conf->cc_startup_boost_duty = MCCONF_CC_STARTUP_BOOST_DUTY;
|
||||||
conf->cc_min_current = MCPWM_CURRENT_CONTROL_MIN;
|
conf->cc_min_current = MCCONF_CC_MIN_CURRENT;
|
||||||
conf->cc_gain = MCPWM_CURRENT_CONTROL_GAIN;
|
conf->cc_gain = MCCONF_CC_GAIN;
|
||||||
conf->cc_ramp_step_max = 0.04;
|
conf->cc_ramp_step_max = MCCONF_CC_RAMP_STEP;
|
||||||
|
|
||||||
conf->m_fault_stop_time_ms = MCPWM_FAULT_STOP_TIME;
|
conf->m_fault_stop_time_ms = MCCONF_M_FAULT_STOP_TIME;
|
||||||
conf->m_duty_ramp_step = MCPWM_RAMP_STEP;
|
conf->m_duty_ramp_step = MCCONF_M_RAMP_STEP;
|
||||||
conf->m_duty_ramp_step_rpm_lim = MCPWM_RAMP_STEP_RPM_LIMIT;
|
conf->m_duty_ramp_step_rpm_lim = MCCONF_M_RAMP_STEP_RPM_LIM;
|
||||||
conf->m_current_backoff_gain = MCPWM_CURRENT_LIMIT_GAIN;
|
conf->m_current_backoff_gain = MCCONF_M_CURRENT_BACKOFF_GAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
// Firmware version
|
// Firmware version
|
||||||
#define FW_VERSION_MAJOR 1
|
#define FW_VERSION_MAJOR 1
|
||||||
#define FW_VERSION_MINOR 12
|
#define FW_VERSION_MINOR 13
|
||||||
|
|
||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
#define AUTO_PRINT_FAULTS 0
|
#define AUTO_PRINT_FAULTS 0
|
||||||
#define SYSTEM_CORE_CLOCK 168000000
|
#define SYSTEM_CORE_CLOCK 168000000
|
||||||
|
|
||||||
// Component parameters to override
|
// Settings and parameters to override
|
||||||
//#define VIN_R1 33000.0
|
//#define VIN_R1 33000.0
|
||||||
//#define VIN_R2 2200.0
|
//#define VIN_R2 2200.0
|
||||||
//#define CURRENT_AMP_GAIN 10.0
|
//#define CURRENT_AMP_GAIN 10.0
|
||||||
|
@ -49,18 +49,26 @@
|
||||||
/*
|
/*
|
||||||
* Select only one hardware version
|
* Select only one hardware version
|
||||||
*/
|
*/
|
||||||
|
#if !defined(HW_VERSION_40) && !defined(HW_VERSION_45) && !defined(HW_VERSION_46) && \
|
||||||
|
!defined(HW_VERSION_48) && !defined(HW_VERSION_R2) && !defined(HW_VERSION_VICTOR_R1A)
|
||||||
//#define HW_VERSION_40
|
//#define HW_VERSION_40
|
||||||
//#define HW_VERSION_45
|
//#define HW_VERSION_45
|
||||||
#define HW_VERSION_46 // Also for 4.7
|
//#define HW_VERSION_46 // Also for 4.7
|
||||||
|
#define HW_VERSION_48
|
||||||
//#define HW_VERSION_R2
|
//#define HW_VERSION_R2
|
||||||
//#define HW_VERSION_VICTOR_R1A
|
//#define HW_VERSION_VICTOR_R1A
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select only one (default) motor configuration
|
* Select default user motor configuration
|
||||||
*/
|
*/
|
||||||
//#define MCCONF_OUTRUNNER1
|
//#define MCCONF_DEFAULT_USER "mcconf_outrunner2.h"
|
||||||
#define MCCONF_OUTRUNNER2
|
//#define MCCONF_DEFAULT_USER "mcconf_sten.h"
|
||||||
//#define MCCONF_STEN
|
|
||||||
|
/*
|
||||||
|
* Select default user app configuration
|
||||||
|
*/
|
||||||
|
//#define APPCONF_DEFAULT_USER "appconf_example_ppm.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select which custom application to use. To configure the default applications and
|
* Select which custom application to use. To configure the default applications and
|
||||||
|
@ -96,7 +104,7 @@
|
||||||
#define WS2811_ENABLE 0
|
#define WS2811_ENABLE 0
|
||||||
#endif
|
#endif
|
||||||
#define WS2811_CLK_HZ 800000
|
#define WS2811_CLK_HZ 800000
|
||||||
#define WS2811_LED_NUM 14
|
#define WS2811_LED_NUM 28
|
||||||
#define WS2811_USE_CH2 1 // 0: CH1 (PB6) 1: CH2 (PB7)
|
#define WS2811_USE_CH2 1 // 0: CH1 (PB6) 1: CH2 (PB7)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -136,7 +136,7 @@ typedef struct {
|
||||||
float s_pid_kp;
|
float s_pid_kp;
|
||||||
float s_pid_ki;
|
float s_pid_ki;
|
||||||
float s_pid_kd;
|
float s_pid_kd;
|
||||||
float s_pid_min_rpm;
|
float s_pid_min_erpm;
|
||||||
// Pos PID
|
// Pos PID
|
||||||
float p_pid_kp;
|
float p_pid_kp;
|
||||||
float p_pid_ki;
|
float p_pid_ki;
|
||||||
|
@ -238,6 +238,7 @@ typedef struct {
|
||||||
float rpm_lim_end;
|
float rpm_lim_end;
|
||||||
float ramp_time_pos;
|
float ramp_time_pos;
|
||||||
float ramp_time_neg;
|
float ramp_time_neg;
|
||||||
|
float stick_erpm_per_s_in_cc;
|
||||||
bool multi_esc;
|
bool multi_esc;
|
||||||
bool tc;
|
bool tc;
|
||||||
float tc_max_diff;
|
float tc_max_diff;
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include "hw_45.h"
|
#include "hw_45.h"
|
||||||
#elif defined HW_VERSION_46
|
#elif defined HW_VERSION_46
|
||||||
#include "hw_46.h"
|
#include "hw_46.h"
|
||||||
|
#elif defined HW_VERSION_48
|
||||||
|
#include "hw_48.h"
|
||||||
#elif defined HW_VERSION_R2
|
#elif defined HW_VERSION_R2
|
||||||
#include "hw_r2.h"
|
#include "hw_r2.h"
|
||||||
#elif defined HW_VERSION_BW
|
#elif defined HW_VERSION_BW
|
||||||
|
|
|
@ -175,4 +175,4 @@
|
||||||
#define READ_HALL2() palReadPad(HW_HALL_ENC_GPIO2, HW_HALL_ENC_PIN2)
|
#define READ_HALL2() palReadPad(HW_HALL_ENC_GPIO2, HW_HALL_ENC_PIN2)
|
||||||
#define READ_HALL3() palReadPad(HW_HALL_ENC_GPIO3, HW_HALL_ENC_PIN3)
|
#define READ_HALL3() palReadPad(HW_HALL_ENC_GPIO3, HW_HALL_ENC_PIN3)
|
||||||
|
|
||||||
#endif /* HW_40_H_ */
|
#endif /* HW_48_H_ */
|
||||||
|
|
|
@ -0,0 +1,245 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 Benjamin Vedder benjamin@vedder.se
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hw.h"
|
||||||
|
#ifdef HW_VERSION_48
|
||||||
|
|
||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
#include "stm32f4xx_conf.h"
|
||||||
|
#include "servo.h"
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
static volatile bool i2c_running = false;
|
||||||
|
|
||||||
|
// I2C configuration
|
||||||
|
static const I2CConfig i2cfg = {
|
||||||
|
OPMODE_I2C,
|
||||||
|
100000,
|
||||||
|
STD_DUTY_CYCLE
|
||||||
|
};
|
||||||
|
|
||||||
|
void hw_init_gpio(void) {
|
||||||
|
// GPIO clock enable
|
||||||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
||||||
|
|
||||||
|
// LEDs
|
||||||
|
palSetPadMode(GPIOC, 4,
|
||||||
|
PAL_MODE_OUTPUT_PUSHPULL |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST);
|
||||||
|
palSetPadMode(GPIOA, 7,
|
||||||
|
PAL_MODE_OUTPUT_PUSHPULL |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST);
|
||||||
|
|
||||||
|
// GPIOC (ENABLE_GATE)
|
||||||
|
palSetPadMode(GPIOC, 10,
|
||||||
|
PAL_MODE_OUTPUT_PUSHPULL |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST);
|
||||||
|
DISABLE_GATE();
|
||||||
|
|
||||||
|
// GPIOB (DCCAL)
|
||||||
|
palSetPadMode(GPIOB, 12,
|
||||||
|
PAL_MODE_OUTPUT_PUSHPULL |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST);
|
||||||
|
|
||||||
|
// GPIOA Configuration: Channel 1 to 3 as alternate function push-pull
|
||||||
|
palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(GPIO_AF_TIM1) |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST |
|
||||||
|
PAL_STM32_PUDR_FLOATING);
|
||||||
|
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(GPIO_AF_TIM1) |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST |
|
||||||
|
PAL_STM32_PUDR_FLOATING);
|
||||||
|
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(GPIO_AF_TIM1) |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST |
|
||||||
|
PAL_STM32_PUDR_FLOATING);
|
||||||
|
|
||||||
|
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(GPIO_AF_TIM1) |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST |
|
||||||
|
PAL_STM32_PUDR_FLOATING);
|
||||||
|
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(GPIO_AF_TIM1) |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST |
|
||||||
|
PAL_STM32_PUDR_FLOATING);
|
||||||
|
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(GPIO_AF_TIM1) |
|
||||||
|
PAL_STM32_OSPEED_HIGHEST |
|
||||||
|
PAL_STM32_PUDR_FLOATING);
|
||||||
|
|
||||||
|
// Hall sensors
|
||||||
|
palSetPadMode(HW_HALL_ENC_GPIO1, HW_HALL_ENC_PIN1, PAL_MODE_INPUT_PULLUP);
|
||||||
|
palSetPadMode(HW_HALL_ENC_GPIO2, HW_HALL_ENC_PIN2, PAL_MODE_INPUT_PULLUP);
|
||||||
|
palSetPadMode(HW_HALL_ENC_GPIO3, HW_HALL_ENC_PIN3, PAL_MODE_INPUT_PULLUP);
|
||||||
|
|
||||||
|
// Fault pin
|
||||||
|
palSetPadMode(GPIOC, 12, PAL_MODE_INPUT_PULLUP);
|
||||||
|
|
||||||
|
// ADC Pins
|
||||||
|
palSetPadMode(GPIOA, 0, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_ANALOG);
|
||||||
|
|
||||||
|
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_ANALOG);
|
||||||
|
|
||||||
|
palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOC, 3, PAL_MODE_INPUT_ANALOG);
|
||||||
|
palSetPadMode(GPIOC, 5, PAL_MODE_INPUT_ANALOG);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_setup_adc_channels(void) {
|
||||||
|
// ADC1 regular channels
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_Vrefint, 3, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_15Cycles);
|
||||||
|
|
||||||
|
// ADC2 regular channels
|
||||||
|
ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC2, ADC_Channel_6, 2, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC2, ADC_Channel_9, 3, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC2, ADC_Channel_15, 4, ADC_SampleTime_15Cycles);
|
||||||
|
|
||||||
|
// ADC3 regular channels
|
||||||
|
ADC_RegularChannelConfig(ADC3, ADC_Channel_2, 1, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC3, ADC_Channel_3, 2, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 3, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 4, ADC_SampleTime_15Cycles);
|
||||||
|
|
||||||
|
// Injected channels
|
||||||
|
ADC_InjectedChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_InjectedChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_InjectedChannelConfig(ADC2, ADC_Channel_5, 1, ADC_SampleTime_15Cycles);
|
||||||
|
ADC_InjectedChannelConfig(ADC2, ADC_Channel_6, 2, ADC_SampleTime_15Cycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_setup_servo_outputs(void) {
|
||||||
|
// Set up GPIO ports
|
||||||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||||
|
|
||||||
|
// Set up servo structures
|
||||||
|
servos[0].gpio = GPIOB;
|
||||||
|
servos[0].pin = 5;
|
||||||
|
servos[0].offset = 0;
|
||||||
|
servos[0].pos = 128;
|
||||||
|
|
||||||
|
servos[1].gpio = GPIOB;
|
||||||
|
servos[1].pin = 4;
|
||||||
|
servos[1].offset = 0;
|
||||||
|
servos[1].pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_start_i2c(void) {
|
||||||
|
i2cAcquireBus(&HW_I2C_DEV);
|
||||||
|
|
||||||
|
if (!i2c_running) {
|
||||||
|
palSetPadMode(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN,
|
||||||
|
PAL_MODE_ALTERNATE(HW_I2C_GPIO_AF) |
|
||||||
|
PAL_STM32_OTYPE_OPENDRAIN |
|
||||||
|
PAL_STM32_OSPEED_MID1 |
|
||||||
|
PAL_STM32_PUDR_PULLUP);
|
||||||
|
palSetPadMode(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN,
|
||||||
|
PAL_MODE_ALTERNATE(HW_I2C_GPIO_AF) |
|
||||||
|
PAL_STM32_OTYPE_OPENDRAIN |
|
||||||
|
PAL_STM32_OSPEED_MID1 |
|
||||||
|
PAL_STM32_PUDR_PULLUP);
|
||||||
|
|
||||||
|
i2cStart(&HW_I2C_DEV, &i2cfg);
|
||||||
|
i2c_running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2cReleaseBus(&HW_I2C_DEV);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_stop_i2c(void) {
|
||||||
|
i2cAcquireBus(&HW_I2C_DEV);
|
||||||
|
|
||||||
|
if (i2c_running) {
|
||||||
|
palSetPadMode(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN, PAL_MODE_INPUT);
|
||||||
|
palSetPadMode(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN, PAL_MODE_INPUT);
|
||||||
|
|
||||||
|
i2cStop(&HW_I2C_DEV);
|
||||||
|
i2c_running = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
i2cReleaseBus(&HW_I2C_DEV);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to restore the i2c bus
|
||||||
|
*/
|
||||||
|
void hw_try_restore_i2c(void) {
|
||||||
|
if (i2c_running) {
|
||||||
|
i2cAcquireBus(&HW_I2C_DEV);
|
||||||
|
|
||||||
|
palSetPadMode(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN,
|
||||||
|
PAL_STM32_OTYPE_OPENDRAIN |
|
||||||
|
PAL_STM32_OSPEED_MID1 |
|
||||||
|
PAL_STM32_PUDR_PULLUP);
|
||||||
|
|
||||||
|
palSetPadMode(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN,
|
||||||
|
PAL_STM32_OTYPE_OPENDRAIN |
|
||||||
|
PAL_STM32_OSPEED_MID1 |
|
||||||
|
PAL_STM32_PUDR_PULLUP);
|
||||||
|
|
||||||
|
palSetPad(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN);
|
||||||
|
palSetPad(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN);
|
||||||
|
|
||||||
|
chThdSleep(1);
|
||||||
|
|
||||||
|
for(int i = 0;i < 16;i++) {
|
||||||
|
palClearPad(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN);
|
||||||
|
chThdSleep(1);
|
||||||
|
palSetPad(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN);
|
||||||
|
chThdSleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate start then stop condition
|
||||||
|
palClearPad(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN);
|
||||||
|
chThdSleep(1);
|
||||||
|
palClearPad(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN);
|
||||||
|
chThdSleep(1);
|
||||||
|
palSetPad(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN);
|
||||||
|
chThdSleep(1);
|
||||||
|
palSetPad(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN);
|
||||||
|
|
||||||
|
palSetPadMode(HW_I2C_SCL_PORT, HW_I2C_SCL_PIN,
|
||||||
|
PAL_MODE_ALTERNATE(HW_I2C_GPIO_AF) |
|
||||||
|
PAL_STM32_OTYPE_OPENDRAIN |
|
||||||
|
PAL_STM32_OSPEED_MID1 |
|
||||||
|
PAL_STM32_PUDR_PULLUP);
|
||||||
|
|
||||||
|
palSetPadMode(HW_I2C_SDA_PORT, HW_I2C_SDA_PIN,
|
||||||
|
PAL_MODE_ALTERNATE(HW_I2C_GPIO_AF) |
|
||||||
|
PAL_STM32_OTYPE_OPENDRAIN |
|
||||||
|
PAL_STM32_OSPEED_MID1 |
|
||||||
|
PAL_STM32_PUDR_PULLUP);
|
||||||
|
|
||||||
|
HW_I2C_DEV.state = I2C_STOP;
|
||||||
|
i2cStart(&HW_I2C_DEV, &i2cfg);
|
||||||
|
|
||||||
|
i2cReleaseBus(&HW_I2C_DEV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,172 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 Benjamin Vedder benjamin@vedder.se
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HW_48_H_
|
||||||
|
#define HW_48_H_
|
||||||
|
|
||||||
|
// Macros
|
||||||
|
#define ENABLE_GATE() palSetPad(GPIOC, 10)
|
||||||
|
#define DISABLE_GATE() palClearPad(GPIOC, 10)
|
||||||
|
#define DCCAL_ON() palSetPad(GPIOB, 12)
|
||||||
|
#define DCCAL_OFF() palClearPad(GPIOB, 12)
|
||||||
|
#define IS_DRV_FAULT() (!palReadPad(GPIOC, 12))
|
||||||
|
|
||||||
|
#define LED_GREEN_ON() palSetPad(GPIOC, 4)
|
||||||
|
#define LED_GREEN_OFF() palClearPad(GPIOC, 4)
|
||||||
|
#define LED_RED_ON() palSetPad(GPIOA, 7)
|
||||||
|
#define LED_RED_OFF() palClearPad(GPIOA, 7)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ADC Vector
|
||||||
|
*
|
||||||
|
* 0: IN0 SENS3
|
||||||
|
* 1: IN1 SENS2
|
||||||
|
* 2: IN2 SENS1
|
||||||
|
* 3: IN5 CURR2
|
||||||
|
* 4: IN6 CURR1
|
||||||
|
* 5: IN3 NC
|
||||||
|
* 6: Vrefint
|
||||||
|
* 7: IN9 ADC_EXT2
|
||||||
|
* 8: IN12 AN_IN
|
||||||
|
* 9: IN4 TEMP_MOSFET
|
||||||
|
* 10: IN15 ADC_EXT
|
||||||
|
* 11: IN10 TEMP_MOTOR
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define HW_ADC_CHANNELS 12
|
||||||
|
#define HW_ADC_NBR_CONV 4
|
||||||
|
|
||||||
|
// ADC Indexes
|
||||||
|
#define ADC_IND_SENS1 2
|
||||||
|
#define ADC_IND_SENS2 1
|
||||||
|
#define ADC_IND_SENS3 0
|
||||||
|
#define ADC_IND_CURR1 4
|
||||||
|
#define ADC_IND_CURR2 3
|
||||||
|
#define ADC_IND_VIN_SENS 8
|
||||||
|
#define ADC_IND_EXT 10
|
||||||
|
#define ADC_IND_EXT2 7
|
||||||
|
#define ADC_IND_TEMP_MOS1 9
|
||||||
|
#define ADC_IND_TEMP_MOS2 9
|
||||||
|
#define ADC_IND_TEMP_MOS3 9
|
||||||
|
#define ADC_IND_TEMP_MOS4 9
|
||||||
|
#define ADC_IND_TEMP_MOS5 9
|
||||||
|
#define ADC_IND_TEMP_MOS6 9
|
||||||
|
#define ADC_IND_TEMP_PCB 9
|
||||||
|
#define ADC_IND_VREFINT 6
|
||||||
|
|
||||||
|
// ADC macros and settings
|
||||||
|
|
||||||
|
// Component parameters (can be overridden)
|
||||||
|
#ifndef V_REG
|
||||||
|
//#define V_REG 3.3
|
||||||
|
#endif
|
||||||
|
#ifndef VIN_R1
|
||||||
|
#define VIN_R1 39000.0
|
||||||
|
#endif
|
||||||
|
#ifndef VIN_R2
|
||||||
|
#define VIN_R2 2200.0
|
||||||
|
#endif
|
||||||
|
#ifndef CURRENT_AMP_GAIN
|
||||||
|
#define CURRENT_AMP_GAIN 10.0
|
||||||
|
#endif
|
||||||
|
#ifndef CURRENT_SHUNT_RES
|
||||||
|
#define CURRENT_SHUNT_RES 0.001
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Input voltage
|
||||||
|
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))
|
||||||
|
|
||||||
|
// Voltage on ADC channel
|
||||||
|
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)
|
||||||
|
|
||||||
|
// NTC Termistors
|
||||||
|
//#define NTC_RES(adc_val) (10000.0 / ((4096.0 / (float)adc_val) - 1.0))
|
||||||
|
#define NTC_RES(adc_val) ((4095.0 * 10000.0) / adc_val - 10000.0)
|
||||||
|
#define NTC_TEMP(adc_ind) (1.0 / ((logf(NTC_RES(ADC_Value[adc_ind]) / 10000.0) / 3434.0) + (1.0 / 298.15)) - 273.15)
|
||||||
|
|
||||||
|
// Double samples in beginning and end for positive current measurement.
|
||||||
|
// Useful when the shunt sense traces have noise that causes offset.
|
||||||
|
#ifndef CURR1_DOUBLE_SAMPLE
|
||||||
|
#define CURR1_DOUBLE_SAMPLE 0
|
||||||
|
#endif
|
||||||
|
#ifndef CURR2_DOUBLE_SAMPLE
|
||||||
|
#define CURR2_DOUBLE_SAMPLE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Number of servo outputs
|
||||||
|
#define HW_SERVO_NUM 2
|
||||||
|
|
||||||
|
// UART Peripheral
|
||||||
|
#define HW_UART_DEV UARTD6
|
||||||
|
#define HW_UART_GPIO_AF GPIO_AF_USART6
|
||||||
|
#define HW_UART_TX_PORT GPIOC
|
||||||
|
#define HW_UART_TX_PIN 6
|
||||||
|
#define HW_UART_RX_PORT GPIOC
|
||||||
|
#define HW_UART_RX_PIN 7
|
||||||
|
|
||||||
|
// ICU Peripheral for servo decoding
|
||||||
|
#define HW_ICU_CHANNEL ICU_CHANNEL_2
|
||||||
|
#define HW_ICU_GPIO_AF GPIO_AF_TIM3
|
||||||
|
#define HW_ICU_GPIO GPIOB
|
||||||
|
#define HW_ICU_PIN 5
|
||||||
|
|
||||||
|
// I2C Peripheral
|
||||||
|
#define HW_I2C_DEV I2CD2
|
||||||
|
#define HW_I2C_GPIO_AF GPIO_AF_I2C2
|
||||||
|
#define HW_I2C_SCL_PORT GPIOB
|
||||||
|
#define HW_I2C_SCL_PIN 10
|
||||||
|
#define HW_I2C_SDA_PORT GPIOB
|
||||||
|
#define HW_I2C_SDA_PIN 11
|
||||||
|
|
||||||
|
// Hall/encoder pins
|
||||||
|
#define HW_HALL_ENC_GPIO1 GPIOB
|
||||||
|
#define HW_HALL_ENC_PIN1 6
|
||||||
|
#define HW_HALL_ENC_GPIO2 GPIOB
|
||||||
|
#define HW_HALL_ENC_PIN2 7
|
||||||
|
#define HW_HALL_ENC_GPIO3 GPIOC
|
||||||
|
#define HW_HALL_ENC_PIN3 11
|
||||||
|
#define HW_ENC_TIM TIM4
|
||||||
|
#define HW_ENC_TIM_AF GPIO_AF_TIM4
|
||||||
|
#define HW_ENC_TIM_CLK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE)
|
||||||
|
#define HW_ENC_EXTI_PORTSRC EXTI_PortSourceGPIOC
|
||||||
|
#define HW_ENC_EXTI_PINSRC EXTI_PinSource11
|
||||||
|
#define HW_ENC_EXTI_CH EXTI15_10_IRQn
|
||||||
|
#define HW_ENC_EXTI_LINE EXTI_Line11
|
||||||
|
#define HW_ENC_EXTI_ISR_VEC EXTI15_10_IRQHandler
|
||||||
|
|
||||||
|
// NRF pins
|
||||||
|
#define NRF_PORT_CSN GPIOB
|
||||||
|
#define NRF_PIN_CSN 1
|
||||||
|
#define NRF_PORT_SCK GPIOC
|
||||||
|
#define NRF_PIN_SCK 5
|
||||||
|
#define NRF_PORT_MOSI HW_I2C_SDA_PORT
|
||||||
|
#define NRF_PIN_MOSI HW_I2C_SDA_PIN
|
||||||
|
#define NRF_PORT_MISO HW_I2C_SCL_PORT
|
||||||
|
#define NRF_PIN_MISO HW_I2C_SCL_PIN
|
||||||
|
|
||||||
|
// Measurement macros
|
||||||
|
#define ADC_V_L1 ADC_Value[ADC_IND_SENS1]
|
||||||
|
#define ADC_V_L2 ADC_Value[ADC_IND_SENS2]
|
||||||
|
#define ADC_V_L3 ADC_Value[ADC_IND_SENS3]
|
||||||
|
#define ADC_V_ZERO (ADC_Value[ADC_IND_VIN_SENS] / 2)
|
||||||
|
|
||||||
|
// Macros
|
||||||
|
#define READ_HALL1() palReadPad(HW_HALL_ENC_GPIO1, HW_HALL_ENC_PIN1)
|
||||||
|
#define READ_HALL2() palReadPad(HW_HALL_ENC_GPIO2, HW_HALL_ENC_PIN2)
|
||||||
|
#define READ_HALL3() palReadPad(HW_HALL_ENC_GPIO3, HW_HALL_ENC_PIN3)
|
||||||
|
|
||||||
|
#endif /* HW_48_H_ */
|
|
@ -2,6 +2,7 @@ HWSRC = hwconf/hw_40.c \
|
||||||
hwconf/hw_45.c \
|
hwconf/hw_45.c \
|
||||||
hwconf/hw_r2.c \
|
hwconf/hw_r2.c \
|
||||||
hwconf/hw_46.c \
|
hwconf/hw_46.c \
|
||||||
|
hwconf/hw_48.c \
|
||||||
hwconf/hw_victor_r1a.c
|
hwconf/hw_victor_r1a.c
|
||||||
|
|
||||||
HWINC = hwconf
|
HWINC = hwconf
|
||||||
|
|
|
@ -0,0 +1,205 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 Benjamin Vedder benjamin@vedder.se
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MCCONF_DEFAULT_H_
|
||||||
|
#define MCCONF_DEFAULT_H_
|
||||||
|
|
||||||
|
// Default settings
|
||||||
|
#ifndef MCCONF_DEFAULT_MOTOR_TYPE
|
||||||
|
#define MCCONF_DEFAULT_MOTOR_TYPE MOTOR_TYPE_BLDC
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_PWM_MODE
|
||||||
|
#define MCCONF_PWM_MODE PWM_MODE_SYNCHRONOUS // Default PWM mode
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SENSOR_MODE
|
||||||
|
#define MCCONF_SENSOR_MODE SENSOR_MODE_SENSORLESS // Sensor mode
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_COMM_MODE
|
||||||
|
#define MCCONF_COMM_MODE COMM_MODE_INTEGRATE // The commutation mode to use
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Limits
|
||||||
|
#ifndef MCCONF_L_CURRENT_MAX
|
||||||
|
#define MCCONF_L_CURRENT_MAX 60.0 // Current limit in Amperes (Upper)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_CURRENT_MIN
|
||||||
|
#define MCCONF_L_CURRENT_MIN -60.0 // Current limit in Amperes (Lower)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_IN_CURRENT_MAX
|
||||||
|
#define MCCONF_L_IN_CURRENT_MAX 60.0 // Input current limit in Amperes (Upper)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_IN_CURRENT_MIN
|
||||||
|
#define MCCONF_L_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_MAX_ABS_CURRENT
|
||||||
|
#define MCCONF_L_MAX_ABS_CURRENT 130.0 // The maximum absolute current above which a fault is generated
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_MIN_VOLTAGE
|
||||||
|
#define MCCONF_L_MIN_VOLTAGE 8.0 // Minimum input voltage
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_MAX_VOLTAGE
|
||||||
|
#define MCCONF_L_MAX_VOLTAGE 50.0 // Maximum input voltage
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_BATTERY_CUT_START
|
||||||
|
#define MCCONF_L_BATTERY_CUT_START 10.0 // Start limiting the positive current at this voltage
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_BATTERY_CUT_END
|
||||||
|
#define MCCONF_L_BATTERY_CUT_END 8.0 // Limit the positive current completely at this voltage
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_RPM_MAX
|
||||||
|
#define MCCONF_L_RPM_MAX 100000.0 // The motor speed limit (Upper)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_RPM_MIN
|
||||||
|
#define MCCONF_L_RPM_MIN -100000.0 // The motor speed limit (Lower)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_SLOW_ABS_OVERCURRENT
|
||||||
|
#define MCCONF_L_SLOW_ABS_OVERCURRENT true // Use the filtered (and hence slower) current for the overcurrent fault detection
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_MIN_DUTY
|
||||||
|
#define MCCONF_L_MIN_DUTY 0.005 // Minimum duty cycle
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_MAX_DUTY
|
||||||
|
#define MCCONF_L_MAX_DUTY 0.95 // Maximum duty cycle
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_RPM_LIMIT_NEG_TORQUE
|
||||||
|
#define MCCONF_L_RPM_LIMIT_NEG_TORQUE true // Use negative torque to limit the RPM
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_CURR_MAX_RPM_FBRAKE
|
||||||
|
#define MCCONF_L_CURR_MAX_RPM_FBRAKE 300 // Maximum electrical RPM to use full brake at
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_CURR_MAX_RPM_FBRAKE_CC
|
||||||
|
#define MCCONF_L_CURR_MAX_RPM_FBRAKE_CC 1500 // Maximum electrical RPM to use full brake at with current control
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_LIM_TEMP_FET_START
|
||||||
|
#define MCCONF_L_LIM_TEMP_FET_START 80.0 // MOSFET temperature where current limiting should begin
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_LIM_TEMP_FET_END
|
||||||
|
#define MCCONF_L_LIM_TEMP_FET_END 100.0 // MOSFET temperature where everything should be shut off
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_LIM_TEMP_MOTOR_START
|
||||||
|
#define MCCONF_L_LIM_TEMP_MOTOR_START 80.0 // MOTOR temperature where current limiting should begin
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_L_LIM_TEMP_MOTOR_END
|
||||||
|
#define MCCONF_L_LIM_TEMP_MOTOR_END 100.0 // MOTOR temperature where everything should be shut off
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Speed PID parameters
|
||||||
|
#ifndef MCCONF_S_PID_KP
|
||||||
|
#define MCCONF_S_PID_KP 0.0001 // Proportional gain
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_S_PID_KI
|
||||||
|
#define MCCONF_S_PID_KI 0.002 // Integral gain
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_S_PID_KD
|
||||||
|
#define MCCONF_S_PID_KD 0.0 // Derivative gain
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_S_PID_MIN_RPM
|
||||||
|
#define MCCONF_S_PID_MIN_RPM 900.0 // Minimum allowed RPM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Position PID parameters
|
||||||
|
#ifndef MCCONF_P_PID_KP
|
||||||
|
#define MCCONF_P_PID_KP 0.0001 // Proportional gain
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_P_PID_KI
|
||||||
|
#define MCCONF_P_PID_KI 0.002 // Integral gain
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_P_PID_KD
|
||||||
|
#define MCCONF_P_PID_KD 0.0 // Derivative gain
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Current control parameters
|
||||||
|
#ifndef MCCONF_CC_GAIN
|
||||||
|
#define MCCONF_CC_GAIN 0.0046 // Current controller error gain
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_CC_MIN_CURRENT
|
||||||
|
#define MCCONF_CC_MIN_CURRENT 1.0 // Minimum allowed current
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_CC_STARTUP_BOOST_DUTY
|
||||||
|
#define MCCONF_CC_STARTUP_BOOST_DUTY 0.01 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE)
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_CC_RAMP_STEP
|
||||||
|
#define MCCONF_CC_RAMP_STEP 0.04 // Maximum duty cycle ramping step in CC mode
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sensorless
|
||||||
|
#ifndef MCCONF_SL_MIN_RPM
|
||||||
|
#define MCCONF_SL_MIN_RPM 150 // Auto-commutate below this RPM
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SL_MIN_ERPM_CYCLE_INT_LIMIT
|
||||||
|
#define MCCONF_SL_MIN_ERPM_CYCLE_INT_LIMIT 1100.0 // Minimum RPM to calculate the BEMF coupling from
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SL_CYCLE_INT_LIMIT
|
||||||
|
#define MCCONF_SL_CYCLE_INT_LIMIT 62.0 // Flux integrator limit 0 ERPM
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SL_BEMF_COUPLING_K
|
||||||
|
#define MCCONF_SL_BEMF_COUPLING_K 600.0 // Input voltage to bemf coupling constant
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SL_PHASE_ADVANCE_AT_BR
|
||||||
|
#define MCCONF_SL_PHASE_ADVANCE_AT_BR 0.8 // Flux integrator limit percentage at MCPWM_CYCLE_INT_START_RPM_BR ERPM
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SL_CYCLE_INT_BR
|
||||||
|
#define MCCONF_SL_CYCLE_INT_BR 80000.0 // RPM border between the START and LOW interval
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_SL_MAX_FB_CURR_DIR_CHANGE
|
||||||
|
#define MCCONF_SL_MAX_FB_CURR_DIR_CHANGE 10.0 // Maximum current during full brake during which a direction change is allowed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Default hall sensor table
|
||||||
|
#ifndef MCCONF_HALL_TAB_0
|
||||||
|
#define MCCONF_HALL_TAB_0 -1
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_1
|
||||||
|
#define MCCONF_HALL_TAB_1 1
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_2
|
||||||
|
#define MCCONF_HALL_TAB_2 3
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_3
|
||||||
|
#define MCCONF_HALL_TAB_3 2
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_4
|
||||||
|
#define MCCONF_HALL_TAB_4 5
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_5
|
||||||
|
#define MCCONF_HALL_TAB_5 6
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_6
|
||||||
|
#define MCCONF_HALL_TAB_6 4
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_TAB_7
|
||||||
|
#define MCCONF_HALL_TAB_7 -1
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_HALL_ERPM
|
||||||
|
#define MCCONF_HALL_ERPM 2000.0 // ERPM above which sensorless commutation is used in hybrid mode
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
#ifndef MCCONF_M_FAULT_STOP_TIME
|
||||||
|
#define MCCONF_M_FAULT_STOP_TIME 3000 // Ignore commands for this duration in msec when faults occur
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_M_RAMP_STEP
|
||||||
|
#define MCCONF_M_RAMP_STEP 0.02 // Duty cycle ramping step (1000 times/sec) at maximum duty cycle
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_M_RAMP_STEP_RPM_LIM
|
||||||
|
#define MCCONF_M_RAMP_STEP_RPM_LIM 0.0005 // Ramping step when limiting the RPM
|
||||||
|
#endif
|
||||||
|
#ifndef MCCONF_M_CURRENT_BACKOFF_GAIN
|
||||||
|
#define MCCONF_M_CURRENT_BACKOFF_GAIN 0.5 // The error gain of the current limiting algorithm
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MCCONF_DEFAULT_H_ */
|
|
@ -30,34 +30,34 @@
|
||||||
/*
|
/*
|
||||||
* Parameters
|
* Parameters
|
||||||
*/
|
*/
|
||||||
#define MCPWM_CURRENT_MAX 60.0 // Current limit in Amperes (Upper)
|
#define MCCONF_L_CURRENT_MAX 60.0 // Current limit in Amperes (Upper)
|
||||||
#define MCPWM_CURRENT_MIN -60.0 // Current limit in Amperes (Lower)
|
#define MCCONF_L_CURRENT_MIN -60.0 // Current limit in Amperes (Lower)
|
||||||
#define MCPWM_IN_CURRENT_MAX 60.0 // Input current limit in Amperes (Upper)
|
#define MCCONF_L_IN_CURRENT_MAX 60.0 // Input current limit in Amperes (Upper)
|
||||||
#define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
|
#define MCCONF_L_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
|
||||||
#define MCPWM_MAX_ABS_CURRENT 130.0 // The maximum absolute current above which a fault is generated
|
#define MCCONF_L_MAX_ABS_CURRENT 130.0 // The maximum absolute current above which a fault is generated
|
||||||
#define MCPWM_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
|
#define MCCONF_L_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
|
||||||
|
|
||||||
// Sensorless settings
|
// Sensorless settings
|
||||||
#define MCPWM_SENSOR_MODE SENSOR_MODE_SENSORLESS // Sensor mode
|
#define MCCONF_SENSOR_MODE SENSOR_MODE_SENSORLESS // Sensor mode
|
||||||
#define MCPWM_MIN_RPM 150 // Auto-commutate below this RPM
|
#define MCCONF_SL_MIN_RPM 150 // Auto-commutate below this RPM
|
||||||
#define MCPWM_CYCLE_INT_LIMIT_MIN_RPM 1100.0 // Minimum RPM to calculate the BEMF coupling from
|
#define MCCONF_SL_MIN_ERPM_CYCLE_INT_LIMIT 1100.0 // Minimum RPM to calculate the BEMF coupling from
|
||||||
#define MCPWM_CYCLE_INT_LIMIT 62.0 // Flux integrator limit 0 ERPM
|
#define MCCONF_SL_CYCLE_INT_LIMIT 62.0 // Flux integrator limit 0 ERPM
|
||||||
#define MCPWM_CYCLE_INT_LIMIT_HIGH_FAC 0.8 // Flux integrator limit percentage at MCPWM_CYCLE_INT_START_RPM_BR ERPM
|
#define MCCONF_SL_PHASE_ADVANCE_AT_BR 0.8 // Flux integrator limit percentage at MCPWM_CYCLE_INT_START_RPM_BR ERPM
|
||||||
#define MCPWM_BEMF_INPUT_COUPLING_K 600.0 // Input voltage to bemf coupling constant
|
#define MCCONF_SL_BEMF_COUPLING_K 600.0 // Input voltage to bemf coupling constant
|
||||||
|
|
||||||
// Speed PID parameters
|
// Speed PID parameters
|
||||||
#define MCPWM_PID_KP 0.0001 // Proportional gain
|
#define MCCONF_S_PID_KP 0.0001 // Proportional gain
|
||||||
#define MCPWM_PID_KI 0.002 // Integral gain
|
#define MCCONF_S_PID_KI 0.002 // Integral gain
|
||||||
#define MCPWM_PID_KD 0.0 // Derivative gain
|
#define MCCONF_S_PID_KD 0.0 // Derivative gain
|
||||||
#define MCPWM_PID_MIN_RPM 900.0 // Minimum allowed RPM
|
#define MCCONF_S_PID_MIN_RPM 900.0 // Minimum allowed RPM
|
||||||
|
|
||||||
// Position PID parameters
|
// Position PID parameters
|
||||||
#define MCPWM_P_PID_KP 0.0001 // Proportional gain
|
#define MCCONF_P_PID_KP 0.0001 // Proportional gain
|
||||||
#define MCPWM_P_PID_KI 0.002 // Integral gain
|
#define MCCONF_P_PID_KI 0.002 // Integral gain
|
||||||
#define MCPWM_P_PID_KD 0.0 // Derivative gain
|
#define MCCONF_P_PID_KD 0.0 // Derivative gain
|
||||||
|
|
||||||
// Current control parameters
|
// Current control parameters
|
||||||
#define MCPWM_CURRENT_CONTROL_GAIN 0.0046 // Current controller error gain
|
#define MCCONF_CC_GAIN 0.0046 // Current controller error gain
|
||||||
#define MCPWM_CURRENT_CONTROL_MIN 1.0 // Minimum allowed current
|
#define MCCONF_CC_MIN_CURRENT 1.0 // Minimum allowed current
|
||||||
|
|
||||||
#endif /* MCCONF_OUTRUNNER2_H_ */
|
#endif /* MCCONF_OUTRUNNER2_H_ */
|
||||||
|
|
|
@ -28,41 +28,41 @@
|
||||||
/*
|
/*
|
||||||
* Parameters
|
* Parameters
|
||||||
*/
|
*/
|
||||||
#define MCPWM_CURRENT_MAX 35.0 // Current limit in Amperes (Upper)
|
#define MCCONF_L_CURRENT_MAX 35.0 // Current limit in Amperes (Upper)
|
||||||
#define MCPWM_CURRENT_MIN -30.0 // Current limit in Amperes (Lower)
|
#define MCCONF_L_CURRENT_MIN -30.0 // Current limit in Amperes (Lower)
|
||||||
#define MCPWM_MAX_ABS_CURRENT 100.0 // The maximum absolute current above which a fault is generated
|
#define MCCONF_L_MAX_ABS_CURRENT 100.0 // The maximum absolute current above which a fault is generated
|
||||||
#define MCPWM_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
|
#define MCCONF_L_SLOW_ABS_OVERCURRENT 1 // Use the filtered (and hence slower) current for the overcurrent fault detection
|
||||||
#define MCPWM_IN_CURRENT_MAX 25.0 // Input current limit in Amperes (Upper)
|
#define MCCONF_L_IN_CURRENT_MAX 25.0 // Input current limit in Amperes (Upper)
|
||||||
#define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
|
#define MCCONF_L_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower)
|
||||||
#define MCPWM_RPM_MAX 80000.0 // The motor speed limit (Upper)
|
#define MCCONF_L_RPM_MAX 80000.0 // The motor speed limit (Upper)
|
||||||
#define MCPWM_RPM_MIN -80000.0 // The motor speed limit (Lower)
|
#define MCCONF_L_RPM_MIN -80000.0 // The motor speed limit (Lower)
|
||||||
#define MCPWM_MIN_VOLTAGE 20.0 // Minimum input voltage
|
#define MCCONF_L_MIN_VOLTAGE 20.0 // Minimum input voltage
|
||||||
#define MCPWM_MAX_VOLTAGE 50.0 // Maximum input voltage
|
#define MCCONF_L_MAX_VOLTAGE 50.0 // Maximum input voltage
|
||||||
#define MCPWM_CURRENT_STARTUP_BOOST 0.02 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE)
|
#define MCCONF_CC_STARTUP_BOOST_DUTY 0.02 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE)
|
||||||
#define MCPWM_RPM_LIMIT_NEG_TORQUE 0 // Use negative torque to limit the RPM
|
#define MCCONF_L_RPM_LIMIT_NEG_TORQUE 0 // Use negative torque to limit the RPM
|
||||||
#define MCPWM_CURR_MAX_RPM_FBRAKE 1500 // Maximum electrical RPM to use full brake at
|
#define MCCONF_L_CURR_MAX_RPM_FBRAKE 1500 // Maximum electrical RPM to use full brake at
|
||||||
|
|
||||||
// Sensorless settings
|
// Sensorless settings
|
||||||
#define MCPWM_SENSOR_MODE SENSOR_MODE_SENSORLESS // Sensor mode
|
#define MCCONF_SENSOR_MODE SENSOR_MODE_SENSORLESS // Sensor mode
|
||||||
#define MCPWM_MIN_RPM 250 // Auto-commutate below this RPM
|
#define MCCONF_SL_MIN_RPM 250 // Auto-commutate below this RPM
|
||||||
#define MCPWM_CYCLE_INT_LIMIT_MIN_RPM 500.0 // Minimum RPM to calculate the BEMF coupling from
|
#define MCCONF_SL_MIN_ERPM_CYCLE_INT_LIMIT 500.0 // Minimum RPM to calculate the BEMF coupling from
|
||||||
#define MCPWM_CYCLE_INT_LIMIT 80.0 // Flux integrator limit 0 ERPM
|
#define MCCONF_SL_CYCLE_INT_LIMIT 80.0 // Flux integrator limit 0 ERPM
|
||||||
#define MCPWM_CYCLE_INT_LIMIT_HIGH_FAC 0.8 // Flux integrator limit percentage at MCPWM_CYCLE_INT_START_RPM_BR ERPM
|
#define MCCONF_SL_PHASE_ADVANCE_AT_BR 0.8 // Flux integrator limit percentage at MCPWM_CYCLE_INT_START_RPM_BR ERPM
|
||||||
#define MCPWM_BEMF_INPUT_COUPLING_K 750.0 // Input voltage to bemf coupling constant
|
#define MCCONF_SL_BEMF_COUPLING_K 750.0 // Input voltage to bemf coupling constant
|
||||||
|
|
||||||
// Speed PID parameters
|
// Speed PID parameters
|
||||||
#define MCPWM_PID_KP 0.0001 // Proportional gain
|
#define MCCONF_S_PID_KP 0.0001 // Proportional gain
|
||||||
#define MCPWM_PID_KI 0.002 // Integral gain
|
#define MCCONF_S_PID_KI 0.002 // Integral gain
|
||||||
#define MCPWM_PID_KD 0.0 // Derivative gain
|
#define MCCONF_S_PID_KD 0.0 // Derivative gain
|
||||||
#define MCPWM_PID_MIN_RPM 1200.0 // Minimum allowed RPM
|
#define MCCONF_S_PID_MIN_RPM 1200.0 // Minimum allowed RPM
|
||||||
|
|
||||||
// Position PID parameters
|
// Position PID parameters
|
||||||
#define MCPWM_P_PID_KP 0.0001 // Proportional gain
|
#define MCCONF_P_PID_KP 0.0001 // Proportional gain
|
||||||
#define MCPWM_P_PID_KI 0.002 // Integral gain
|
#define MCCONF_P_PID_KI 0.002 // Integral gain
|
||||||
#define MCPWM_P_PID_KD 0.0 // Derivative gain
|
#define MCCONF_P_PID_KD 0.0 // Derivative gain
|
||||||
|
|
||||||
// Current control parameters
|
// Current control parameters
|
||||||
#define MCPWM_CURRENT_CONTROL_GAIN 0.0046 // Current controller error gain
|
#define MCCONF_CC_GAIN 0.0046 // Current controller error gain
|
||||||
#define MCPWM_CURRENT_CONTROL_MIN 0.05 // Minimum allowed current
|
#define MCCONF_CC_MIN_CURRENT 0.05 // Minimum allowed current
|
||||||
|
|
||||||
#endif /* MCCONF_STEN_H_ */
|
#endif /* MCCONF_STEN_H_ */
|
||||||
|
|
2
mcpwm.c
2
mcpwm.c
|
@ -1320,7 +1320,7 @@ static void run_pid_control_speed(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Too low RPM set. Stop and return.
|
// Too low RPM set. Stop and return.
|
||||||
if (fabsf(speed_pid_set_rpm) < conf.s_pid_min_rpm) {
|
if (fabsf(speed_pid_set_rpm) < conf.s_pid_min_erpm) {
|
||||||
i_term = dutycycle_now;
|
i_term = dutycycle_now;
|
||||||
prev_error = 0;
|
prev_error = 0;
|
||||||
mcpwm_set_duty(0.0);
|
mcpwm_set_duty(0.0);
|
||||||
|
|
8
packet.c
8
packet.c
|
@ -63,9 +63,8 @@ void packet_send_packet(unsigned char *data, unsigned int len, int handler_num)
|
||||||
handler_states[handler_num].tx_buffer[b_ind++] = len & 0xFF;
|
handler_states[handler_num].tx_buffer[b_ind++] = len & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned int i = 0;i < len;i++) {
|
memcpy(handler_states[handler_num].tx_buffer + b_ind, data, len);
|
||||||
handler_states[handler_num].tx_buffer[b_ind++] = data[i];
|
b_ind += len;
|
||||||
}
|
|
||||||
|
|
||||||
unsigned short crc = crc16(data, len);
|
unsigned short crc = crc16(data, len);
|
||||||
handler_states[handler_num].tx_buffer[b_ind++] = (uint8_t)(crc >> 8);
|
handler_states[handler_num].tx_buffer[b_ind++] = (uint8_t)(crc >> 8);
|
||||||
|
@ -118,7 +117,8 @@ void packet_process_byte(uint8_t rx_data, int handler_num) {
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
handler_states[handler_num].payload_length |= (unsigned int)rx_data;
|
handler_states[handler_num].payload_length |= (unsigned int)rx_data;
|
||||||
if (handler_states[handler_num].payload_length <= PACKET_MAX_PL_LEN) {
|
if (handler_states[handler_num].payload_length > 0 &&
|
||||||
|
handler_states[handler_num].payload_length <= PACKET_MAX_PL_LEN) {
|
||||||
handler_states[handler_num].rx_state++;
|
handler_states[handler_num].rx_state++;
|
||||||
handler_states[handler_num].rx_timeout = PACKET_RX_TIMEOUT;
|
handler_states[handler_num].rx_timeout = PACKET_RX_TIMEOUT;
|
||||||
} else {
|
} else {
|
||||||
|
|
2
utils.h
2
utils.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2012-2014 Benjamin Vedder benjamin@vedder.se
|
Copyright 2012-2015 Benjamin Vedder benjamin@vedder.se
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
Loading…
Reference in New Issue