STM32H723ZG Frequency measure issue.
Currently using NUCLEO-STM32H723ZG board.
I'm setting TIMER1 as a PWM output, TIMER2 set as Input Capture direct mode
try to measrue the frequency output from TIMER1.
Clock Configuration : APB1/ APB2 Timer Clocks 100 (MHZ)
Timer 1 :
- Prescaler : 1-1
- Counter Period : 100-1
- PWM output
Timer 2 :
- Input Capture direct mode
- Prescaler : 0
- Counter Period: 4294967295


Whenever I modify the TIMER1 output PWM over 200KHZ, I can't get the stable value or even zero from the HAL_TIM_ReadCapturedValue.
I set the TIMER1
- prescaler : 2-1
- Counter Period : 100-1
- Which will generate the PWM to 100M / 2 / 100 = 500MHZ.
But I got read back like this.
Idealy TIMER2 run under 100MHZ( APB/PSC) should be able to capture up to 10MHZ signal.
eventually I need to measure a signal up to 100MHZ, If i set the APB bus to Max frequency (137MHZ) will this method works? or is there any other way to measure it?
#define TIMCLOCK 100000000
#define PRESCALER 1
uint32_t IC_Value1 = 0;
uint32_t IC_Value2 = 0;
uint32_t Difference = 0;
float Frequency = 0;
int Is_First_Captured = 0; // is the first value captured? 0 - no, 1- yes
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) // input capture callback
{
if (htim->Instance == TIM2)
{
if (htim -> Channel == HAL_TIM_ACTIVE_CHANNEL_1) // if the source is channel 1
{
// first we need to check for either the first value is capture or not
if (IC_Value1 == 0)
{
IC_Value1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
// IC_Value1 = __HAL_TIM_GET_COUNTER(htim);
}
else
{
IC_Value2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
// IC_Value2 = __HAL_TIM_GET_COUNTER(htim);
if (IC_Value2 > IC_Value1 )
{
Difference = IC_Value2 - IC_Value1 ;
}
else if (IC_Value2 < IC_Value1)
{
Difference = (0xffffffff-IC_Value1)+ IC_Value2 ;
}
float refClock = TIMCLOCK / PRESCALER;
float frequency = refClock / Difference;
printf("frequency = %2f Hz\r\n",frequency);
IC_Value1 = 0;
}
}
// float frequency = (TIMCLOCK / PRESCALER) / __HAL_TIM_GET_COUNTER(&htim2);
// printf("Frequency = %10.0f\r\n", frequency);
// __HAL_TIM_SET_COUNTER(&htim2, 0); // reset the counter
}
}
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USB_OTG_HS_USB_Init();
MX_TIM1_Init();
MX_USART3_UART_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
HAL_UARTEx_ReceiveToIdle_DMA(&huart3, RxBuf, RxBuf_SIZE);
TIM1 ->CCR1 = 50;
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
while (1)
{
}
}