2025-03-20 11:53 PM - last edited on 2025-03-21 2:10 AM by Andrew Neil
I am using STM32F100. I wrote a very long code for my timer interrupt. If the processing time of this code exceeds the interrupt duration, can a pin I SET be RESET?
2025-03-21 1:42 AM
How can I see how many milliseconds it takes for the MCU to complete the code I wrote in the timer interrupt routine?
2025-03-21 1:48 AM
You want to keep handling interrupts as short as possible. If it takes too long you need to break it up in multiple steps.
2025-03-21 2:04 AM
As @unsigned_char_array said, please give some more details - see: How to write your question to maximize your chances to find a solution.
@XooM wrote:I wrote a very long code for my timer interrupt.
That's generally a poor practice - so why did you do that?
Rather than try to bodge the problems that it causes, why not adopt a better approach instead?
@XooM wrote:can a pin I SET be RESET?
Pardon?
@XooM wrote:How can I see how many milliseconds it takes for the MCU to complete the code
2025-03-22 4:40 AM
I have a relay connected to my PB13 output.
Even though I keep the PB13 pin, to which the relay is connected, in the '1' position, it occasionally switches to the '0' position. This causes the relay to chatter. And I can’t find what’s causing this issue in my program.
Since the program is long, I can’t share it here.
I’m trying to figure out what could be causing this drop to '0.'
I wanted to ask if the timer interrupt routine’s code not being processed before another timer interrupt occurs could be causing this issue.
2025-03-22 4:56 AM - edited 2025-03-22 5:00 AM
@XooM wrote:I have a relay connected to my PB13 output.
Show your schematic.
It's generally a bad idea to connect a relay direct to a microcontroller pin.
@XooM wrote:Since the program is long, I can’t share it here.
So try to create a minimal program which demonstrates the issue.
Chances are that the process of doing that will help you to find the problem - even before you post it!
@XooM wrote:This causes the relay to chatter. And I can’t find what’s causing this issue in my program.
Find all locations* in your program which write to the pin.
Put breakpoints on the ones which write a zero.
When the breakpoint is hit, see how the code got there.
* This where having well-structured code, with only one place writing to the pin, helps!
@XooM wrote:I wanted to ask if the timer interrupt routine’s code not being processed before another timer interrupt occurs could be causing this issue.
Way too little information to be able to say.
As already noted, having over-long interrupt routines is generally a Bad Idea - so why not just fix that?
@Andrew Neil wrote:
@XooM wrote:How can I see how many milliseconds it takes for the MCU to complete the code
- toggle an IO pin at the start of your routine, and again at the end. view the pin on an oscilloscope or logic analyser.
You could also use this technique to see if the dropping of the pin corresponds to the execution of the interrupt routine - or any other code execution.
Having your code give status output to a UART could also help.
(but don't do UART output in an ISR!)