2014-11-23 11:29:36 -08:00
|
|
|
/*
|
|
|
|
Copyright 2012-2014 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hw_40.6
|
|
|
|
*
|
|
|
|
* Created on: 22 nov 2014
|
|
|
|
* Author: benjamin
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_46_H_
|
|
|
|
#define HW_46_H_
|
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
#define HW_NAME "46"
|
|
|
|
|
2014-11-23 11:29:36 -08:00
|
|
|
// 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))
|
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
#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)
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ADC Vector
|
|
|
|
*
|
|
|
|
* 0: IN0 SENS3
|
|
|
|
* 1: IN1 SENS2
|
|
|
|
* 2: IN2 SENS1
|
|
|
|
* 3: IN5 CURR2
|
|
|
|
* 4: IN6 CURR1
|
|
|
|
* 5: IN3 NC
|
2015-08-23 09:26:05 -07:00
|
|
|
* 6: Vrefint
|
2014-11-23 11:29:36 -08:00
|
|
|
* 7: IN11 NC
|
|
|
|
* 8: IN12 AN_IN
|
|
|
|
* 9: IN4 TEMP_MOSFET
|
|
|
|
* 10: IN15 ADC_EXT
|
2015-08-23 09:26:05 -07:00
|
|
|
* 11: IN10 TEMP_MOTOR
|
2014-11-23 11:29:36 -08:00
|
|
|
*/
|
|
|
|
|
2016-11-04 07:18:34 -07:00
|
|
|
#define HW_ADC_CHANNELS 12
|
|
|
|
#define HW_ADC_INJ_CHANNELS 2
|
|
|
|
#define HW_ADC_NBR_CONV 4
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// ADC Indexes
|
2016-11-04 07:18:34 -07:00
|
|
|
#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_TEMP_MOS 9
|
|
|
|
#define ADC_IND_TEMP_MOTOR 11
|
|
|
|
#define ADC_IND_VREFINT 6
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// ADC macros and settings
|
|
|
|
|
2015-01-22 02:48:38 -08:00
|
|
|
// Component parameters (can be overridden)
|
|
|
|
#ifndef V_REG
|
2016-11-04 07:18:34 -07:00
|
|
|
#define V_REG 3.3
|
2015-01-22 02:48:38 -08:00
|
|
|
#endif
|
|
|
|
#ifndef VIN_R1
|
2016-11-04 07:18:34 -07:00
|
|
|
#define VIN_R1 39000.0
|
2015-01-22 02:48:38 -08:00
|
|
|
#endif
|
|
|
|
#ifndef VIN_R2
|
2016-11-04 07:18:34 -07:00
|
|
|
#define VIN_R2 2200.0
|
2015-01-22 02:48:38 -08:00
|
|
|
#endif
|
|
|
|
#ifndef CURRENT_AMP_GAIN
|
2016-11-04 07:18:34 -07:00
|
|
|
#define CURRENT_AMP_GAIN 10.0
|
2015-01-22 02:48:38 -08:00
|
|
|
#endif
|
|
|
|
#ifndef CURRENT_SHUNT_RES
|
2016-11-04 07:18:34 -07:00
|
|
|
#define CURRENT_SHUNT_RES 0.001
|
2015-01-22 02:48:38 -08:00
|
|
|
#endif
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// Input voltage
|
2016-11-04 07:18:34 -07:00
|
|
|
#define GET_INPUT_VOLTAGE() ((V_REG / 4095.0) * (float)ADC_Value[ADC_IND_VIN_SENS] * ((VIN_R1 + VIN_R2) / VIN_R2))
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// Voltage on ADC channel
|
2016-11-04 07:18:34 -07:00
|
|
|
#define ADC_VOLTS(ch) ((float)ADC_Value[ch] / 4095.0 * V_REG)
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// NTC Termistors
|
2016-11-04 07:18:34 -07:00
|
|
|
#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)
|
|
|
|
|
|
|
|
#define NTC_RES_MOTOR(adc_val) (10000.0 / ((4095.0 / (float)adc_val) - 1.0)) // Motor temp sensor on low side
|
2017-09-06 12:13:28 -07:00
|
|
|
#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)
|
2014-11-23 11:29:36 -08:00
|
|
|
|
2015-08-23 09:26:05 -07:00
|
|
|
// 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
|
2016-11-04 07:18:34 -07:00
|
|
|
#define CURR1_DOUBLE_SAMPLE 1
|
2015-08-23 09:26:05 -07:00
|
|
|
#endif
|
|
|
|
#ifndef CURR2_DOUBLE_SAMPLE
|
2016-11-04 07:18:34 -07:00
|
|
|
#define CURR2_DOUBLE_SAMPLE 0
|
2015-08-23 09:26:05 -07:00
|
|
|
#endif
|
|
|
|
|
2014-11-23 11:29:36 -08:00
|
|
|
// Number of servo outputs
|
2016-11-04 07:18:34 -07:00
|
|
|
#define HW_SERVO_NUM 2
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// UART Peripheral
|
2019-02-18 10:30:19 -08:00
|
|
|
#define HW_UART_DEV SD6
|
2016-11-04 07:18:34 -07:00
|
|
|
#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
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// ICU Peripheral for servo decoding
|
2018-02-28 01:22:25 -08:00
|
|
|
#define HW_ICU_TIMER TIM3
|
|
|
|
#define HW_ICU_TIM_CLK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE)
|
2016-11-04 07:18:34 -07:00
|
|
|
#define HW_ICU_DEV ICUD3
|
|
|
|
#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
|
2014-11-23 11:29:36 -08:00
|
|
|
|
|
|
|
// I2C Peripheral
|
2016-11-04 07:18:34 -07:00
|
|
|
#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
|
2014-11-23 11:29:36 -08:00
|
|
|
|
2015-04-11 01:07:36 -07:00
|
|
|
// 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
|
2016-04-27 06:32:32 -07:00
|
|
|
#define HW_ENC_TIM_ISR_CH TIM4_IRQn
|
|
|
|
#define HW_ENC_TIM_ISR_VEC TIM4_IRQHandler
|
2015-04-11 01:07:36 -07:00
|
|
|
|
|
|
|
// NRF pins
|
2016-11-04 07:18:34 -07:00
|
|
|
#define NRF_PORT_CSN HW_ICU_GPIO
|
|
|
|
#define NRF_PIN_CSN HW_ICU_PIN
|
|
|
|
#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
|
2015-04-11 01:07:36 -07:00
|
|
|
|
|
|
|
// Measurement macros
|
2016-11-04 07:18:34 -07:00
|
|
|
#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)
|
2015-04-11 01:07:36 -07:00
|
|
|
|
|
|
|
// Macros
|
2016-11-04 07:18:34 -07:00
|
|
|
#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)
|
2015-04-11 01:07:36 -07:00
|
|
|
|
2017-09-04 12:12:43 -07:00
|
|
|
// Setting limits
|
|
|
|
#define HW_LIM_CURRENT -100.0, 100.0
|
|
|
|
#define HW_LIM_CURRENT_IN -100.0, 100.0
|
|
|
|
#define HW_LIM_CURRENT_ABS 0.0, 150.0
|
|
|
|
#define HW_LIM_VIN 6.0, 57.0
|
|
|
|
#define HW_LIM_ERPM -200e3, 200e3
|
|
|
|
#define HW_LIM_DUTY_MIN 0.0, 0.1
|
|
|
|
#define HW_LIM_DUTY_MAX 0.0, 0.95
|
|
|
|
#define HW_LIM_TEMP_FET -40.0, 110.0
|
|
|
|
|
2015-09-17 14:24:55 -07:00
|
|
|
#endif /* HW_48_H_ */
|