2024-08-29 02:10 AM
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:
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.
Solved! Go to Solution.
2024-08-29 05:57 AM
> uint32_t captureValue1 = htim->Instance->CCR1;
This creates a new local variable called "captureValue1", which immediately goes out of scope. You probably want to modify the global variable, which is done like this:
captureValue1 = htim->Instance->CCR1;
2024-08-29 03:04 AM
Hello @Kannn1chtpennen
You can refer to this example in STM32CubeF3 firmware.
2024-08-29 05:57 AM
> uint32_t captureValue1 = htim->Instance->CCR1;
This creates a new local variable called "captureValue1", which immediately goes out of scope. You probably want to modify the global variable, which is done like this:
captureValue1 = htim->Instance->CCR1;
2024-08-29 06:22 AM
Thank you TDK,
Just as you mentioned, I forgot to set my variable as a global variable. Thank you for your reply