Skip to main content
CChri.5
Associate II
March 12, 2022
Question

STM32H745I-Disco PWM Input Frequency Not detecting

  • March 12, 2022
  • 5 replies
  • 1579 views

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.

This topic has been closed for replies.

5 replies

CChri.5
CChri.5Author
Associate II
March 12, 2022
/* 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
CChri.5Author
Associate II
March 12, 2022
 */
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
CChri.5Author
Associate II
March 12, 2022
 /** 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
CChri.5Author
Associate II
March 12, 2022

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

lbthomsen
Associate
March 13, 2022

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

CChri.5
CChri.5Author
Associate II
March 13, 2022

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!