AnsweredAssumed Answered

can't able to read capture and compare values on STM32F0 Board

Question asked by kumar.jagadeesh on Oct 14, 2015
hi,
I am trying to input capture and output compare values but i cant able to read those values is there any mistake in my code.I enabled clocks also.But still I am getting this issue.Can any one guide me please.

// init function
  void MX_TIM15_Init(void)
{
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
  TIM_IC_InitTypeDef sConfigIC;
  TIM_OC_InitTypeDef sConfigOC;
  
  
  htim15.Instance = TIM15;
  htim15.Init.Prescaler = 0;
  htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim15.Init.Period = 16666;
  htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim15.Init.RepetitionCounter = 0; 


  HAL_TIM_IC_Init(&htim15);


  HAL_TIM_OC_Init(&htim15);


  sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENABLE;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig);


  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
  sBreakDeadTimeConfig.DeadTime = 0;
  sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
  HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig);


  sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
  sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  sConfigIC.ICPrescaler = TIM_ICPSC_DIV2;
  sConfigIC.ICFilter = 0;
  HAL_TIM_IC_ConfigChannel(&htim15, &sConfigIC, TIM_CHANNEL_1);


  sConfigOC.OCMode = TIM_OCMODE_TIMING;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
  TIM_OC2_SetConfig( (TIM_TypeDef* )&htim15.Instance,&sConfigOC);
  HAL_TIM_OC_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2);
  HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
  HAL_TIM_OC_Start_IT(&htim15,TIM_CHANNEL_2);
  HAL_TIM_IC_Start_IT(&htim15,TIM_CHANNEL_1);
  __HAL_TIM_ENABLE_IT(&htim15,TIM_IT_CC2); //output compare 
  __HAL_TIM_ENABLE_IT(&htim15,TIM_IT_CC1);
}
//interrupt functions
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
  
  uint32_t OutPutCompare = 0;
OutPutCompare = HAL_TIM_ReadCapturedValue(&htim15, TIM_CHANNEL_2 );
      __HAL_TIM_SET_COUNTER(&htim15,DaliOutPutCompare + 16666 );
      __HAL_TIM_CLEAR_IT(&htim15,TIM_IT_CC2);
      __HAL_TIM_CLEAR_FLAG(&htim15, TIM_FLAG_CC2);
}

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
  uint32_t InputCapture;
InputCapture = HAL_TIM_ReadCapturedValue(&htim15, TIM_CHANNEL_1 );
     __HAL_TIM_SET_COUNTER(&htim15,DaliInputCapture + 16666 );
     __HAL_TIM_CLEAR_IT(&htim15,TIM_IT_CC1);
     __HAL_TIM_CLEAR_FLAG(&htim15, TIM_FLAG_CC1);
}

Outcomes