1 | uint32_t configEncoder(void){
|
2 |
|
3 |
|
4 | // Enable GPIO Peripheral clock for Resolver GPIO A8 & GPIO A9
|
5 | RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
6 |
|
7 | GPIO_InitTypeDef GPIO_InitStructure;
|
8 |
|
9 | GPIO_InitStructure.Pin = GPIO_PIN_8;
|
10 | GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
11 | GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
|
12 | GPIO_InitStructure.Pull = GPIO_PULLUP;
|
13 | GPIO_InitStructure.Alternate = GPIO_AF1_TIM1;
|
14 |
|
15 | GPIO_InitStructure.Pin = GPIO_PIN_9;
|
16 | HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
|
17 |
|
18 |
|
19 |
|
20 | /* First and foremost: Enable TIM1 clock */
|
21 | RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
22 |
|
23 | TIM_HandleTypeDef TimHandle;
|
24 |
|
25 | /* Set TIM1 instance */
|
26 | TimHandle.Instance = TIM1;
|
27 |
|
28 | TimHandle.Init.Prescaler = 0;
|
29 | TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
30 | TimHandle.Init.Period = 9999;
|
31 | TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
32 | TimHandle.Init.RepetitionCounter = 0xFF; // DEBUG: ohne Funktion?
|
33 | HAL_TIM_Base_Init(&TimHandle);
|
34 |
|
35 |
|
36 | TIM_Encoder_InitTypeDef sConfigure;
|
37 |
|
38 | sConfigure.EncoderMode = TIM_ENCODERMODE_TI12;
|
39 | sConfigure.IC1Polarity = TIM_ICPOLARITY_BOTHEDGE;
|
40 | sConfigure.IC1Selection = TIM_ICSELECTION_DIRECTTI;
|
41 | sConfigure.IC1Prescaler = TIM_ICPSC_DIV1;
|
42 | sConfigure.IC1Filter = 0;
|
43 | sConfigure.IC2Polarity = TIM_ICPOLARITY_BOTHEDGE;
|
44 | sConfigure.IC2Selection = TIM_ICSELECTION_DIRECTTI;
|
45 | sConfigure.IC2Prescaler = TIM_ICPSC_DIV1;
|
46 | sConfigure.IC2Filter = 0;
|
47 |
|
48 | // send errorcode to caller:
|
49 | return HAL_TIM_Encoder_Init(&TimHandle, &sConfigure);
|
50 |
|
51 | }
|