Home > other >  STM32 HAL library orthogonal decoding
STM32 HAL library orthogonal decoding

Time:09-17

Consult everybody, I made the encoder STM32 HAL library of orthogonal decoding, the idea is to count on overflow or underflow after enter the interrupt, into a callback function to read the count value and direction, but the callback function into not to go, can help have a look at programs have what problem? The main function of the initialization when calling void TIM4_Encoder_Configration (under-16 arr, under-16 PSC) should I feel ok? Why not go to the callback function? I think should be into the void HAL_TIM_IC_CaptureCallback (TIM_HandleTypeDef * htim) this callback function right? Relevant procedure is as follows:
Void TIM4_Encoder_Configration (under-16 arr, under-16 PSC)
{
Htim4. Instance=TIM4;
Htim4. Init. Prescaler=0;//frequency division coefficient
Htim4. Init. CounterMode=TIM_COUNTERMODE_UP;//counter up
Htim4. Init. Period=arr;//loading value automatically, when the TIM4 - & gt; CNT to interrupt during the equals the value and the value of
Htim4. Init. ClockDivision=TIM_CLOCKDIVISION_DIV1;//the clock divider factor, frequency division,
//HAL_TIM_Base_Init (& amp; Htim4);//HAL_TIM_OC_Init (& amp; Htim4);


Htim4_encoder. EncoderMode=TIM_ENCODERMODE_TI12;//mode selection, is single-phase count (can only reflect speed) or bipolar count (speed and direction)? Is this meaning?
Htim4_encoder. IC1Filter=6;//a lot of other programs here is 6
Htim4_encoder. IC1Polarity=TIM_ICPOLARITY_RISING;//1 phase is rising along the trigger
Htim4_encoder. IC1Prescaler=TIM_ICPSC_DIV1;
Htim4_encoder. IC1Selection=TIM_ICSELECTION_DIRECTTI;


Htim4_encoder. IC2Filter=6;
Htim4_encoder. IC2Polarity=TIM_ICPOLARITY_RISING;//2 phase is rising along the trigger
Htim4_encoder. IC2Selection=TIM_ICSELECTION_DIRECTTI;
Htim4_encoder. IC2Prescaler=TIM_ICPSC_DIV1;
HAL_TIM_Encoder_Init (& amp; Htim4, & amp; Htim4_encoder);

HAL_TIM_Encoder_Start_IT (& amp; Htim4 TIM_CHANNEL_ALL);

TIM4 - & gt; CNT=0;

}
Void HAL_TIM_Encoder_MspInit (TIM_HandleTypeDef * htim)//D12 D13 D14 D15 AF2 is TIM4 CH1 CH2 CH3 CH4, corresponding faith they PWM interface from left to right below 4 pins,
{
GPIO_InitTypeDef GPIO_Initure;
If (htim - & gt; The Instance==TIM4)
{
__HAL_RCC_GPIOD_CLK_ENABLE ();//open GPIOD clock
__HAL_RCC_TIM4_CLK_ENABLE ();//can make TIM4 clock
GPIO_Initure. Pin=GPIO_PIN_12 | GPIO_PIN_13;
GPIO_Initure. Mode=GPIO_MODE_AF_PP;//enter
GPIO_Initure. Pull=GPIO_PULLUP;//pull
GPIO_Initure. Alternate=GPIO_AF2_TIM4;//
HAL_GPIO_Init (GPIOD, & amp; GPIO_Initure);

HAL_NVIC_SetPriority (TIM4_IRQn, 0, 0);//set the interrupt priority, preemption priority 2, son priority 0
HAL_NVIC_EnableIRQ (TIM4_IRQn);//open channel ITM4 interrupt

TIM4 - & gt; CNT=0;
}

}
Void TIM4_IRQHandler (void)
{
HAL_TIM_IRQHandler (& amp; Htim4);
}

CodePudding user response:

You there and the main function is initialized, because is the original factory to provide the form of libraries, so some of the code are simulation did not enter,
You have to through other ways to judge whether the code execution,

CodePudding user response:

Well well, thank you, I mean in the main initialization function,

CodePudding user response:

On your main function calls using __HAL_TIM_ENABLE_IT after initialization function (& amp; Htim4, the channel position) function which channel which is invoked by specific use
Detailed parameters see HAL library handbook
__HAL_TIM_ENABLE_IT Description:
? Enable the specified TIM interrupts.
The Parameters:
? __HANDLE__ : specifies the TIM Handle.
? __INTERRUPT__ : specifies the TIM
Interrupt source. To enable This parameter
Can be one of the following values:
? TIM_IT_UPDATE: Update interrupt
? TIM_IT_CC1: the Capture/Compare 1
Interrupt
? TIM_IT_CC2: the Capture/Compare 2
Interrupt
? TIM_IT_CC3: the Capture/Compare 3
Interrupt
? TIM_IT_CC4: the Capture/Compare 4
Interrupt
? TIM_IT_COM: Commutation interrupt
? TIM_IT_TRIGGER: Trigger interrupt
? TIM_IT_BREAK: Break interrupt
The Return value:
? None
  • Related