2014-04-14 14:02:45 -07:00
|
|
|
/*
|
2022-02-04 16:04:12 -08:00
|
|
|
Copyright 2017 - 2022 Benjamin Vedder benjamin@vedder.se
|
2014-04-14 14:02:45 -07:00
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
This file is part of the VESC firmware.
|
|
|
|
|
|
|
|
The VESC firmware is free software: you can redistribute it and/or modify
|
2014-04-14 14:02:45 -07:00
|
|
|
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.
|
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
The VESC firmware is distributed in the hope that it will be useful,
|
2014-04-14 14:02:45 -07:00
|
|
|
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 CONF_GENERAL_H_
|
|
|
|
#define CONF_GENERAL_H_
|
|
|
|
|
2015-05-08 13:53:59 -07:00
|
|
|
// Firmware version
|
2022-01-16 12:57:12 -08:00
|
|
|
#define FW_VERSION_MAJOR 6
|
2023-03-20 14:10:01 -07:00
|
|
|
#define FW_VERSION_MINOR 05
|
2020-04-05 12:28:08 -07:00
|
|
|
// Set to 0 for building a release and iterate during beta test builds
|
2024-07-20 04:40:58 -07:00
|
|
|
#define FW_TEST_VERSION_NUMBER 31
|
2015-05-04 14:25:43 -07:00
|
|
|
|
2014-09-14 14:08:22 -07:00
|
|
|
#include "datatypes.h"
|
|
|
|
|
2017-09-04 12:12:43 -07:00
|
|
|
// Disable hardware limits on configuration parameters
|
|
|
|
//#define DISABLE_HW_LIMITS
|
|
|
|
|
2022-03-05 15:09:11 -08:00
|
|
|
#if !defined(HW_SOURCE) && !defined(HW_SOURCE_ALT)
|
2019-02-18 10:30:19 -08:00
|
|
|
#error "No hardware source file set"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HW_HEADER
|
|
|
|
#error "No hardware header file set"
|
2015-09-17 14:24:55 -07:00
|
|
|
#endif
|
|
|
|
|
2019-09-03 11:39:05 -07:00
|
|
|
#ifdef USER_MC_CONF
|
|
|
|
#include USER_MC_CONF
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USER_APP_CONF
|
|
|
|
#include USER_APP_CONF
|
|
|
|
#endif
|
2019-04-26 02:07:31 -07:00
|
|
|
|
2021-04-24 13:36:00 -07:00
|
|
|
// This is how to provide a custom UI in VESC Tool. The UI can be created and tested in the
|
|
|
|
// scripting page, then the source files can be exported. The defines below use the exported
|
|
|
|
// files to provide the custom UI when VESC Tool connects.
|
|
|
|
//
|
|
|
|
// The intention if the HW gui is to be part of the HW-file and the app gui is for custom apps.
|
|
|
|
// Both can be used at the same time.
|
|
|
|
//
|
|
|
|
// Defining QMLUI_HW_FULLSCREEN and/or QMLUI_APP_FULLSCREEN will disable the other pages in the
|
|
|
|
// mobile version of VESC Tool.
|
|
|
|
//
|
|
|
|
//#define QMLUI_SOURCE_HW "qmlui/hw/qmlui_example_hw.c"
|
|
|
|
//#define QMLUI_HEADER_HW "qmlui/hw/qmlui_example_hw.h"
|
|
|
|
//#define QMLUI_HW_FULLSCREEN
|
|
|
|
//
|
|
|
|
//#define QMLUI_SOURCE_APP "qmlui/app/qmlui_example_app.c"
|
|
|
|
//#define QMLUI_HEADER_APP "qmlui/app/qmlui_example_app.h"
|
|
|
|
//#define QMLUI_APP_FULLSCREEN
|
|
|
|
|
2015-09-17 14:24:55 -07:00
|
|
|
/*
|
|
|
|
* Select default user motor configuration
|
|
|
|
*/
|
2021-03-31 05:10:27 -07:00
|
|
|
//#include "mcconf_default.h"
|
2021-03-27 06:15:22 -07:00
|
|
|
//#include "mcconf_china_60kv.h"
|
2014-04-14 14:02:45 -07:00
|
|
|
|
|
|
|
/*
|
2015-09-17 14:24:55 -07:00
|
|
|
* Select default user app configuration
|
2014-04-14 14:02:45 -07:00
|
|
|
*/
|
2019-09-03 11:39:05 -07:00
|
|
|
//#include "appconf_example_ppm.h"
|
|
|
|
//#include "appconf_custom.h"
|
|
|
|
|
2014-04-18 15:09:46 -07:00
|
|
|
/*
|
2017-09-04 12:12:43 -07:00
|
|
|
* Set APP_CUSTOM_TO_USE to the name of the main C file of the custom application.
|
2014-04-18 15:09:46 -07:00
|
|
|
*/
|
2019-09-03 11:39:05 -07:00
|
|
|
//#define APP_CUSTOM_TO_USE "app_custom_template.c"
|
2019-12-19 07:55:38 -08:00
|
|
|
//#define APP_CUSTOM_TO_USE "app_motor_heater.c"
|
2021-04-06 05:12:57 -07:00
|
|
|
//#include "er/app_erockit_conf_v2.h"
|
2020-12-06 12:33:08 -08:00
|
|
|
//#include "finn/app_finn_az_conf.h"
|
2020-10-09 12:08:48 -07:00
|
|
|
|
2019-12-05 10:50:17 -08:00
|
|
|
#include "hw.h"
|
|
|
|
#include "mcconf_default.h"
|
|
|
|
#include "appconf_default.h"
|
2014-04-18 15:09:46 -07:00
|
|
|
|
2019-03-31 01:49:18 -07:00
|
|
|
/*
|
|
|
|
* Enable blackmagic probe output on SWD port
|
|
|
|
*/
|
|
|
|
#ifndef HAS_BLACKMAGIC
|
|
|
|
#define HAS_BLACKMAGIC 1
|
|
|
|
#endif
|
|
|
|
|
2015-04-26 15:02:32 -07:00
|
|
|
/*
|
2015-04-27 11:43:02 -07:00
|
|
|
* Enable CAN-bus
|
2015-04-26 15:02:32 -07:00
|
|
|
*/
|
2019-04-26 02:07:31 -07:00
|
|
|
#ifndef CAN_ENABLE
|
2016-11-04 07:18:34 -07:00
|
|
|
#define CAN_ENABLE 1
|
2019-04-26 02:07:31 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HW_HAS_NO_CAN
|
|
|
|
#undef CAN_ENABLE
|
|
|
|
#define CAN_ENABLE 0
|
|
|
|
#endif
|
2015-04-26 15:02:32 -07:00
|
|
|
|
2015-07-31 14:26:50 -07:00
|
|
|
/*
|
|
|
|
* Servo output driver
|
|
|
|
*/
|
2016-11-04 07:18:34 -07:00
|
|
|
#define SERVO_OUT_PULSE_MIN_US 1000 // Minimum pulse length in microseconds
|
|
|
|
#define SERVO_OUT_PULSE_MAX_US 2000 // Maximum pulse length in microseconds
|
|
|
|
#define SERVO_OUT_RATE_HZ 50 // Update rate in Hz
|
2015-07-31 14:26:50 -07:00
|
|
|
|
2015-08-23 09:26:05 -07:00
|
|
|
// Correction factor for computations that depend on the old resistor division factor
|
2016-11-04 07:18:34 -07:00
|
|
|
#define VDIV_CORR ((VIN_R2 / (VIN_R2 + VIN_R1)) / (2.2 / (2.2 + 33.0)))
|
2015-08-23 09:26:05 -07:00
|
|
|
|
2016-06-27 08:29:09 -07:00
|
|
|
// Current ADC to amperes factor
|
2016-11-04 07:18:34 -07:00
|
|
|
#define FAC_CURRENT ((V_REG / 4095.0) / (CURRENT_SHUNT_RES * CURRENT_AMP_GAIN))
|
2024-02-06 14:23:53 -08:00
|
|
|
#define FAC_CURRENT1 (FAC_CURRENT * CURRENT_CAL1)
|
|
|
|
#define FAC_CURRENT2 (FAC_CURRENT * CURRENT_CAL2)
|
|
|
|
#define FAC_CURRENT3 (FAC_CURRENT * CURRENT_CAL3)
|
|
|
|
#define FAC_CURRENT1_M2 (FAC_CURRENT * CURRENT_CAL1_M2)
|
|
|
|
#define FAC_CURRENT2_M2 (FAC_CURRENT * CURRENT_CAL2_M2)
|
|
|
|
#define FAC_CURRENT3_M2 (FAC_CURRENT * CURRENT_CAL3_M2)
|
2016-06-27 08:29:09 -07:00
|
|
|
|
2019-04-06 06:36:00 -07:00
|
|
|
#define VOLTAGE_TO_ADC_FACTOR ( VIN_R2 / (VIN_R2 + VIN_R1) ) * ( 4096.0 / V_REG )
|
|
|
|
|
2015-08-23 09:26:05 -07:00
|
|
|
// Actual voltage on 3.3V net based on internal reference
|
2016-11-04 07:18:34 -07:00
|
|
|
//#define V_REG (1.21 / ((float)ADC_Value[ADC_IND_VREFINT] / 4095.0))
|
2019-03-04 10:23:38 -08:00
|
|
|
//#define V_REG 3.3
|
2015-08-23 09:26:05 -07:00
|
|
|
|
2016-06-27 08:29:09 -07:00
|
|
|
// Use the pins for the hardware SPI port instead of the hall/encoder pins for the AS5047
|
2021-07-28 08:14:10 -07:00
|
|
|
#ifndef AS504x_USE_SW_MOSI_PIN
|
|
|
|
#define AS504x_USE_SW_MOSI_PIN 0
|
|
|
|
#endif
|
|
|
|
|
2016-11-06 09:14:06 -08:00
|
|
|
/*
|
2017-09-04 12:12:43 -07:00
|
|
|
* MCU
|
2016-11-06 09:14:06 -08:00
|
|
|
*/
|
|
|
|
#define SYSTEM_CORE_CLOCK 168000000
|
2017-09-04 12:12:43 -07:00
|
|
|
#define STM32_UUID ((uint32_t*)0x1FFF7A10)
|
|
|
|
#define STM32_UUID_8 ((uint8_t*)0x1FFF7A10)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the BLDC speed controller in current mode instead of duty cycle mode. This will
|
|
|
|
* make it behave like the FOC speed controller. The duty cycle mode has the advantage
|
|
|
|
* that it does not require the extra current controller since bldc inherently runs
|
|
|
|
* with duty cycle control. The current controller also outputs a duty cycle in the
|
|
|
|
* end, and then the speed controller might as well do the same without the current
|
|
|
|
* controller dynamics in between. FOC on the other hand is inherently based on current
|
|
|
|
* control.
|
|
|
|
*/
|
|
|
|
#define BLDC_SPEED_CONTROL_CURRENT 1
|
|
|
|
|
2019-01-29 19:33:56 -08:00
|
|
|
/*
|
|
|
|
* Run the FOC loop once every N ADC ISR requests. This way the pwm frequency is
|
|
|
|
* detached from the FOC calculation, which because it takes ~25usec it can't work
|
|
|
|
* at >40khz. To set a 100kHz pwm FOC_CONTROL_LOOP_FREQ_DIVIDER can be set at 3
|
|
|
|
* so it skips 2 ISR calls and execute the control loop in the 3rd call.
|
|
|
|
*/
|
|
|
|
#ifndef FOC_CONTROL_LOOP_FREQ_DIVIDER
|
|
|
|
#define FOC_CONTROL_LOOP_FREQ_DIVIDER 1
|
|
|
|
#endif
|
|
|
|
|
2017-09-04 12:12:43 -07:00
|
|
|
// Global configuration variables
|
|
|
|
extern bool conf_general_permanent_nrf_found;
|
2021-04-11 10:36:11 -07:00
|
|
|
extern volatile backup_data g_backup;
|
2016-11-06 09:14:06 -08:00
|
|
|
|
2014-09-14 14:08:22 -07:00
|
|
|
// Functions
|
|
|
|
void conf_general_init(void);
|
2021-04-11 10:36:11 -07:00
|
|
|
bool conf_general_store_backup_data(void);
|
2019-04-19 01:42:43 -07:00
|
|
|
bool conf_general_read_eeprom_var_hw(eeprom_var *v, int address);
|
|
|
|
bool conf_general_read_eeprom_var_custom(eeprom_var *v, int address);
|
|
|
|
bool conf_general_store_eeprom_var_hw(eeprom_var *v, int address);
|
2019-09-27 03:56:49 -07:00
|
|
|
bool conf_general_store_eeprom_var_custom(eeprom_var *v, int address);
|
2014-09-17 12:05:57 -07:00
|
|
|
void conf_general_read_app_configuration(app_configuration *conf);
|
|
|
|
bool conf_general_store_app_configuration(app_configuration *conf);
|
2020-03-16 10:32:39 -07:00
|
|
|
void conf_general_read_mc_configuration(mc_configuration *conf, bool is_motor_2);
|
|
|
|
bool conf_general_store_mc_configuration(mc_configuration *conf, bool is_motor_2);
|
2014-09-15 11:48:46 -07:00
|
|
|
bool conf_general_detect_motor_param(float current, float min_rpm, float low_duty,
|
2022-11-08 02:46:35 -08:00
|
|
|
float *int_limit, float *bemf_coupling_k, int8_t *hall_table, int *hall_res);
|
2015-12-08 12:01:23 -08:00
|
|
|
bool conf_general_measure_flux_linkage(float current, float duty,
|
2022-11-08 02:46:35 -08:00
|
|
|
float min_erpm, float res, float *linkage);
|
2019-02-01 02:03:37 -08:00
|
|
|
uint8_t conf_general_calculate_deadtime(float deadtime_ns, float core_clock_freq);
|
2022-09-27 13:52:40 -07:00
|
|
|
int conf_general_measure_flux_linkage_openloop(float current, float duty,
|
2022-11-08 02:46:35 -08:00
|
|
|
float erpm_per_sec, float res, float ind, float *linkage,
|
|
|
|
float *linkage_undriven, float *undriven_samples, bool *result);
|
2019-02-18 10:30:19 -08:00
|
|
|
int conf_general_autodetect_apply_sensors_foc(float current,
|
2022-11-08 02:46:35 -08:00
|
|
|
bool store_mcconf_on_success, bool send_mcconf_on_success, int *result);
|
2020-03-16 10:32:39 -07:00
|
|
|
void conf_general_calc_apply_foc_cc_kp_ki_gain(mc_configuration *mcconf, float tc);
|
2019-02-18 10:30:19 -08:00
|
|
|
int conf_general_detect_apply_all_foc(float max_power_loss,
|
2022-11-08 02:46:35 -08:00
|
|
|
bool store_mcconf_on_success, bool send_mcconf_on_success);
|
2019-02-18 10:30:19 -08:00
|
|
|
int conf_general_detect_apply_all_foc_can(bool detect_can, float max_power_loss,
|
2022-11-22 09:18:38 -08:00
|
|
|
float min_current_in, float max_current_in,
|
|
|
|
float openloop_rpm, float sl_erpm,
|
|
|
|
void(*reply_func)(unsigned char* data, unsigned int len));
|
2014-09-14 14:08:22 -07:00
|
|
|
|
2021-08-20 05:59:36 -07:00
|
|
|
|
2014-04-14 14:02:45 -07:00
|
|
|
#endif /* CONF_GENERAL_H_ */
|