Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SPI_TFT_ILI9341 TFT_fonts mbed
Fork of Mandelbrot by
Encoder/EncoderInit.cpp@3:267e7130007d, 2015-01-22 (annotated)
- Committer:
- gregeric
- Date:
- Thu Jan 22 10:01:49 2015 +0000
- Revision:
- 3:267e7130007d
- Parent:
- 2:b1169b84a563
Increase debounce time, shown necessary after round of testing.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gregeric | 2:b1169b84a563 | 1 | #include "mbed.h" |
| gregeric | 2:b1169b84a563 | 2 | |
| gregeric | 2:b1169b84a563 | 3 | void EncoderInit(TIM_Encoder_InitTypeDef encoder, TIM_HandleTypeDef timer, TIM_TypeDef *TIMx, uint32_t maxcount, uint32_t encmode) |
| gregeric | 2:b1169b84a563 | 4 | { |
| gregeric | 2:b1169b84a563 | 5 | timer.Instance = TIMx; |
| gregeric | 2:b1169b84a563 | 6 | timer.Init.Period = maxcount; |
| gregeric | 2:b1169b84a563 | 7 | timer.Init.CounterMode = TIM_COUNTERMODE_UP; |
| gregeric | 2:b1169b84a563 | 8 | timer.Init.Prescaler = 0; |
| gregeric | 2:b1169b84a563 | 9 | timer.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
| gregeric | 2:b1169b84a563 | 10 | |
| gregeric | 2:b1169b84a563 | 11 | encoder.EncoderMode = encmode; |
| gregeric | 2:b1169b84a563 | 12 | |
| gregeric | 2:b1169b84a563 | 13 | encoder.IC1Filter = 0x0F; |
| gregeric | 2:b1169b84a563 | 14 | encoder.IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING; |
| gregeric | 2:b1169b84a563 | 15 | encoder.IC1Prescaler = TIM_ICPSC_DIV4; |
| gregeric | 2:b1169b84a563 | 16 | encoder.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
| gregeric | 2:b1169b84a563 | 17 | |
| gregeric | 2:b1169b84a563 | 18 | encoder.IC2Filter = 0x0F; |
| gregeric | 2:b1169b84a563 | 19 | encoder.IC2Polarity = TIM_INPUTCHANNELPOLARITY_FALLING; |
| gregeric | 2:b1169b84a563 | 20 | encoder.IC2Prescaler = TIM_ICPSC_DIV4; |
| gregeric | 2:b1169b84a563 | 21 | encoder.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
| gregeric | 2:b1169b84a563 | 22 | |
| gregeric | 2:b1169b84a563 | 23 | |
| gregeric | 2:b1169b84a563 | 24 | if (HAL_TIM_Encoder_Init(&timer, &encoder) != HAL_OK) { |
| gregeric | 2:b1169b84a563 | 25 | printf("Couldn't Init Encoder\r\n"); |
| gregeric | 2:b1169b84a563 | 26 | while (1) {} |
| gregeric | 2:b1169b84a563 | 27 | } |
| gregeric | 2:b1169b84a563 | 28 | |
| gregeric | 2:b1169b84a563 | 29 | if(HAL_TIM_Encoder_Start(&timer,TIM_CHANNEL_1)!=HAL_OK) { |
| gregeric | 2:b1169b84a563 | 30 | printf("Couldn't Start Encoder\r\n"); |
| gregeric | 2:b1169b84a563 | 31 | while (1) {} |
| gregeric | 2:b1169b84a563 | 32 | } |
| gregeric | 2:b1169b84a563 | 33 | } |
| gregeric | 2:b1169b84a563 | 34 |
