Skip to content

Commit 539a63b

Browse files
committed
tim5 encoder
1 parent 97b6c49 commit 539a63b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

HAL_custom_init.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ void AF_Tim2_pins_encoder(){
1414
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
1515
}
1616

17+
// Set PA_0 and PA_1 as alternate function 1 -> TIM5
18+
void AF_Tim5_pins_encoder(){
19+
GPIO_InitTypeDef GPIO_InitStruct;
20+
__HAL_RCC_TIM5_CLK_ENABLE();
21+
__HAL_RCC_GPIOA_CLK_ENABLE();
22+
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
23+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
24+
GPIO_InitStruct.Pull = GPIO_NOPULL;
25+
GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
26+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
27+
}
28+
1729
// Set PC_6 and PC_7 as alternate function 2 -> TIM3
1830
void AF_Tim3_pins_encoder(){
1931
GPIO_InitTypeDef GPIO_InitStruct;

examples/.DS_Store

6 KB
Binary file not shown.

examples/test/test.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "Arduino_Robot_Firmware.h"
22

3-
Encoder enc_right(TIM2);
3+
Encoder enc_right(TIM5);
44
Encoder enc_left(TIM3);
55
RGBled led1(LED_1_RED, LED_1_GREEN, LED_1_BLUE);
66

77

88
void setup(){
99
Serial.begin(115200);
1010
Serial.println("Start");
11-
AF_Tim2_pins_encoder();
11+
AF_Tim5_pins_encoder();
1212
AF_Tim3_pins_encoder();
1313
enc_right.begin();
1414
enc_left.begin();

0 commit comments

Comments
 (0)