diff --git a/Firmware/carteHRI.uvoptx b/Firmware/carteHRI.uvoptx index 2dda120..cc6d1ed 100644 --- a/Firmware/carteHRI.uvoptx +++ b/Firmware/carteHRI.uvoptx @@ -1,788 +1,801 @@ 1.0
### uVision Project, (C) Keil Software
*.c *.s*; *.src; *.a* *.obj *.lib *.txt; *.h; *.inc *.plm *.cpp 0 0 0 Target 1 0x4 ARM-ADS 168000000 1 1 0 1 0 1 65535 0 0 0 79 66 8 .\lst\ 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 18 0 User Manual (MCBSTM32F400) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\Keil\MCBSTM32F400\Documentation\mcbstm32f200.chm 1 Schematics (MCBSTM32F400) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\Keil\MCBSTM32F400\Documentation\mcbstm32f400-schematics.pdf 2 Getting Started (STM32F4-Discovery) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\ST\STM32F4-Discovery\Documentation\DM00037368.pdf 3 User Manual (STM32F4-Discovery) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\ST\STM32F4-Discovery\Documentation\DM00039084.pdf 4 Bill of Materials (STM32F4-Discovery) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\ST\STM32F4-Discovery\Documentation\stm32f4discovery_bom.zip 5 Gerber Files (STM32F4-Discovery) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\ST\STM32F4-Discovery\Documentation\stm32f4discovery_gerber.zip 6 Schematics (STM32F4-Discovery) C:\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.5.0\MDK\Boards\ST\STM32F4-Discovery\Documentation\stm32f4discovery_sch.zip 7 MCBSTM32F400 Evaluation Board Web Page (MCBSTM32F400) http://www.keil.com/mcbstm32f400/ 8 STM32F4-Discovery Web Page (STM32F4-Discovery) http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1199/PF252419 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 11 STLink\ST-LINKIII-KEIL_SWO.dll 0 ARMRTXEVENTFLAGS -L50 -Z18 -C0 -M0 -T0 0 DLGDARM (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0) 0 DLGTARM (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(1012=-1,-1,-1,-1,0) 0 ARMDBGFLAGS -T0 0 DLGUARM (105=-1,-1,-1,-1,0) 0 ST-LINKIII-KEIL_SWO -U303030303030303030303031 -O8398 -S1 -C0 -A0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO19 -TC168000000 -TP21 -TDS8053 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407VG$CMSIS\Flash\STM32F4xx_1024.FLM) 0 UL2CM3 UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F407VG$Flash\STM32F4xx_1024.FLM)) 0 1 uart_txBuffer[0] 1 1 uart_txBuffer[1] 2 1 demoSineOutput 3 1 ctrl_motorPosHall 4 1 ctrl_timestamp 0 2 motorCurrentDebug 1 2 motorTargetCurrentDebug 2 2 ctrl_motorTorque_mNm_c 3 2 motorTorque_mNm_dbg 4 2 motorTorque_mNm 5 2 nCycles 6 2 motorPosCod,0x0A 7 2 CurrentSensOffset,0x0A 8 2 motorCurrent_mA_mean 9 2 motorCurrent_mA 10 2 ADCValuesBuffer,0x0A 11 2 motorCurrent_mA 12 2 motorCurrentSum 13 2 debugVar01,0x0A 14 2 adcValues1,0x0A 15 2 motorCurrent_mA 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 STM32_files 1 0 0 0 1 1 1 0 0 0 0 .\src\system_stm32f4xx.c system_stm32f4xx.c 0 0 1 2 2 0 0 0 0 .\startup_stm32f4xx.s startup_stm32f4xx.s 0 0 SRC 1 0 0 0 2 3 1 0 0 0 0 .\src\main.c main.c 0 0 2 4 1 0 0 0 0 .\src\communication.c communication.c 0 0 2 5 1 0 0 0 0 .\src\controller.c controller.c 0 0 STM32_libs 1 0 0 0 3 6 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_gpio.c stm32f4xx_gpio.c 0 0 3 7 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_rcc.c stm32f4xx_rcc.c 0 0 3 8 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_tim.c stm32f4xx_tim.c 0 0 3 9 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\misc.c misc.c 0 0 3 10 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_exti.c stm32f4xx_exti.c 0 0 3 11 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_syscfg.c stm32f4xx_syscfg.c 0 0 3 12 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_adc.c stm32f4xx_adc.c 0 0 3 13 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_dac.c stm32f4xx_dac.c 0 0 3 14 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_dma.c stm32f4xx_dma.c 0 0 3 15 1 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_usart.c stm32f4xx_usart.c 0 0 3 16 4 0 0 0 0 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\CMSIS\Lib\ARM\arm_cortexM4lf_math.lib arm_cortexM4lf_math.lib 0 0 SRC_drivers 1 0 0 0 4 17 1 0 0 0 0 .\src\drivers\adc.c adc.c 0 0 4 18 1 0 0 0 0 .\src\drivers\callback_timers.c callback_timers.c 0 0 4 19 1 0 0 0 0 .\src\drivers\dac.c dac.c 0 0 4 20 1 0 0 0 0 .\src\drivers\h_bridge.c h_bridge.c 0 0 4 21 1 0 0 0 0 .\src\drivers\incr_encoder.c incr_encoder.c 0 0 4 22 1 0 0 0 0 .\src\drivers\uart.c uart.c 0 0 4 23 1 0 0 0 0 .\src\drivers\hall.c hall.c 0 0 4 24 1 0 0 0 0 .\src\drivers\strain_gauge.c strain_gauge.c 0 0 4 25 1 0 0 0 0 .\src\drivers\tachometer.c tachometer.c 0 0 4 26 1 0 0 0 0 .\src\drivers\led.c led.c 0 0 4 27 1 0 0 0 0 .\src\drivers\debug_gpio.c debug_gpio.c 0 0 + + 4 + 28 + 1 + 0 + 0 + 0 + 0 + .\src\drivers\button.c + button.c + 0 + 0 + SRC_lib 1 0 0 0 5 - 28 + 29 1 0 0 0 0 .\src\lib\basic_filter.c basic_filter.c 0 0 5 - 29 + 30 1 0 0 0 0 .\src\lib\pid.c pid.c 0 0 5 - 30 + 31 1 0 0 0 0 .\src\lib\utils.c utils.c 0 0 5 - 31 + 32 1 0 0 0 0 .\src\lib\circular_buffer.c circular_buffer.c 0 0
diff --git a/Firmware/carteHRI.uvprojx b/Firmware/carteHRI.uvprojx index de48bfb..4684c8a 100644 --- a/Firmware/carteHRI.uvprojx +++ b/Firmware/carteHRI.uvprojx @@ -1,596 +1,601 @@ 2.1
### uVision Project, (C) Keil Software
Target 1 0x4 ARM-ADS STM32F407VG STMicroelectronics Keil.STM32F4xx_DFP.2.5.0 http://www.keil.com/pack IROM(0x08000000,0x100000) IRAM(0x20000000,0x20000) IRAM2(0x10000000,0x10000) CPUTYPE("Cortex-M4") FPU2 CLOCK(168000000) ELITTLE UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F407VG$Flash\STM32F4xx_1024.FLM)) 6103 $$Device:STM32F407VG$Device\Include\stm32f4xx.h $$Device:STM32F407VG$SVD\STM32F40x.svd 0 0 0 0 0 0 1 .\output\ motorControl 1 0 1 1 1 .\lst\ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 3 1 SARMCM3.DLL -REMAP -MPU DCM.DLL -pCM4 SARMCM3.DLL -REMAP -MPU TCM.DLL -pCM4 1 0 0 0 16 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 11 STLink\ST-LINKIII-KEIL_SWO.dll 1 0 0 1 1 4096 1 BIN\UL2CM3.DLL "" () 0 0 1 1 1 1 1 1 1 0 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 0 "Cortex-M4" 0 0 0 1 1 0 0 2 1 0 8 0 0 0 3 3 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0x0 0x0 0 0x0 0x0 0 0x0 0x0 0 0x0 0x0 0 0x0 0x0 0 0x0 0x0 0 0x20000000 0x20000 1 0x8000000 0x100000 0 0x0 0x0 1 0x0 0x0 1 0x0 0x0 1 0x0 0x0 1 0x8000000 0x100000 1 0x0 0x0 0 0x0 0x0 0 0x0 0x0 0 0x0 0x0 0 0x20000000 0x20000 0 0x10000000 0x10000 1 4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 USE_STDPERIPH_DRIVER STM32F4XX ARM_MATH_CM4 ..\CodeUC;.\inc;.\src;C:\STM32F4-Discovery_FW_V1.1.0\Libraries\CMSIS\ST\STM32F4xx\Include;C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\inc;C:\STM32F4-Discovery_FW_V1.1.0\Utilities\STM32F4-Discovery;C:\STM32F4-Discovery_FW_V1.1.0\Libraries\CMSIS\Include 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0x08000000 0x20000000 STM32_files system_stm32f4xx.c 1 .\src\system_stm32f4xx.c startup_stm32f4xx.s 2 .\startup_stm32f4xx.s SRC main.c 1 .\src\main.c communication.c 1 .\src\communication.c controller.c 1 .\src\controller.c STM32_libs stm32f4xx_gpio.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_gpio.c stm32f4xx_rcc.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_rcc.c stm32f4xx_tim.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_tim.c misc.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\misc.c stm32f4xx_exti.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_exti.c stm32f4xx_syscfg.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_syscfg.c stm32f4xx_adc.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_adc.c stm32f4xx_dac.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_dac.c stm32f4xx_dma.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_dma.c stm32f4xx_usart.c 1 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\src\stm32f4xx_usart.c arm_cortexM4lf_math.lib 4 C:\STM32F4-Discovery_FW_V1.1.0\Libraries\CMSIS\Lib\ARM\arm_cortexM4lf_math.lib SRC_drivers adc.c 1 .\src\drivers\adc.c callback_timers.c 1 .\src\drivers\callback_timers.c dac.c 1 .\src\drivers\dac.c h_bridge.c 1 .\src\drivers\h_bridge.c incr_encoder.c 1 .\src\drivers\incr_encoder.c uart.c 1 .\src\drivers\uart.c hall.c 1 .\src\drivers\hall.c strain_gauge.c 1 .\src\drivers\strain_gauge.c tachometer.c 1 .\src\drivers\tachometer.c led.c 1 .\src\drivers\led.c debug_gpio.c 1 .\src\drivers\debug_gpio.c + + button.c + 1 + .\src\drivers\button.c + SRC_lib basic_filter.c 1 .\src\lib\basic_filter.c pid.c 1 .\src\lib\pid.c utils.c 1 .\src\lib\utils.c circular_buffer.c 1 .\src\lib\circular_buffer.c
diff --git a/Firmware/src/drivers/button.c b/Firmware/src/drivers/button.c new file mode 100644 index 0000000..8199d7f --- /dev/null +++ b/Firmware/src/drivers/button.c @@ -0,0 +1,80 @@ +#include "button.h" +#include "../communication.h" + +#define BOARD_BUTTON_PORT GPIOE +#define BOARD_BUTTON_PIN GPIO_Pin_2 +#define USER_BUTTON_IRQ_CHANNEL EXTI2_IRQn +#define USER_BUTTON_IRQ_LINE EXTI_Line2 +#define USER_BUTTON_IRQ_PINSOURCE EXTI_PinSource2 +#define USER_BUTTON_IRQ_SOURCE EXTI_PortSourceGPIOE + +void (*userButtonStateChangedCallback)(bool); ///< Function called when the button state changes. The bool parameter is true if the button was released. + +/** + * @brief Initializes the button module. + * @param stateChangedCallback function pointer to the callback function that + * should be called when the button state changes. If this feature is not used, + * NULL can be passed instead. + */ +void but_Init(void (*stateChangedCallback)(bool)) +{ + GPIO_InitTypeDef GPIO_InitStruct; + EXTI_InitTypeDef EXTI_InitStruct; + NVIC_InitTypeDef NVIC_InitStruct; + + // Initialize the pin as input. + GPIO_InitStruct.GPIO_Pin = BOARD_BUTTON_PIN; + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; + GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; + GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; + GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(BOARD_BUTTON_PORT, &GPIO_InitStruct); + + // Optionally setup the callback that triggers when the button is pressed or + // released. + userButtonStateChangedCallback = stateChangedCallback; + + if(stateChangedCallback != NULL) + { + SYSCFG_EXTILineConfig(USER_BUTTON_IRQ_SOURCE, + USER_BUTTON_IRQ_PINSOURCE); + + EXTI_InitStruct.EXTI_Line = USER_BUTTON_IRQ_LINE; + EXTI_InitStruct.EXTI_LineCmd = ENABLE; + EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling; + EXTI_Init(&EXTI_InitStruct); + + NVIC_InitStruct.NVIC_IRQChannel = USER_BUTTON_IRQ_CHANNEL; + NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = USER_BUTTON_IRQ_PRIORITY; + NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x0; + NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStruct); + } +} + +/** + * @brief Gets the current state of the user button. + * @return the state of the button (1=released, 0=pressed). + */ +bool but_GetState(void) +{ + return GPIO_ReadInputDataBit(BOARD_BUTTON_PORT, BOARD_BUTTON_PIN) != 0; +} + +/** + * @brief Calls the user button callback function. + * @remark: this function is called automatically by the pin change interrupt of + * the user button. + */ +void EXTI2_IRQHandler(void) +{ + if(EXTI_GetITStatus(USER_BUTTON_IRQ_LINE) != RESET) + { + if(userButtonStateChangedCallback != NULL) + userButtonStateChangedCallback(but_GetState()); + + // Clear interrupt flag. + EXTI_ClearITPendingBit(USER_BUTTON_IRQ_LINE); + } +} diff --git a/Firmware/src/drivers/button.h b/Firmware/src/drivers/button.h new file mode 100644 index 0000000..dc3e4eb --- /dev/null +++ b/Firmware/src/drivers/button.h @@ -0,0 +1,27 @@ +#ifndef __BUTTON_H +#define __BUTTON_H + +#include "../main.h" + +/** @defgroup Button Driver / Button + * @brief Driver to access a button + * + * Call but_Init() first in the initialization code. Then, call but_GetState() + * to read the current state of the button. + * + * It is also possible to pass a function pointer to the but_Init() function. + * Then, the given function will be called automatically when the button state + * changes (pressed or released). + * + * @addtogroup Button + * @{ + */ + +void but_Init(void (*stateChangedCallback)(bool)); +bool but_GetState(void); + +/** + * @} + */ + +#endif diff --git a/Firmware/src/main.c b/Firmware/src/main.c index 6716ade..57c4556 100644 --- a/Firmware/src/main.c +++ b/Firmware/src/main.c @@ -1,76 +1,77 @@ #include "main.h" #include "communication.h" #include "controller.h" #include "drivers/adc.h" #include "drivers/callback_timers.h" #include "drivers/dac.h" #include "drivers/debug_gpio.h" #include "drivers/h_bridge.h" #include "drivers/hall.h" #include "drivers/incr_encoder.h" #include "drivers/led.h" #include "drivers/strain_gauge.h" #include "drivers/tachometer.h" #include "lib/utils.h" extern volatile uint32_t ctrl_timestamp; volatile uint32_t statusReg = 0x00000000; // Main state register. /** * @brief Main function, setups all the drivers and controllers. */ int main(void) { // Setup the GPIOs and the interrupts. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); // cbt_Init(); // Setup the timers that will call the loops functions. adc_Init(); // Setup the ADC. comm_Init(); // Setup the communication module. ctrl_Init(); // Setup the controllers. enc_Init(); // Setup the incremental encoders. hb_Init(); // Setup the H-bridge. hb_Enable(); // dac_Init(); // Setup the DAC. - led_Init(); + led_Init(); // Setup the LEDs. dio_Init(); // Delay to let the power electronics stabilize before calibrating the // current sensor. utils_DelayMs(200); adc_CalibrateCurrentSens(); // Start the current loop. ctrl_StartCurrentLoop(); // Init the external sensors drivers, connected to the ADC. hall_Init(ANIN1); //sg_Init(ANIN2); //tac_Init(ANIN2); // End of the initialization. Lock the SyncVar list, and notify the PC that // the board has (re)started. comm_LockSyncVarsList(); comm_NotifyReady(); // Endless loop. The low priority functions are called here. while(1) { // Update the communication. comm_Step(); } } diff --git a/Firmware/src/main.h b/Firmware/src/main.h index f6e29f3..eba926f 100644 --- a/Firmware/src/main.h +++ b/Firmware/src/main.h @@ -1,95 +1,96 @@ /** \mainpage HRI board firmware documentation * \section intro_sec Introduction * This is the documentation of the HRI board firmware. You will find a * description of the provided library and drivers. As all the hardware and * software is very new, please do not hesitate to suggest improvements to the * course assistants (Romain Baud, Philipp Hörler and Laurent Jenni). * * \section code_struct_sec Code structure * The code is divided into 3 parts: * - main: this is where the controllers and the communication protocol are * implemented. The call of all the initialization functions is also made here. * - library: all the algorithms, data structures that could be used at many * places, are put into the library. * - drivers: there is one driver per peripheral. All the hardware-specific * code is wrapped into these files, so that the user does not have to worry * about the microcontroller operation (and spend a lot of time to read the * documentation). * * One module (controller, communication, library or driver) is always splitted * in two files, .h and .c, like in C++. * @image html soft_architecture.png * * \section lib_how_to How to use the provided library * For most of the driver/library modules, call x_Init() only once, when the * program starts (typically in the main()). Then, you can call * x_Step()/x_Set()/x_Get() everytime as needed, typically in the control * functions called periodically (ctrl_RegulatePosition()...). * * See the "Modules" section of this documentation to see how they work. * * \section stm32_resources_usage STM32's resources usage * \subsection stm32_resources_usage_timers Timers * - TIM1: PWM of the 4 user LEDs. * - TIM2: - * - TIM3: - * - TIM4: - * - TIM5: encoder quadrature decoder. * - TIM6: position loop. * - TIM7: variables streaming loop. * - TIM8: H-bridge PWM. * - TIM9: - * - TIM10: current loop. * - TIM11: - * - TIM12: - * - TIM13: - * - TIM14: - * \subsection stm32_resources_usage_adcs ADCs * - ADC1: general purpose ADC. * - ADC2: - * - ADC3: motor current sensor ADC. * \subsection stm32_resources_usage_dac DAC * - DAC: DAC extension. * \subsection stm32_resources_usage_buses Communication buses * - USART1: UART extension. * - USART2: USB communication UART. * - I2C1: I2C extension. * - SPI3: SPI extension. */ #ifndef __MAIN_H #define __MAIN_H #include "stm32f4_discovery.h" #include #include #include "arm_math.h" // Clocks configuration. #define STM_SYSCLOCK_FREQ 168000000 // [Hz]. #define APB1_PRESCALER 4 #define APB2_PRESCALER 2 #define TIM_MULTIPLIER 2 // Interupt priority. -#define CURRENT_LOOP_IRQ_PRIORITY 1 // High freq loop, should not be interrupted. +#define CURRENT_LOOP_IRQ_PRIORITY 1 // High freq loop, should interrupt all the others. #define CONTROL_LOOP_IRQ_PRIORITY 2 #define CODER_INDEX_IRQ_PRIORITY 2 // Useless, remove? #define UART_RX_IRQ_PRIORIY 3 -#define DATA_LOOP_IRQ_PRIORITY 4 // Streaming packets, lowest priority. +#define DATA_LOOP_IRQ_PRIORITY 4 // Streaming packets. +#define USER_BUTTON_IRQ_PRIORITY 4 // Electrical parameters. #define STM_SUPPLY_VOLTAGE 3.3f // Power supply voltage of the microcontroller [V]. #define ADC_REF_VOLTAGE 2.5f // Voltage reference of the ADC (VREF) [V]. #define H_BRIDGE_SUPPLY_VOLTAGE 24.0f // [V]. #define CURRENT_SHUNT_RESISTANCE 0.025f // [ohm]. #define CURRENT_SHUNT_AMPLIFIER_GAIN 50.0f // []. #define MOTOR_RESISTANCE 10.6f + 5.0f // 10.6 ohm according to the datasheet, actually more, depends on the motor [ohm]. // Mechanical parameters. #define REDUCTION_RATIO 16.5f #define MOTOR_TORQUE_CONST 0.0538f // [N.m/A]. #define MOTOR_SPEED_CONST 177.0f // [RPM/V]. #define MOTOR_NOMINAL_TORQUE 0.0323f // [N.m]. #endif