void vMBPortTimersDisable( ) { /* Disable any pending timers. */ __HAL_TIM_DISABLE(&htim6); __HAL_TIM_SetCounter(&htim6,0); __HAL_TIM_DISABLE_IT(&htim6,TIM_IT_UPDATE); __HAL_TIM_CLEAR_IT(&htim6,TIM_IT_UPDATE); }
// Clear timer counter to 0, and then start the timer int timer_reset_n_go(hacs_timer_t tim) { TIM_HandleTypeDef *htim = &tim_handles[tim]; __HAL_TIM_DISABLE(htim); __HAL_TIM_SetCounter(htim, 0); __HAL_TIM_ENABLE(htim); return HACS_NO_ERROR; }
void vMBPortTimersEnable( ) { /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */ /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */ __HAL_TIM_CLEAR_IT(&htim6,TIM_IT_UPDATE); __HAL_TIM_ENABLE_IT(&htim6,TIM_IT_UPDATE); __HAL_TIM_SetCounter(&htim6,0); __HAL_TIM_ENABLE(&htim6); }
void encoder2_init(void) { GPIO_InitTypeDef gpio_init; gpio_init.Pin = GPIO_PIN_12; gpio_init.Pull = GPIO_PULLUP; gpio_init.Speed = GPIO_SPEED_HIGH; gpio_init.Mode = GPIO_MODE_AF_PP; gpio_init.Alternate = GPIO_AF2_TIM4; __GPIOD_CLK_ENABLE(); HAL_GPIO_Init(GPIOD, &gpio_init); gpio_init.Pin = GPIO_PIN_13; HAL_GPIO_Init(GPIOD, &gpio_init); __TIM4_CLK_ENABLE(); hTIM4.Instance = TIM4; // hTIM4.Init.Prescaler = (SystemCoreClock/65535) - 1; // 1s // hTIM4.Init.CounterMode = TIM_COUNTERMODE_UP; // hTIM4.Init.ClockDivision = 0; hTIM4.Init.Period = 65535; //hTIM4.Channel = HAL_TIM_ACTIVE_CHANNEL_1 | HAL_TIM_ACTIVE_CHANNEL_2; //HAL_TIM_Base_Init(&hTIM4); TIM_Encoder_InitTypeDef enc_init; enc_init.EncoderMode = TIM_ENCODERMODE_TI12; enc_init.IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING; enc_init.IC2Polarity = TIM_INPUTCHANNELPOLARITY_RISING; enc_init.IC1Selection = TIM_ICSELECTION_DIRECTTI; enc_init.IC2Selection = TIM_ICSELECTION_DIRECTTI; enc_init.IC1Prescaler = TIM_ICPSC_DIV1; enc_init.IC2Prescaler = TIM_ICPSC_DIV1; enc_init.IC1Filter = 0; enc_init.IC2Filter = 0; HAL_TIM_Encoder_Init(&hTIM4, &enc_init); __HAL_TIM_SetCounter(&hTIM4,0); HAL_TIM_Encoder_Start(&hTIM4, TIM_CHANNEL_1 | TIM_CHANNEL_2); }
/********************************************************** * @brief Encoder init timer 8 * @param None * @retval None **********************************************************/ static void encoder_iniTimer8(void) { TIM_HandleTypeDef timer8_initStruct; TIM_Encoder_InitTypeDef t8Encod_initStruct; // TIM8 Clock Enable __TIM8_CLK_ENABLE(); // Timer 8 init structure timer8_initStruct.Instance = TIM8; timer8_initStruct.Init.Prescaler = 0; timer8_initStruct.Init.CounterMode = TIM_COUNTERMODE_UP; timer8_initStruct.Init.Period = 0xFFFF; timer8_initStruct.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; t8Encod_initStruct.EncoderMode = TIM_ENCODERMODE_TI12; t8Encod_initStruct.IC1Polarity = TIM_INPUTCHANNELPOLARITY_RISING; t8Encod_initStruct.IC2Polarity = TIM_INPUTCHANNELPOLARITY_RISING; t8Encod_initStruct.IC1Selection = TIM_ICSELECTION_DIRECTTI; t8Encod_initStruct.IC2Selection = TIM_ICSELECTION_DIRECTTI; t8Encod_initStruct.IC1Prescaler = TIM_ICPSC_DIV1; t8Encod_initStruct.IC2Prescaler = TIM_ICPSC_DIV1; t8Encod_initStruct.IC1Filter = 8;// digital filter t8Encod_initStruct.IC2Filter = 8;// digital filter // Init timer HAL_TIM_Encoder_Init(&timer8_initStruct,&t8Encod_initStruct); __HAL_TIM_SetCounter(&timer8_initStruct,0); HAL_TIM_Encoder_Start(&timer8_initStruct, TIM_CHANNEL_1 | TIM_CHANNEL_2); }
void TickTock_Start(void) { __HAL_TIM_SetCounter(&TIM_Handle,0); }
/** * @brief Initialize encoder reader. */ void encoder_init(void) { HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_1 | TIM_CHANNEL_2); __HAL_TIM_SetCounter(&htim2, 0x7FFFFFFF); }
void ClearCMX7262TimerCounter(void) { __HAL_TIM_SetCounter(&htim5,0); }
void ClearHighPrecisionCounter(void) { __HAL_TIM_SetCounter(&htim2,0); __HAL_TIM_SetCounter(&htim3,0); }
/** * @brief SYSTICK callback. * @param None * @retval None */ void HAL_SYSTICK_Callback(void) { uint8_t *buf; uint16_t Temp_X, Temp_Y = 0x00; uint16_t NewARR_X, NewARR_Y = 0x00; if (DemoEnterCondition != 0x00) { buf = USBD_HID_GetPos(); if((buf[1] != 0) ||(buf[2] != 0)) { USBD_HID_SendReport (&hUSBDDevice, buf, 4); } Counter ++; if (Counter == 10) { /* Reset Buffer used to get accelerometer values */ Buffer[0] = 0; Buffer[1] = 0; /* Disable All TIM4 Capture Compare Channels */ HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_1); HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_2); HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4); /* Read Acceleration*/ BSP_ACCELERO_GetXYZ(Buffer); /* Set X and Y positions */ X_Offset = Buffer[0]; Y_Offset = Buffer[1]; /* Update New autoreload value in case of X or Y acceleration*/ /* Basic accelration X_Offset and Y_Offset are divide by 40 to fir with ARR range */ NewARR_X = TIM_ARR - ABS(X_Offset/3); NewARR_Y = TIM_ARR - ABS(Y_Offset/3); /* Calculation of Max acceleration detected on X or Y axis */ Temp_X = ABS(X_Offset/3); Temp_Y = ABS(Y_Offset/3); MaxAcceleration = MAX_AB(Temp_X, Temp_Y); if(MaxAcceleration != 0) { /* Reset CNT to a lowest value (equal to min CCRx of all Channels) */ __HAL_TIM_SetCounter(&htim4,(TIM_ARR-MaxAcceleration)/2); if (X_Offset < ThreadholdAcceleroLow) { /* Sets the TIM4 Capture Compare for Channel1 Register value */ /* Equal to NewARR_X/2 to have duty cycle equal to 50% */ __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_1, NewARR_X/2); /* Time base configuration */ __HAL_TIM_SetAutoreload(&htim4, NewARR_X); /* Enable TIM4 Capture Compare Channel1 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); } else if (X_Offset > ThreadholdAcceleroHigh) { /* Sets the TIM4 Capture Compare for Channel3 Register value */ /* Equal to NewARR_X/2 to have duty cycle equal to 50% */ __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, NewARR_X/2); /* Time base configuration */ __HAL_TIM_SetAutoreload(&htim4, NewARR_X); /* Enable TIM4 Capture Compare Channel3 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); } if (Y_Offset > ThreadholdAcceleroHigh) { /* Sets the TIM4 Capture Compare for Channel2 Register value */ /* Equal to NewARR_Y/2 to have duty cycle equal to 50% */ __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_2,NewARR_Y/2); /* Time base configuration */ __HAL_TIM_SetAutoreload(&htim4, NewARR_Y); /* Enable TIM4 Capture Compare Channel2 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2); } else if (Y_Offset < ThreadholdAcceleroLow) { /* Sets the TIM4 Capture Compare for Channel4 Register value */ /* Equal to NewARR_Y/2 to have duty cycle equal to 50% */ __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_4, NewARR_Y/2); /* Time base configuration */ __HAL_TIM_SetAutoreload(&htim4, NewARR_Y); /* Enable TIM4 Capture Compare Channel4 */ HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); } } Counter = 0x00; } } }
void TIMER5_Reset(void) { TIMER5_Stop(); __HAL_TIM_SetCounter(&timer_hd, 0); }