cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H745I-Disco PWM Input Frequency Not detecting

CChri.5
Associate III

Hi, I am trying to detect a 3v PWM frequency with my STM32, I have my live expresions setup for my variables, but the values do not budge from 0. Im sure it is something up with my code. Any help would be appreciated cheers.

6 REPLIES 6
CChri.5
Associate III
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM1_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
uint32_t ICValue = 0;
uint32_t Frequency = 0;
 
float Duty = 0;
 
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
	if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)  // If the interrupt is triggered by channel 1
	{
		// Read the IC value
		ICValue = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
 
		if (ICValue != 0)
		{
			// calculate the Duty Cycle
			Duty = (HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2) *100)/ICValue;
 
			Frequency = 36000000/ICValue;
		}
	}
}
 
 
/* USER CODE END 0 */

CChri.5
Associate III
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
	HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1);  // channel 1 main
	HAL_TIM_IC_Start(&htim1,  TIM_CHANNEL_2); // channel 2 indirect
 
 
 
 
  /* USER CODE END 1 */

CChri.5
Associate III
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 5;
  RCC_OscInitStruct.PLL.PLLN = 72;
  RCC_OscInitStruct.PLL.PLLP = 2;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  RCC_OscInitStruct.PLL.PLLR = 4;
  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
  RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  RCC_OscInitStruct.PLL.PLLFRACN = 0;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

CChri.5
Associate III

The input signal is connect to my PA8 terminal of my STM32

lbthomsen
Associate II

Did you enable the Global interrupt of the timer you use for the capture?

I've got a working example described here: https://stm32world.com/wiki/STM32_Timer_PWM_Input_Capture

Ah, I think thats where I have gone wrong. I'll sort that out, if that doesn't work i'll give your example a trial. Cheers!