nucleo-f446re: add FOC example based on IHM08M1 expansion board
This commit is contained in:
parent
0186ec1e05
commit
2b309349fe
@ -573,3 +573,67 @@ Configurations
|
||||
CLK D3
|
||||
|
||||
Framebuffer application can be started from terminal by typing "fb".
|
||||
|
||||
ihm08m1_f32 and ihm08m1_b16:
|
||||
----------------------------
|
||||
|
||||
These examples are dedicated for the X-NUCLEO-IHM08M1 expansion board with
|
||||
L6398 gate drivers and discrete transistors.
|
||||
|
||||
WARNING: L6398 gate drivers require channel 2 negative polarisation and
|
||||
negative sign for the deadtime. Make sure that your gate drivers logic
|
||||
is compatible with this configuration.
|
||||
|
||||
X-NUCLEO-IHM08M1 must be configured to work with FOC and 3-shunt
|
||||
resistors. See ST documentation for details.
|
||||
|
||||
Pin configuration for the X-NUCLEO-IHM08M1 (TIM1 configuration):
|
||||
|
||||
Board Function Chip Function Chip Pin Number
|
||||
------------- ---------------- -----------------
|
||||
Phase U high TIM1_CH1 PA8
|
||||
Phase U low TIM1_CH1N PA7
|
||||
Phase V high TIM1_CH2 PA9
|
||||
Phase V low TIM1_CH2N PB0
|
||||
Phase W high TIM1_CH3 PA10
|
||||
Phase W low TIM1_CH3N PB1
|
||||
Current U ADC1_IN0 PA0
|
||||
Current V ADC1_IN11 PC1
|
||||
Current W ADC1_IN10 PC0
|
||||
Temperature ADC1_IN12 PC2
|
||||
VBUS ADC1_IN1 PA1
|
||||
BEMF1 (NU) PC3
|
||||
BEMF2 (NU) PC4
|
||||
BEMF3 (NU) PC5
|
||||
LED GPIO_PB2 PB2
|
||||
+3V3 (CN7_16)
|
||||
GND (CN7_20)
|
||||
GPIO_BEMF (NU) PC9
|
||||
ENCO_A/HALL_H1 TIM2_CH1 PA15
|
||||
ENCO_B/HALL_H2 TIM2_CH2 PB3
|
||||
ENCO_Z/HALL_H3 TIM2_CH3 PB10
|
||||
DAC (NU) PA5
|
||||
GPIO3 (NU) PB13
|
||||
CPOUT (NU) PA12
|
||||
BKIN1 (NU) PA6
|
||||
BKIN2 (NU) PA11
|
||||
BKIN3 (NU) PB14
|
||||
POT/DAC DAC1_CH1/ADC1_IN4 PA4
|
||||
CURR_REF (NU) PB4
|
||||
DEBUG0 GPIO PB12
|
||||
DEBUG1 GPIO PB9
|
||||
DEBUG2 GPIO PC6
|
||||
DEBUG3 GPIO PB5
|
||||
DEBUG4 GPIO PC8
|
||||
|
||||
Current shunt resistance = 0.01
|
||||
Current sense gain = -5.18 (inverted current)
|
||||
Vbus sense gain = 9.31k/(9.31k+169k) = 0.0522
|
||||
Vbus min = 10V
|
||||
Vbus max = 48V
|
||||
Iout max = 15A RMS
|
||||
|
||||
IPHASE_RATIO = 1/(R_shunt*gain) = -19.3
|
||||
VBUS_RATIO = 1/VBUS_gain = 19.152
|
||||
|
||||
For now only 3-shunt resistors configuration is supported.
|
||||
|
92
boards/arm/stm32/nucleo-f446re/configs/ihm08m1_b16/defconfig
Normal file
92
boards/arm/stm32/nucleo-f446re/configs/ihm08m1_b16/defconfig
Normal file
@ -0,0 +1,92 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
CONFIG_ADC=y
|
||||
CONFIG_ADC_FIFOSIZE=3
|
||||
CONFIG_ANALOG=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-f446re"
|
||||
CONFIG_ARCH_BOARD_NUCLEO_F446RE=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32"
|
||||
CONFIG_ARCH_CHIP_STM32=y
|
||||
CONFIG_ARCH_CHIP_STM32F446R=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=1024
|
||||
CONFIG_ARCH_IRQBUTTONS=y
|
||||
CONFIG_ARMV7M_LIBM=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=8499
|
||||
CONFIG_BOARD_STM32_COMMON=y
|
||||
CONFIG_BOARD_STM32_IHM08M1=y
|
||||
CONFIG_BOARD_STM32_IHM08M1_POT=y
|
||||
CONFIG_BOARD_STM32_IHM08M1_VBUS=y
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEFAULT_SMALL=y
|
||||
CONFIG_DEFAULT_TASK_STACKSIZE=1024
|
||||
CONFIG_EXAMPLES_FOC=y
|
||||
CONFIG_EXAMPLES_FOC_ADC_MAX=4095
|
||||
CONFIG_EXAMPLES_FOC_ADC_VREF=3300
|
||||
CONFIG_EXAMPLES_FOC_CONTROL_STACKSIZE=2048
|
||||
CONFIG_EXAMPLES_FOC_FIXED16_INST=1
|
||||
CONFIG_EXAMPLES_FOC_HAVE_BUTTON=y
|
||||
CONFIG_EXAMPLES_FOC_IPHASE_ADC=-1555
|
||||
CONFIG_EXAMPLES_FOC_RAMP_ACC=200000
|
||||
CONFIG_EXAMPLES_FOC_RAMP_DEC=200000
|
||||
CONFIG_EXAMPLES_FOC_RAMP_THR=10000
|
||||
CONFIG_EXAMPLES_FOC_VBUS_ADC=y
|
||||
CONFIG_EXAMPLES_FOC_VBUS_SCALE=19152
|
||||
CONFIG_EXAMPLES_FOC_VEL_ADC=y
|
||||
CONFIG_INDUSTRY_FOC=y
|
||||
CONFIG_INDUSTRY_FOC_FIXED16=y
|
||||
CONFIG_INPUT=y
|
||||
CONFIG_INPUT_BUTTONS=y
|
||||
CONFIG_INPUT_BUTTONS_LOWER=y
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_LIBM=y
|
||||
CONFIG_MAX_TASKS=8
|
||||
CONFIG_MOTOR=y
|
||||
CONFIG_MOTOR_FOC=y
|
||||
CONFIG_MOTOR_FOC_TRACE=y
|
||||
CONFIG_MQ_MAXMSGSIZE=5
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=16386
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_START_DAY=14
|
||||
CONFIG_START_MONTH=10
|
||||
CONFIG_START_YEAR=2014
|
||||
CONFIG_STM32_ADC1_ANIOC_TRIGGER=1
|
||||
CONFIG_STM32_ADC1_DMA=y
|
||||
CONFIG_STM32_ADC1_DMA_CFG=1
|
||||
CONFIG_STM32_ADC1_INJECTED_CHAN=3
|
||||
CONFIG_STM32_DMA1=y
|
||||
CONFIG_STM32_DMA2=y
|
||||
CONFIG_STM32_FOC=y
|
||||
CONFIG_STM32_FOC_FOC0=y
|
||||
CONFIG_STM32_JTAG_SW_ENABLE=y
|
||||
CONFIG_STM32_TIM1_CH1MODE=0
|
||||
CONFIG_STM32_TIM1_CH1NPOL=1
|
||||
CONFIG_STM32_TIM1_CH2MODE=0
|
||||
CONFIG_STM32_TIM1_CH2NPOL=1
|
||||
CONFIG_STM32_TIM1_CH3MODE=0
|
||||
CONFIG_STM32_TIM1_CH3NPOL=1
|
||||
CONFIG_STM32_TIM1_MODE=2
|
||||
CONFIG_STM32_TIM2=y
|
||||
CONFIG_STM32_USART1=y
|
||||
CONFIG_STM32_USART2=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=0
|
||||
CONFIG_USART2_SERIAL_CONSOLE=y
|
||||
CONFIG_USART2_TXDMA=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
92
boards/arm/stm32/nucleo-f446re/configs/ihm08m1_f32/defconfig
Normal file
92
boards/arm/stm32/nucleo-f446re/configs/ihm08m1_f32/defconfig
Normal file
@ -0,0 +1,92 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
CONFIG_ADC=y
|
||||
CONFIG_ADC_FIFOSIZE=3
|
||||
CONFIG_ANALOG=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nucleo-f446re"
|
||||
CONFIG_ARCH_BOARD_NUCLEO_F446RE=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="stm32"
|
||||
CONFIG_ARCH_CHIP_STM32=y
|
||||
CONFIG_ARCH_CHIP_STM32F446R=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=1024
|
||||
CONFIG_ARCH_IRQBUTTONS=y
|
||||
CONFIG_ARMV7M_LIBM=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=8499
|
||||
CONFIG_BOARD_STM32_COMMON=y
|
||||
CONFIG_BOARD_STM32_IHM08M1=y
|
||||
CONFIG_BOARD_STM32_IHM08M1_POT=y
|
||||
CONFIG_BOARD_STM32_IHM08M1_VBUS=y
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEFAULT_SMALL=y
|
||||
CONFIG_DEFAULT_TASK_STACKSIZE=1024
|
||||
CONFIG_EXAMPLES_FOC=y
|
||||
CONFIG_EXAMPLES_FOC_ADC_MAX=4095
|
||||
CONFIG_EXAMPLES_FOC_ADC_VREF=3300
|
||||
CONFIG_EXAMPLES_FOC_CONTROL_STACKSIZE=2048
|
||||
CONFIG_EXAMPLES_FOC_FLOAT_INST=1
|
||||
CONFIG_EXAMPLES_FOC_HAVE_BUTTON=y
|
||||
CONFIG_EXAMPLES_FOC_IPHASE_ADC=-1555
|
||||
CONFIG_EXAMPLES_FOC_RAMP_ACC=200000
|
||||
CONFIG_EXAMPLES_FOC_RAMP_DEC=200000
|
||||
CONFIG_EXAMPLES_FOC_RAMP_THR=10000
|
||||
CONFIG_EXAMPLES_FOC_VBUS_ADC=y
|
||||
CONFIG_EXAMPLES_FOC_VBUS_SCALE=19152
|
||||
CONFIG_EXAMPLES_FOC_VEL_ADC=y
|
||||
CONFIG_INDUSTRY_FOC=y
|
||||
CONFIG_INDUSTRY_FOC_FLOAT=y
|
||||
CONFIG_INPUT=y
|
||||
CONFIG_INPUT_BUTTONS=y
|
||||
CONFIG_INPUT_BUTTONS_LOWER=y
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_LIBM=y
|
||||
CONFIG_MAX_TASKS=8
|
||||
CONFIG_MOTOR=y
|
||||
CONFIG_MOTOR_FOC=y
|
||||
CONFIG_MOTOR_FOC_TRACE=y
|
||||
CONFIG_MQ_MAXMSGSIZE=5
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=16386
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_START_DAY=14
|
||||
CONFIG_START_MONTH=10
|
||||
CONFIG_START_YEAR=2014
|
||||
CONFIG_STM32_ADC1_ANIOC_TRIGGER=1
|
||||
CONFIG_STM32_ADC1_DMA=y
|
||||
CONFIG_STM32_ADC1_DMA_CFG=1
|
||||
CONFIG_STM32_ADC1_INJECTED_CHAN=3
|
||||
CONFIG_STM32_DMA1=y
|
||||
CONFIG_STM32_DMA2=y
|
||||
CONFIG_STM32_FOC=y
|
||||
CONFIG_STM32_FOC_FOC0=y
|
||||
CONFIG_STM32_JTAG_SW_ENABLE=y
|
||||
CONFIG_STM32_TIM1_CH1MODE=0
|
||||
CONFIG_STM32_TIM1_CH1NPOL=1
|
||||
CONFIG_STM32_TIM1_CH2MODE=0
|
||||
CONFIG_STM32_TIM1_CH2NPOL=1
|
||||
CONFIG_STM32_TIM1_CH3MODE=0
|
||||
CONFIG_STM32_TIM1_CH3NPOL=1
|
||||
CONFIG_STM32_TIM1_MODE=2
|
||||
CONFIG_STM32_TIM2=y
|
||||
CONFIG_STM32_USART1=y
|
||||
CONFIG_STM32_USART2=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=0
|
||||
CONFIG_USART2_SERIAL_CONSOLE=y
|
||||
CONFIG_USART2_TXDMA=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -218,6 +218,10 @@
|
||||
#define DMACHAN_SPI2_RX DMAMAP_SPI2_RX
|
||||
#define DMACHAN_SPI2_TX DMAMAP_SPI2_TX
|
||||
|
||||
/* ADC 1 */
|
||||
|
||||
#define ADC1_DMA_CHAN DMAMAP_ADC1_1
|
||||
|
||||
/* Alternate function pin selections ****************************************/
|
||||
|
||||
/* USART1:
|
||||
@ -227,7 +231,7 @@
|
||||
* PB6 CN5 pin 3, CN10 pin 17
|
||||
*/
|
||||
|
||||
#if 1
|
||||
#if !defined(CONFIG_BOARD_STM32_IHM08M1)
|
||||
# define GPIO_USART1_RX GPIO_USART1_RX_1 /* PA10 */
|
||||
# define GPIO_USART1_TX GPIO_USART1_TX_1 /* PA9 */
|
||||
#else
|
||||
@ -376,4 +380,38 @@
|
||||
#define GPIO_TIM2_CH1IN (GPIO_TIM2_CH1IN_1 | GPIO_PULLUP)
|
||||
#define GPIO_TIM2_CH2IN (GPIO_TIM2_CH2IN_1 | GPIO_PULLUP)
|
||||
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1
|
||||
|
||||
/* Configuration specific to the X-NUCLEO-IHM08M1 expansion board with
|
||||
* the L6398 gate drivers.
|
||||
*/
|
||||
|
||||
/* TIM1 configuration *******************************************************/
|
||||
|
||||
#define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1 /* TIM1 CH1 - PA8 - U high */
|
||||
#define GPIO_TIM1_CH1NOUT GPIO_TIM1_CH1N_1 /* TIM1 CH1N - PA7 - U low */
|
||||
#define GPIO_TIM1_CH2OUT GPIO_TIM1_CH2OUT_1 /* TIM1 CH2 - PA9 - V high */
|
||||
#define GPIO_TIM1_CH2NOUT GPIO_TIM1_CH2N_1 /* TIM1 CH2N - PB0 - V low */
|
||||
#define GPIO_TIM1_CH3OUT GPIO_TIM1_CH3OUT_1 /* TIM1 CH3 - PA10 - W high */
|
||||
#define GPIO_TIM1_CH3NOUT GPIO_TIM1_CH3N_1 /* TIM1 CH3N - PB1 - W low */
|
||||
#define GPIO_TIM1_CH4OUT 0 /* not used as output */
|
||||
|
||||
/* Board LED */
|
||||
|
||||
# define GPIO_FOC_LED2 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN2)
|
||||
|
||||
/* Debug pin */
|
||||
|
||||
# define GPIO_FOC_DEBUG0 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN12)
|
||||
# define GPIO_FOC_DEBUG1 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN9)
|
||||
# define GPIO_FOC_DEBUG2 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN6)
|
||||
# define GPIO_FOC_DEBUG3 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz| \
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN5)
|
||||
|
||||
#endif /* CONFIG_BOARD_STM32_IHM08M1 */
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_NUCLEO_F446RE_INCLUDE_BOARD_H */
|
||||
|
@ -36,12 +36,14 @@ ifeq ($(CONFIG_LCD_ILI9225),y)
|
||||
CSRCS += stm32_ili9225.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32_FOC),n)
|
||||
ifeq ($(CONFIG_ADC),y)
|
||||
CSRCS += stm32_adc.c
|
||||
ifeq ($(CONFIG_INPUT_AJOYSTICK),y)
|
||||
CSRCS += stm32_ajoystick.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_CAN),y)
|
||||
CSRCS += stm32_can.c
|
||||
@ -51,6 +53,10 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
||||
CSRCS += stm32_appinit.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BOARD_STM32_IHM08M1),y)
|
||||
CSRCS += stm32_foc_ihm08m1.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path board
|
||||
VPATH += :board
|
||||
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
|
||||
|
@ -318,4 +318,16 @@ int stm32_can_setup(void);
|
||||
int board_ajoy_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_foc_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize FOC peripheral for the board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32_FOC
|
||||
int stm32_foc_setup(void);
|
||||
#endif
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_NUCLEO_F401RE_SRC_NUCLEO_F446RE_H */
|
||||
|
@ -116,6 +116,16 @@ int stm32_bringup(void)
|
||||
syslog(LOG_INFO, "[boot] Initialized SDIO\n");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32_FOC
|
||||
/* Initialize and register the FOC device */
|
||||
|
||||
ret = stm32_foc_setup();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_foc_setup failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ADC
|
||||
/* Initialize ADC and register the ADC driver. */
|
||||
|
||||
|
188
boards/arm/stm32/nucleo-f446re/src/stm32_foc_ihm08m1.c
Normal file
188
boards/arm/stm32/nucleo-f446re/src/stm32_foc_ihm08m1.c
Normal file
@ -0,0 +1,188 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/nucleo-f446re/src/stm32_foc_ihm08m1.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "stm32_ihm08m1.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CURRENT_SAMPLE_TIME ADC_SMPR_15
|
||||
#define VBUS_SAMPLE_TIME ADC_SMPR_15
|
||||
#define POT_SAMPLE_TIME ADC_SMPR_15
|
||||
|
||||
/* ADC1 channels used in this example */
|
||||
|
||||
#define ADC1_INJECTED (CONFIG_MOTOR_FOC_SHUNTS)
|
||||
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_VBUS
|
||||
# define IHM08M1_VBUS 1
|
||||
#else
|
||||
# define IHM08M1_VBUS 0
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_POT
|
||||
# define IHM08M1_POT 1
|
||||
#else
|
||||
# define IHM08M1_POT 0
|
||||
#endif
|
||||
|
||||
#define ADC1_REGULAR (IHM08M1_VBUS + IHM08M1_POT)
|
||||
#define ADC1_NCHANNELS (ADC1_INJECTED + ADC1_REGULAR)
|
||||
|
||||
/* Check ADC1 configuration */
|
||||
|
||||
#if ADC1_INJECTED != CONFIG_STM32_ADC1_INJECTED_CHAN
|
||||
# error
|
||||
#endif
|
||||
|
||||
#if CONFIG_STM32_ADC1_RESOLUTION != 0
|
||||
# error
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* FOC ADC configration:
|
||||
* - Current Phase V -> ADC1 INJ1 -> ADC1_IN0 (PA0)
|
||||
* - Current Phase U -> ADC1 INJ2 -> ADC1_IN11 (PC1)
|
||||
* - Current Phase W -> ADC1 INJ3 -> ADC1_IN10 (PC0)
|
||||
* optional:
|
||||
* - VBUS -> ADC1 REG -> ADC1_IN1 (PA1)
|
||||
* - POT -> ADC1 REG -> ADC1_IN4 (PA4)
|
||||
*
|
||||
* TIM1 PWM configuration:
|
||||
* - Phase U high -> TIM1_CH1 (PA8)
|
||||
* - Phase U low -> TIM1_CH1N (PA7)
|
||||
* - Phase V high -> TIM1_CH2 (PA9)
|
||||
* - Phase V low -> TIM1_CH2N (PB0)
|
||||
* - Phase W high -> TIM1_CH3 (PA10)
|
||||
* - Phase W low -> TIM1_CH3N (PB1)
|
||||
*
|
||||
*/
|
||||
|
||||
static uint8_t g_adc1_chan[] =
|
||||
{
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_VBUS
|
||||
1, /* ADC1 REG1 - VBUS */
|
||||
#endif
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_POT
|
||||
4, /* ADC1 REG - POT */
|
||||
#endif
|
||||
0, /* ADC1 INJ1 - PHASE 1 */
|
||||
#if CONFIG_MOTOR_FOC_SHUNTS > 1
|
||||
11, /* ADC1 INJ2 - PHASE 2 */
|
||||
#endif
|
||||
#if CONFIG_MOTOR_FOC_SHUNTS > 2
|
||||
10, /* ADC1 INJ3 - PHASE 3 */
|
||||
#endif
|
||||
};
|
||||
|
||||
static uint32_t g_adc1_pins[] =
|
||||
{
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_VBUS
|
||||
GPIO_ADC1_IN1,
|
||||
#endif
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_POT
|
||||
GPIO_ADC1_IN4,
|
||||
#endif
|
||||
GPIO_ADC1_IN0,
|
||||
#if CONFIG_MOTOR_FOC_SHUNTS > 1
|
||||
GPIO_ADC1_IN11,
|
||||
#endif
|
||||
#if CONFIG_MOTOR_FOC_SHUNTS > 2
|
||||
GPIO_ADC1_IN10
|
||||
#endif
|
||||
};
|
||||
|
||||
/* ADC1 sample time configuration */
|
||||
|
||||
static adc_channel_t g_adc1_stime[] =
|
||||
{
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_VBUS
|
||||
{
|
||||
.channel = 1,
|
||||
.sample_time = VBUS_SAMPLE_TIME
|
||||
},
|
||||
#endif
|
||||
#ifdef CONFIG_BOARD_STM32_IHM08M1_POT
|
||||
{
|
||||
.channel = 4,
|
||||
.sample_time = POT_SAMPLE_TIME
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.channel = 0,
|
||||
.sample_time = CURRENT_SAMPLE_TIME
|
||||
},
|
||||
#if CONFIG_MOTOR_FOC_SHUNTS > 1
|
||||
{
|
||||
.channel = 11,
|
||||
.sample_time = CURRENT_SAMPLE_TIME
|
||||
},
|
||||
#endif
|
||||
#if CONFIG_MOTOR_FOC_SHUNTS > 2
|
||||
{
|
||||
.channel = 10,
|
||||
.sample_time = CURRENT_SAMPLE_TIME
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Board specific ADC configuration for FOC */
|
||||
|
||||
static struct stm32_foc_adc_s g_adc_cfg =
|
||||
{
|
||||
.chan = g_adc1_chan,
|
||||
.pins = g_adc1_pins,
|
||||
.stime = g_adc1_stime,
|
||||
.nchan = ADC1_NCHANNELS,
|
||||
.regch = ADC1_REGULAR,
|
||||
.intf = 1
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_foc_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize FOC driver.
|
||||
*
|
||||
* This function should be call by board_app_initialize().
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 on success, a negated errno value on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_foc_setup(void)
|
||||
{
|
||||
return board_ihm08m1_initialize(&g_adc_cfg);
|
||||
}
|
Loading…
Reference in New Issue
Block a user