From 19ce7ebe48718fce3a654eb5ced17a661ebaaf6f Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Thu, 7 Jul 2022 18:26:51 +0200 Subject: [PATCH] hwconf fizes --- hwconf/trampa/60_75/hw_60_75_mk2_no_limits.h | 1 + hwconf/trampa/60_75/hw_60_75_no_limits.h | 1 - hwconf/trampa/vesc_edu/hw_edu.h | 303 +---------------- .../vesc_edu/{hw_edu.c => hw_edu_core.c} | 0 hwconf/trampa/vesc_edu/hw_edu_core.h | 320 ++++++++++++++++++ hwconf/trampa/vesc_edu/hw_edu_no_limits.h | 27 ++ 6 files changed, 352 insertions(+), 300 deletions(-) rename hwconf/trampa/vesc_edu/{hw_edu.c => hw_edu_core.c} (100%) create mode 100644 hwconf/trampa/vesc_edu/hw_edu_core.h create mode 100644 hwconf/trampa/vesc_edu/hw_edu_no_limits.h diff --git a/hwconf/trampa/60_75/hw_60_75_mk2_no_limits.h b/hwconf/trampa/60_75/hw_60_75_mk2_no_limits.h index ebfb20a6..9886c27a 100644 --- a/hwconf/trampa/60_75/hw_60_75_mk2_no_limits.h +++ b/hwconf/trampa/60_75/hw_60_75_mk2_no_limits.h @@ -20,6 +20,7 @@ #ifndef HW_60_75_NO_LIMITS_H_ #define HW_60_75_NO_LIMITS_H_ +#define HW_60_75_IS_MK2 #define DISABLE_HW_LIMITS #include "hw_60_75_core.h" diff --git a/hwconf/trampa/60_75/hw_60_75_no_limits.h b/hwconf/trampa/60_75/hw_60_75_no_limits.h index 9886c27a..ebfb20a6 100644 --- a/hwconf/trampa/60_75/hw_60_75_no_limits.h +++ b/hwconf/trampa/60_75/hw_60_75_no_limits.h @@ -20,7 +20,6 @@ #ifndef HW_60_75_NO_LIMITS_H_ #define HW_60_75_NO_LIMITS_H_ -#define HW_60_75_IS_MK2 #define DISABLE_HW_LIMITS #include "hw_60_75_core.h" diff --git a/hwconf/trampa/vesc_edu/hw_edu.h b/hwconf/trampa/vesc_edu/hw_edu.h index 6622a298..1df95949 100644 --- a/hwconf/trampa/vesc_edu/hw_edu.h +++ b/hwconf/trampa/vesc_edu/hw_edu.h @@ -17,304 +17,9 @@ along with this program. If not, see . */ -#ifndef HW_60_75_H_ -#define HW_60_75_H_ +#ifndef HW_EDU_H_ +#define HW_EDU_H_ -#define HW_NAME "EDU" +#include "hw_edu_core.h" -// HW properties -#define HW_HAS_3_SHUNTS -#define HW_HAS_PHASE_SHUNTS -#define HW_HAS_PHASE_FILTERS -#define HW_HAS_DRV8313 - -// Macros -#define LED_GREEN_GPIO GPIOB -#define LED_GREEN_PIN 5 -#define LED_RED_GPIO GPIOB -#define LED_RED_PIN 7 - -#define LED_GREEN_ON() palSetPad(LED_GREEN_GPIO, LED_GREEN_PIN) -#define LED_GREEN_OFF() palClearPad(LED_GREEN_GPIO, LED_GREEN_PIN) -#define LED_RED_ON() palSetPad(LED_RED_GPIO, LED_RED_PIN) -#define LED_RED_OFF() palClearPad(LED_RED_GPIO, LED_RED_PIN) - -// For power stages with enable pins (e.g. DRV8313) -#define ENABLE_BR1() palSetPad(GPIOB, 13) -#define ENABLE_BR2() palSetPad(GPIOB, 14) -#define ENABLE_BR3() palSetPad(GPIOB, 15) -#define DISABLE_BR1() palClearPad(GPIOB, 13) -#define DISABLE_BR2() palClearPad(GPIOB, 14) -#define DISABLE_BR3() palClearPad(GPIOB, 15) -#define ENABLE_BR() palWriteGroup(GPIOB, PAL_GROUP_MASK(3), 13, 7) -#define DISABLE_BR() palWriteGroup(GPIOB, PAL_GROUP_MASK(3), 13, 0) - -#define INIT_BR() palSetPadMode(GPIOB, 13, \ - PAL_MODE_OUTPUT_PUSHPULL | \ - PAL_STM32_OSPEED_HIGHEST); \ - palSetPadMode(GPIOB, 14, \ - PAL_MODE_OUTPUT_PUSHPULL | \ - PAL_STM32_OSPEED_HIGHEST); \ - palSetPadMode(GPIOB, 15, \ - PAL_MODE_OUTPUT_PUSHPULL | \ - PAL_STM32_OSPEED_HIGHEST); \ - DISABLE_BR(); - -#define PHASE_FILTER_GPIO GPIOC -#define PHASE_FILTER_PIN 9 -#define PHASE_FILTER_ON() palSetPad(PHASE_FILTER_GPIO, PHASE_FILTER_PIN) -#define PHASE_FILTER_OFF() palClearPad(PHASE_FILTER_GPIO, PHASE_FILTER_PIN) - -// Sensor port voltage control -#define SENSOR_VOLTAGE_GPIO GPIOC -#define SENSOR_VOLTAGE_PIN 12 -#define SENSOR_PORT_5V() palSetPad(SENSOR_VOLTAGE_GPIO, SENSOR_VOLTAGE_PIN) -#define SENSOR_PORT_3V3() palClearPad(SENSOR_VOLTAGE_GPIO, SENSOR_VOLTAGE_PIN) - -#define CURRENT_FILTER_GPIO GPIOD -#define CURRENT_FILTER_PIN 2 -#define CURRENT_FILTER_ON() palSetPad(CURRENT_FILTER_GPIO, CURRENT_FILTER_PIN) -#define CURRENT_FILTER_OFF() palClearPad(CURRENT_FILTER_GPIO, CURRENT_FILTER_PIN) - -// Shutdown pin -#define HW_SHUTDOWN_GPIO GPIOC -#define HW_SHUTDOWN_PIN 5 -#define HW_SHUTDOWN_HOLD_ON() palSetPad(HW_SHUTDOWN_GPIO, HW_SHUTDOWN_PIN) -#define HW_SHUTDOWN_HOLD_OFF() palClearPad(HW_SHUTDOWN_GPIO, HW_SHUTDOWN_PIN) -#define HW_SAMPLE_SHUTDOWN() hw_sample_shutdown_button() - -// Vdiv en -#define PHASE_VDIV_GPIO GPIOA -#define PHASE_VDIV_PIN 15 - -// ZCD en -#define ZCD_GPIO GPIOC -#define ZCD_PIN 14 - -// CAN en -#define CAN_EN_GPIO GPIOB -#define CAN_EN_PIN 2 - -// Hold shutdown pin early to wake up on short pulses -#define HW_EARLY_INIT() palSetPadMode(HW_SHUTDOWN_GPIO, HW_SHUTDOWN_PIN, PAL_MODE_OUTPUT_PUSHPULL); \ - HW_SHUTDOWN_HOLD_ON(); \ - palSetPadMode(PHASE_VDIV_GPIO, PHASE_VDIV_PIN, PAL_MODE_OUTPUT_PUSHPULL); \ - palSetPad(PHASE_VDIV_GPIO, PHASE_VDIV_PIN); -/* - * ADC Vector - * - * 0 (1): IN0 SENS1 - * 1 (2): IN1 SENS2 - * 2 (3): IN2 SENS3 - * 3 (1): IN10 CURR1 - * 4 (2): IN11 CURR2 - * 5 (3): IN12 CURR3 - * 6 (1): IN5 ADC_EXT1 - * 7 (2): IN6 ADC_EXT2 - * 8 (3): IN3 TEMP_MOS - * 9 (1): IN14 TEMP_MOTOR - * 10 (2): IN15 Shutdown - * 11 (3): IN13 AN_IN - * 12 (1): Vrefint - * 13 (2): IN0 SENS1 - * 14 (3): IN1 SENS2 - * 15 (1): IN8 TEMP_MOS_2 - * 16 (2): IN9 TEMP_MOS_3 - * 17 (3): IN3 SENS3 - */ - -#define HW_ADC_CHANNELS 18 -#define HW_ADC_INJ_CHANNELS 3 -#define HW_ADC_NBR_CONV 6 - -// ADC Indexes -#define ADC_IND_SENS1 3 -#define ADC_IND_SENS2 4 -#define ADC_IND_SENS3 5 -#define ADC_IND_CURR1 0 -#define ADC_IND_CURR2 1 -#define ADC_IND_CURR3 2 -#define ADC_IND_VIN_SENS 11 -#define ADC_IND_EXT 6 -#define ADC_IND_EXT2 7 -#define ADC_IND_SHUTDOWN 10 -#define ADC_IND_TEMP_MOS 8 -#define ADC_IND_TEMP_MOTOR 9 -#define ADC_IND_VREFINT 12 - -// ADC macros and settings - -// Component parameters (can be overridden) -#ifndef V_REG -#define V_REG 3.3 -#endif -#ifndef VIN_R1 -#define VIN_R1 22000.0 -#endif -#ifndef VIN_R2 -#define VIN_R2 2200.0 -#endif -#ifndef CURRENT_AMP_GAIN -#define CURRENT_AMP_GAIN 50.0 -#endif -#ifndef CURRENT_SHUNT_RES -#define CURRENT_SHUNT_RES 0.0005 -#endif - -// Input voltage -#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2)) - -// NTC Termistors -#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) / 3380.0) + (1.0 / 298.15)) - 273.15) - -#define NTC_RES_MOTOR(adc_val) (10000.0 / ((4095.0 / (float)adc_val) - 1.0)) -#define NTC_TEMP_MOTOR(beta) (1.0 / ((logf(NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR]) / 10000.0) / beta) + (1.0 / 298.15)) - 273.15) - -// Voltage on ADC channel -#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG) - -// COMM-port ADC GPIOs -#define HW_ADC_EXT_GPIO GPIOA -#define HW_ADC_EXT_PIN 5 -#define HW_ADC_EXT2_GPIO GPIOA -#define HW_ADC_EXT2_PIN 6 - -// UART Peripheral -#define HW_UART_DEV SD3 -#define HW_UART_GPIO_AF GPIO_AF_USART3 -#define HW_UART_TX_PORT GPIOB -#define HW_UART_TX_PIN 10 -#define HW_UART_RX_PORT GPIOB -#define HW_UART_RX_PIN 11 - -// ICU Peripheral for servo decoding -#define HW_USE_SERVO_TIM4 -#define HW_ICU_TIMER TIM4 -#define HW_ICU_TIM_CLK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE) -#define HW_ICU_DEV ICUD4 -#define HW_ICU_CHANNEL ICU_CHANNEL_1 -#define HW_ICU_GPIO_AF GPIO_AF_TIM4 -#define HW_ICU_GPIO GPIOB -#define HW_ICU_PIN 6 - -// 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 GPIOC -#define HW_HALL_ENC_PIN1 6 -#define HW_HALL_ENC_GPIO2 GPIOC -#define HW_HALL_ENC_PIN2 7 -#define HW_HALL_ENC_GPIO3 GPIOC -#define HW_HALL_ENC_PIN3 8 -#define HW_ENC_TIM TIM3 -#define HW_ENC_TIM_AF GPIO_AF_TIM3 -#define HW_ENC_TIM_CLK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE) -#define HW_ENC_EXTI_PORTSRC EXTI_PortSourceGPIOC -#define HW_ENC_EXTI_PINSRC EXTI_PinSource8 -#define HW_ENC_EXTI_CH EXTI9_5_IRQn -#define HW_ENC_EXTI_LINE EXTI_Line8 -#define HW_ENC_EXTI_ISR_VEC EXTI9_5_IRQHandler -#define HW_ENC_TIM_ISR_CH TIM3_IRQn -#define HW_ENC_TIM_ISR_VEC TIM3_IRQHandler - -// SPI pins -#define HW_SPI_DEV SPID1 -#define HW_SPI_GPIO_AF GPIO_AF_SPI1 -#define HW_SPI_PORT_NSS GPIOB -#define HW_SPI_PIN_NSS 11 -#define HW_SPI_PORT_SCK GPIOA -#define HW_SPI_PIN_SCK 5 -#define HW_SPI_PORT_MOSI GPIOA -#define HW_SPI_PIN_MOSI 7 -#define HW_SPI_PORT_MISO GPIOA -#define HW_SPI_PIN_MISO 6 - -// BMI160 -#define BMI160_SPI_PORT_NSS GPIOC -#define BMI160_SPI_PIN_NSS 13 -#define BMI160_SPI_PORT_SCK GPIOB -#define BMI160_SPI_PIN_SCK 12 -#define BMI160_SPI_PORT_MOSI GPIOB -#define BMI160_SPI_PIN_MOSI 3 -#define BMI160_SPI_PORT_MISO GPIOB -#define BMI160_SPI_PIN_MISO 4 - -// NRF SWD -#define NRF5x_SWDIO_GPIO GPIOB -#define NRF5x_SWDIO_PIN 0 -#define NRF5x_SWCLK_GPIO GPIOB -#define NRF5x_SWCLK_PIN 1 - -// Permanent UART -#define HW_UART_P_BAUD 115200 -#define HW_UART_P_DEV SD4 -#define HW_UART_P_DEV_TX SD4 -#define HW_UART_P_GPIO_AF GPIO_AF_UART4 -#define HW_UART_P_TX_PORT GPIOC -#define HW_UART_P_TX_PIN 10 -#define HW_UART_P_RX_PORT GPIOC -#define HW_UART_P_RX_PIN 11 - -// 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) - -#define HW_DEAD_TIME_NSEC 50.0 - -// Default setting overrides -#ifndef MCCONF_L_MIN_VOLTAGE -#define MCCONF_L_MIN_VOLTAGE 6.0 // Minimum input voltage -#endif -#ifndef MCCONF_L_MAX_VOLTAGE -#define MCCONF_L_MAX_VOLTAGE 26.0 // Maximum input voltage -#endif -#ifndef MCCONF_DEFAULT_MOTOR_TYPE -#define MCCONF_DEFAULT_MOTOR_TYPE MOTOR_TYPE_FOC -#endif -#ifndef MCCONF_FOC_F_ZV -#define MCCONF_FOC_F_ZV 30000.0 -#endif -#ifndef MCCONF_L_MAX_ABS_CURRENT -#define MCCONF_L_MAX_ABS_CURRENT 65.0 // The maximum absolute current above which a fault is generated -#endif -#ifndef MCCONF_L_CURRENT_MAX -#define MCCONF_L_CURRENT_MAX 20.0 // Current limit in Amperes (Upper) -#endif -#ifndef MCCONF_L_CURRENT_MIN -#define MCCONF_L_CURRENT_MIN -20.0 // Current limit in Amperes (Lower) -#endif -#ifndef MCCONF_L_IN_CURRENT_MAX -#define MCCONF_L_IN_CURRENT_MAX 20.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 - -// Setting limits -#define HW_LIM_CURRENT -55.0, 55.0 -#define HW_LIM_CURRENT_IN -55.0, 55.0 -#define HW_LIM_CURRENT_ABS 0.0, 65.0 -#define HW_LIM_VIN 5.5, 27.0 -#define HW_LIM_ERPM -200e3, 200e3 -#define HW_LIM_DUTY_MIN 0.0, 0.1 -#define HW_LIM_DUTY_MAX 0.0, 0.99 -#define HW_LIM_TEMP_FET -40.0, 110.0 - -// Functions -bool hw_sample_shutdown_button(void); - -#endif /* HW_60_75_H_ */ +#endif /* HW_EDU_H_ */ diff --git a/hwconf/trampa/vesc_edu/hw_edu.c b/hwconf/trampa/vesc_edu/hw_edu_core.c similarity index 100% rename from hwconf/trampa/vesc_edu/hw_edu.c rename to hwconf/trampa/vesc_edu/hw_edu_core.c diff --git a/hwconf/trampa/vesc_edu/hw_edu_core.h b/hwconf/trampa/vesc_edu/hw_edu_core.h new file mode 100644 index 00000000..ed0bea63 --- /dev/null +++ b/hwconf/trampa/vesc_edu/hw_edu_core.h @@ -0,0 +1,320 @@ +/* + Copyright 2022 Benjamin Vedder benjamin@vedder.se + + This file is part of the VESC firmware. + + The VESC firmware 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. + + The VESC firmware 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 . + */ + +#ifndef HW_EDU_CORE_H_ +#define HW_EDU_CORE_H_ + +#define HW_NAME "EDU" + +// HW properties +#define HW_HAS_3_SHUNTS +#define HW_HAS_PHASE_SHUNTS +#define HW_HAS_PHASE_FILTERS +#define HW_HAS_DRV8313 + +// Macros +#define LED_GREEN_GPIO GPIOB +#define LED_GREEN_PIN 5 +#define LED_RED_GPIO GPIOB +#define LED_RED_PIN 7 + +#define LED_GREEN_ON() palSetPad(LED_GREEN_GPIO, LED_GREEN_PIN) +#define LED_GREEN_OFF() palClearPad(LED_GREEN_GPIO, LED_GREEN_PIN) +#define LED_RED_ON() palSetPad(LED_RED_GPIO, LED_RED_PIN) +#define LED_RED_OFF() palClearPad(LED_RED_GPIO, LED_RED_PIN) + +// For power stages with enable pins (e.g. DRV8313) +#define ENABLE_BR1() palSetPad(GPIOB, 13) +#define ENABLE_BR2() palSetPad(GPIOB, 14) +#define ENABLE_BR3() palSetPad(GPIOB, 15) +#define DISABLE_BR1() palClearPad(GPIOB, 13) +#define DISABLE_BR2() palClearPad(GPIOB, 14) +#define DISABLE_BR3() palClearPad(GPIOB, 15) +#define ENABLE_BR() palWriteGroup(GPIOB, PAL_GROUP_MASK(3), 13, 7) +#define DISABLE_BR() palWriteGroup(GPIOB, PAL_GROUP_MASK(3), 13, 0) + +#define INIT_BR() palSetPadMode(GPIOB, 13, \ + PAL_MODE_OUTPUT_PUSHPULL | \ + PAL_STM32_OSPEED_HIGHEST); \ + palSetPadMode(GPIOB, 14, \ + PAL_MODE_OUTPUT_PUSHPULL | \ + PAL_STM32_OSPEED_HIGHEST); \ + palSetPadMode(GPIOB, 15, \ + PAL_MODE_OUTPUT_PUSHPULL | \ + PAL_STM32_OSPEED_HIGHEST); \ + DISABLE_BR(); + +#define PHASE_FILTER_GPIO GPIOC +#define PHASE_FILTER_PIN 9 +#define PHASE_FILTER_ON() palSetPad(PHASE_FILTER_GPIO, PHASE_FILTER_PIN) +#define PHASE_FILTER_OFF() palClearPad(PHASE_FILTER_GPIO, PHASE_FILTER_PIN) + +// Sensor port voltage control +#define SENSOR_VOLTAGE_GPIO GPIOC +#define SENSOR_VOLTAGE_PIN 12 +#define SENSOR_PORT_5V() palSetPad(SENSOR_VOLTAGE_GPIO, SENSOR_VOLTAGE_PIN) +#define SENSOR_PORT_3V3() palClearPad(SENSOR_VOLTAGE_GPIO, SENSOR_VOLTAGE_PIN) + +#define CURRENT_FILTER_GPIO GPIOD +#define CURRENT_FILTER_PIN 2 +#define CURRENT_FILTER_ON() palSetPad(CURRENT_FILTER_GPIO, CURRENT_FILTER_PIN) +#define CURRENT_FILTER_OFF() palClearPad(CURRENT_FILTER_GPIO, CURRENT_FILTER_PIN) + +// Shutdown pin +#define HW_SHUTDOWN_GPIO GPIOC +#define HW_SHUTDOWN_PIN 5 +#define HW_SHUTDOWN_HOLD_ON() palSetPad(HW_SHUTDOWN_GPIO, HW_SHUTDOWN_PIN) +#define HW_SHUTDOWN_HOLD_OFF() palClearPad(HW_SHUTDOWN_GPIO, HW_SHUTDOWN_PIN) +#define HW_SAMPLE_SHUTDOWN() hw_sample_shutdown_button() + +// Vdiv en +#define PHASE_VDIV_GPIO GPIOA +#define PHASE_VDIV_PIN 15 + +// ZCD en +#define ZCD_GPIO GPIOC +#define ZCD_PIN 14 + +// CAN en +#define CAN_EN_GPIO GPIOB +#define CAN_EN_PIN 2 + +// Hold shutdown pin early to wake up on short pulses +#define HW_EARLY_INIT() palSetPadMode(HW_SHUTDOWN_GPIO, HW_SHUTDOWN_PIN, PAL_MODE_OUTPUT_PUSHPULL); \ + HW_SHUTDOWN_HOLD_ON(); \ + palSetPadMode(PHASE_VDIV_GPIO, PHASE_VDIV_PIN, PAL_MODE_OUTPUT_PUSHPULL); \ + palSetPad(PHASE_VDIV_GPIO, PHASE_VDIV_PIN); +/* + * ADC Vector + * + * 0 (1): IN0 SENS1 + * 1 (2): IN1 SENS2 + * 2 (3): IN2 SENS3 + * 3 (1): IN10 CURR1 + * 4 (2): IN11 CURR2 + * 5 (3): IN12 CURR3 + * 6 (1): IN5 ADC_EXT1 + * 7 (2): IN6 ADC_EXT2 + * 8 (3): IN3 TEMP_MOS + * 9 (1): IN14 TEMP_MOTOR + * 10 (2): IN15 Shutdown + * 11 (3): IN13 AN_IN + * 12 (1): Vrefint + * 13 (2): IN0 SENS1 + * 14 (3): IN1 SENS2 + * 15 (1): IN8 TEMP_MOS_2 + * 16 (2): IN9 TEMP_MOS_3 + * 17 (3): IN3 SENS3 + */ + +#define HW_ADC_CHANNELS 18 +#define HW_ADC_INJ_CHANNELS 3 +#define HW_ADC_NBR_CONV 6 + +// ADC Indexes +#define ADC_IND_SENS1 3 +#define ADC_IND_SENS2 4 +#define ADC_IND_SENS3 5 +#define ADC_IND_CURR1 0 +#define ADC_IND_CURR2 1 +#define ADC_IND_CURR3 2 +#define ADC_IND_VIN_SENS 11 +#define ADC_IND_EXT 6 +#define ADC_IND_EXT2 7 +#define ADC_IND_SHUTDOWN 10 +#define ADC_IND_TEMP_MOS 8 +#define ADC_IND_TEMP_MOTOR 9 +#define ADC_IND_VREFINT 12 + +// ADC macros and settings + +// Component parameters (can be overridden) +#ifndef V_REG +#define V_REG 3.3 +#endif +#ifndef VIN_R1 +#define VIN_R1 22000.0 +#endif +#ifndef VIN_R2 +#define VIN_R2 2200.0 +#endif +#ifndef CURRENT_AMP_GAIN +#define CURRENT_AMP_GAIN 50.0 +#endif +#ifndef CURRENT_SHUNT_RES +#define CURRENT_SHUNT_RES 0.0005 +#endif + +// Input voltage +#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2)) + +// NTC Termistors +#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) / 3380.0) + (1.0 / 298.15)) - 273.15) + +#define NTC_RES_MOTOR(adc_val) (10000.0 / ((4095.0 / (float)adc_val) - 1.0)) +#define NTC_TEMP_MOTOR(beta) (1.0 / ((logf(NTC_RES_MOTOR(ADC_Value[ADC_IND_TEMP_MOTOR]) / 10000.0) / beta) + (1.0 / 298.15)) - 273.15) + +// Voltage on ADC channel +#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4096.0 * V_REG) + +// COMM-port ADC GPIOs +#define HW_ADC_EXT_GPIO GPIOA +#define HW_ADC_EXT_PIN 5 +#define HW_ADC_EXT2_GPIO GPIOA +#define HW_ADC_EXT2_PIN 6 + +// UART Peripheral +#define HW_UART_DEV SD3 +#define HW_UART_GPIO_AF GPIO_AF_USART3 +#define HW_UART_TX_PORT GPIOB +#define HW_UART_TX_PIN 10 +#define HW_UART_RX_PORT GPIOB +#define HW_UART_RX_PIN 11 + +// ICU Peripheral for servo decoding +#define HW_USE_SERVO_TIM4 +#define HW_ICU_TIMER TIM4 +#define HW_ICU_TIM_CLK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE) +#define HW_ICU_DEV ICUD4 +#define HW_ICU_CHANNEL ICU_CHANNEL_1 +#define HW_ICU_GPIO_AF GPIO_AF_TIM4 +#define HW_ICU_GPIO GPIOB +#define HW_ICU_PIN 6 + +// 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 GPIOC +#define HW_HALL_ENC_PIN1 6 +#define HW_HALL_ENC_GPIO2 GPIOC +#define HW_HALL_ENC_PIN2 7 +#define HW_HALL_ENC_GPIO3 GPIOC +#define HW_HALL_ENC_PIN3 8 +#define HW_ENC_TIM TIM3 +#define HW_ENC_TIM_AF GPIO_AF_TIM3 +#define HW_ENC_TIM_CLK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE) +#define HW_ENC_EXTI_PORTSRC EXTI_PortSourceGPIOC +#define HW_ENC_EXTI_PINSRC EXTI_PinSource8 +#define HW_ENC_EXTI_CH EXTI9_5_IRQn +#define HW_ENC_EXTI_LINE EXTI_Line8 +#define HW_ENC_EXTI_ISR_VEC EXTI9_5_IRQHandler +#define HW_ENC_TIM_ISR_CH TIM3_IRQn +#define HW_ENC_TIM_ISR_VEC TIM3_IRQHandler + +// SPI pins +#define HW_SPI_DEV SPID1 +#define HW_SPI_GPIO_AF GPIO_AF_SPI1 +#define HW_SPI_PORT_NSS GPIOB +#define HW_SPI_PIN_NSS 11 +#define HW_SPI_PORT_SCK GPIOA +#define HW_SPI_PIN_SCK 5 +#define HW_SPI_PORT_MOSI GPIOA +#define HW_SPI_PIN_MOSI 7 +#define HW_SPI_PORT_MISO GPIOA +#define HW_SPI_PIN_MISO 6 + +// BMI160 +#define BMI160_SPI_PORT_NSS GPIOC +#define BMI160_SPI_PIN_NSS 13 +#define BMI160_SPI_PORT_SCK GPIOB +#define BMI160_SPI_PIN_SCK 12 +#define BMI160_SPI_PORT_MOSI GPIOB +#define BMI160_SPI_PIN_MOSI 3 +#define BMI160_SPI_PORT_MISO GPIOB +#define BMI160_SPI_PIN_MISO 4 + +// NRF SWD +#define NRF5x_SWDIO_GPIO GPIOB +#define NRF5x_SWDIO_PIN 0 +#define NRF5x_SWCLK_GPIO GPIOB +#define NRF5x_SWCLK_PIN 1 + +// Permanent UART +#define HW_UART_P_BAUD 115200 +#define HW_UART_P_DEV SD4 +#define HW_UART_P_DEV_TX SD4 +#define HW_UART_P_GPIO_AF GPIO_AF_UART4 +#define HW_UART_P_TX_PORT GPIOC +#define HW_UART_P_TX_PIN 10 +#define HW_UART_P_RX_PORT GPIOC +#define HW_UART_P_RX_PIN 11 + +// 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) + +#define HW_DEAD_TIME_NSEC 50.0 + +// Default setting overrides +#ifndef MCCONF_L_MIN_VOLTAGE +#define MCCONF_L_MIN_VOLTAGE 6.0 // Minimum input voltage +#endif +#ifndef MCCONF_L_MAX_VOLTAGE +#define MCCONF_L_MAX_VOLTAGE 26.0 // Maximum input voltage +#endif +#ifndef MCCONF_DEFAULT_MOTOR_TYPE +#define MCCONF_DEFAULT_MOTOR_TYPE MOTOR_TYPE_FOC +#endif +#ifndef MCCONF_FOC_F_ZV +#define MCCONF_FOC_F_ZV 30000.0 +#endif +#ifndef MCCONF_L_MAX_ABS_CURRENT +#define MCCONF_L_MAX_ABS_CURRENT 65.0 // The maximum absolute current above which a fault is generated +#endif +#ifndef MCCONF_L_CURRENT_MAX +#define MCCONF_L_CURRENT_MAX 20.0 // Current limit in Amperes (Upper) +#endif +#ifndef MCCONF_L_CURRENT_MIN +#define MCCONF_L_CURRENT_MIN -20.0 // Current limit in Amperes (Lower) +#endif +#ifndef MCCONF_L_IN_CURRENT_MAX +#define MCCONF_L_IN_CURRENT_MAX 20.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 + +// Setting limits +#define HW_LIM_CURRENT -55.0, 55.0 +#define HW_LIM_CURRENT_IN -55.0, 55.0 +#define HW_LIM_CURRENT_ABS 0.0, 65.0 +#define HW_LIM_VIN 5.5, 27.0 +#define HW_LIM_ERPM -200e3, 200e3 +#define HW_LIM_DUTY_MIN 0.0, 0.1 +#define HW_LIM_DUTY_MAX 0.0, 0.99 +#define HW_LIM_TEMP_FET -40.0, 110.0 + +// Functions +bool hw_sample_shutdown_button(void); + +#endif /* HW_EDU_CORE_H_ */ diff --git a/hwconf/trampa/vesc_edu/hw_edu_no_limits.h b/hwconf/trampa/vesc_edu/hw_edu_no_limits.h new file mode 100644 index 00000000..34f2601c --- /dev/null +++ b/hwconf/trampa/vesc_edu/hw_edu_no_limits.h @@ -0,0 +1,27 @@ +/* + Copyright 2022 Benjamin Vedder benjamin@vedder.se + + This file is part of the VESC firmware. + + The VESC firmware 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. + + The VESC firmware 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 . + */ + +#ifndef HW_EDU_NO_LIMITS_H_ +#define HW_EDU_NO_LIMITS_H_ + +#define DISABLE_HW_LIMITS + +#include "hw_edu_core.h" + +#endif /* HW_EDU_NO_LIMITS_H_ */