cancel
Showing results for 
Search instead for 
Did you mean: 

CCR Values Show on STM32F334R8 MCU but readCaptureValue Returns Zero

Kannn1chtpennen
Associate II

 

Hello everyone,

I'm working on a project using the STM32F334R8 MCU to capture two rising edge signals with the intent of obtaining the CNT value at each signal's rising edge. My calculations and data are meant to be processed through an external interrupt and transmitted to a computer. I am using a 72 MHz clock with Timer 2, specifically channel 1 and 4.

In my debug testing, everything initializes correctly—both input capture and external interrupts start properly, and both CCR1 and CCR4 registers display values. However, when I attempt to retrieve these values using readcapture, the function consistently returns zero. I have also tried accessing the register values directly without using the API, but the results remain the same.

Here are some key points:

  • MCU: STM32F334R8
  • Timer Clock: 72 MHz
  • Timer used: Timer 2 (Channel 1 and 4)
  • Issue: CCR displays values, but HAL_TIM_ReadCaptureValue() returns zero.

Has anyone encountered a similar issue or can provide insights on why this discrepancy occurs and how to fix it? Any advice or suggestions would be greatly appreciated.

Thank you in advance for your help!

 

My code and debug screenshots are as follows.

  uint32_t captureValue1; 
  uint32_t captureValue4; 
  uint16_t a; 
  uint16_t b; 
  uint16_t c; 
  uint32_t diff;
 
 
 void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
 {
if(htim->Channel==HAL_TIM_ACTIVE_CHANNEL_1) // Ref Signal
{
a++;
//uint32_t captureValue1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); 
uint32_t captureValue1 = htim->Instance->CCR1;
 
}
else if(htim->Channel==HAL_TIM_ACTIVE_CHANNEL_4)
{
b++;
//uint32_t captureValue4 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4); 
uint32_t captureValue4 = htim->Instance->CCR4;
}
 
 }
 
 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_PIN)
 {
if(GPIO_PIN==GPIO_PIN_6)
{
c++;
uint32_t diff=captureValue4-captureValue1; 
char buffer[10];
int len= sprintf(buffer,"%u\r\n", diff); 
  HAL_UART_Transmit(&huart2, (uint8_t*)buffer, len, HAL_MAX_DELAY); 
}
 }

foto.jpg

1 REPLY 1
Saket_Om
ST Employee

Hello @Kannn1chtpennen 

 

You can refer to this example in STM32CubeF3 firmware. 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar