AnsweredAssumed Answered

Cube generated code - Encoder mode on a F401 - No interrupts

Question asked by curran.danny on Jul 6, 2015
Latest reply on Jul 8, 2015 by chahrayar.chahrazed
Folks,
Hopefully someone may be able to point me in the right direction

I have a F401RE nucleous board connected to a Quadrature encoder via Tim1
I have used Cube v4.8 to try set the device up ( and use it inconjunction with Keil V5.15) .
The Encoder code does not appear to function correctly in the fact that it appears only the IO is setup and the mode of the timer is set.  

I have noticed that in none cube examples given by others there is code to set up the time base etc  

So when I set the debugger going I can see DIR bit changing dependent upon the encoder movement but there is no count change.

Also I have had trouble getting any interrupts to work ( eg Serial port ) all seem to be configured in a similar manner to the original CMSIS hal but with the Cube CMSIS the interrupts fail to work 

Has anyone come across this? 
The encoder functionality at the mo is my priority 

this is the code for the tim1 producved by Cube what has caught my interst is that it sets 
 htim1.Init.Period = 0;
in none cube code it sets that to 0xFFFF 

plus .Period is a uint32_t  but it has warning in stm32f4xx_hal_tim.h about only setting it to a max of 0xFFFF

e.g.   uint32_t Period;            /*!< Specifies the period value to be loaded into the active
                                   Auto-Reload Register at the next update event.
                                   This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF.  */

void MX_TIM1_Init(void)
{
  TIM_Encoder_InitTypeDef sConfig;
  TIM_MasterConfigTypeDef sMasterConfig;
  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 0;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 0;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
  sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
  sConfig.IC1Filter = 0;
  sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
  sConfig.IC2Filter = 0;
  HAL_TIM_Encoder_Init(&htim1, &sConfig);


  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig);
}









Outcomes