Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void EncoderInit_LPTIM(void)
- {
- LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
- /* Peripheral clock enable */
- LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPTIM1);
- LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
- /**LPTIM1 GPIO Configuration
- PC0 ------> LPTIM1_IN1
- PC2 ------> LPTIM1_IN2
- */
- GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
- GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
- GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
- LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
- GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
- GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
- LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- LL_LPTIM_SetClockSource(LPTIM1, LL_LPTIM_CLK_SOURCE_INTERNAL);
- LL_LPTIM_SetPrescaler(LPTIM1, LL_LPTIM_PRESCALER_DIV1);
- LL_LPTIM_SetPolarity(LPTIM1, LL_LPTIM_OUTPUT_POLARITY_REGULAR);
- LL_LPTIM_SetUpdateMode(LPTIM1, LL_LPTIM_UPDATE_MODE_IMMEDIATE);
- LL_LPTIM_SetCounterMode(LPTIM1, LL_LPTIM_COUNTER_MODE_EXTERNAL);
- LL_LPTIM_ConfigClock(LPTIM1, LL_LPTIM_CLK_FILTER_NONE, LL_LPTIM_CLK_POLARITY_RISING);
- LL_LPTIM_TrigSw(LPTIM1);
- LL_LPTIM_SetEncoderMode(LPTIM1, LL_LPTIM_ENCODER_MODE_RISING);
- LL_LPTIM_EnableEncoderMode(LPTIM1);
- LL_LPTIM_Enable(LPTIM1);
- LL_LPTIM_StartCounter(LPTIM1, LL_LPTIM_OPERATING_MODE_CONTINUOUS);
- }
- int16_t TicksLPTIM(void)
- {
- Ticks = LPTIM1->CNT;
- return Ticks;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement