Advertisement
Guest User

Untitled

a guest
May 12th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. void EncoderInit_LPTIM(void)
  2. {
  3.       LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  4.       /* Peripheral clock enable */
  5.       LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPTIM1);
  6.  
  7.       LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
  8.       /**LPTIM1 GPIO Configuration
  9.       PC0   ------> LPTIM1_IN1
  10.       PC2   ------> LPTIM1_IN2
  11.       */
  12.       GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
  13.       GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  14.       GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  15.       GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  16.       GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  17.       GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  18.       LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  19.  
  20.       GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
  21.       GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  22.       GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  23.       GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  24.       GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  25.       GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  26.       LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  27.  
  28.       LL_LPTIM_SetClockSource(LPTIM1, LL_LPTIM_CLK_SOURCE_INTERNAL);
  29.       LL_LPTIM_SetPrescaler(LPTIM1, LL_LPTIM_PRESCALER_DIV1);
  30.       LL_LPTIM_SetPolarity(LPTIM1, LL_LPTIM_OUTPUT_POLARITY_REGULAR);
  31.       LL_LPTIM_SetUpdateMode(LPTIM1, LL_LPTIM_UPDATE_MODE_IMMEDIATE);
  32.       LL_LPTIM_SetCounterMode(LPTIM1, LL_LPTIM_COUNTER_MODE_EXTERNAL);
  33.       LL_LPTIM_ConfigClock(LPTIM1, LL_LPTIM_CLK_FILTER_NONE, LL_LPTIM_CLK_POLARITY_RISING);
  34.       LL_LPTIM_TrigSw(LPTIM1);
  35.  
  36.       LL_LPTIM_SetEncoderMode(LPTIM1, LL_LPTIM_ENCODER_MODE_RISING);
  37.       LL_LPTIM_EnableEncoderMode(LPTIM1);
  38.  
  39.       LL_LPTIM_Enable(LPTIM1);
  40.       LL_LPTIM_StartCounter(LPTIM1, LL_LPTIM_OPERATING_MODE_CONTINUOUS);
  41. }
  42.  
  43.  
  44. int16_t TicksLPTIM(void)
  45. {
  46.     Ticks = LPTIM1->CNT;
  47.     return Ticks;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement