NUCLEO-F446RE ENCODER TIMER3 Y TIMER 2 HAL AND PWM. PID PARA UN PENDULO INVERTIDO CON 2 ENCODER DE CUADRATURA
Encoder/EncoderMspInitF0.cpp@0:95f924550159, 2016-05-21 (annotated)
- Committer:
- gereina
- Date:
- Sat May 21 04:17:35 2016 +0000
- Revision:
- 0:95f924550159
QEI_TIMER2_TIMER_3 OK; PWM MBED; PID
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gereina | 0:95f924550159 | 1 | #include "mbed.h" |
gereina | 0:95f924550159 | 2 | /* |
gereina | 0:95f924550159 | 3 | * HAL_TIM_Encoder_MspInit() |
gereina | 0:95f924550159 | 4 | * Overrides the __weak function stub in stm32f0xx_hal_tim.h |
gereina | 0:95f924550159 | 5 | * |
gereina | 0:95f924550159 | 6 | * Edit the below for your preferred pin wiring & pullup/down |
gereina | 0:95f924550159 | 7 | * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs. |
gereina | 0:95f924550159 | 8 | * Encoder A&B outputs connected directly to GPIOs. |
gereina | 0:95f924550159 | 9 | * |
gereina | 0:95f924550159 | 10 | * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00088500.pdf |
gereina | 0:95f924550159 | 11 | * Table 11 has GPIO alternate function pinout mappings. |
gereina | 0:95f924550159 | 12 | * |
gereina | 0:95f924550159 | 13 | * TIM1_CH1: AF2 @ PA_8 - TIM1 used as system ticker under mbed, so unavailable |
gereina | 0:95f924550159 | 14 | * TIM1_CH2: AF2 @ PA_9 |
gereina | 0:95f924550159 | 15 | * |
gereina | 0:95f924550159 | 16 | * TIM3_CH1: AF1 @ PA_6, PB_4; AF0 @ PC_6* *only for F030xC devices |
gereina | 0:95f924550159 | 17 | * TIM3_CH2: AF1 @ PA_7, PB_5; AF0 @ PC_7* |
gereina | 0:95f924550159 | 18 | * |
gereina | 0:95f924550159 | 19 | */ |
gereina | 0:95f924550159 | 20 | |
gereina | 0:95f924550159 | 21 | #ifdef TARGET_STM32F0 |
gereina | 0:95f924550159 | 22 | void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
gereina | 0:95f924550159 | 23 | { |
gereina | 0:95f924550159 | 24 | GPIO_InitTypeDef GPIO_InitStruct; |
gereina | 0:95f924550159 | 25 | |
gereina | 0:95f924550159 | 26 | if (htim->Instance == TIM3) { //PB_4 PB_5 = Nucleo D5 D4 |
gereina | 0:95f924550159 | 27 | __TIM3_CLK_ENABLE(); |
gereina | 0:95f924550159 | 28 | __GPIOB_CLK_ENABLE(); |
gereina | 0:95f924550159 | 29 | GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5; |
gereina | 0:95f924550159 | 30 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
gereina | 0:95f924550159 | 31 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
gereina | 0:95f924550159 | 32 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
gereina | 0:95f924550159 | 33 | GPIO_InitStruct.Alternate = GPIO_AF1_TIM3; |
gereina | 0:95f924550159 | 34 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
gereina | 0:95f924550159 | 35 | } |
gereina | 0:95f924550159 | 36 | } |
gereina | 0:95f924550159 | 37 | #endif |