Skip to main content
Associate II
November 29, 2024
Solved

Pulse width measurement under interrupt

Hello everyone,

I'm designing a new system based on the STM32F746BET6.
Basically it's just reading and writing GPIOs and receiving/transmitting data through a few interfaces (ethernet and I2C). The system receives a 100 bit/sec data frame every second for time tagging (IRIG-B) and have to measure time width of every pulse received in order to decode the message (width of every pulse varies from 2 ms to 8 ms).

My idea is capturing every rising and falling edge with a timer and then calculating time difference in order to obtain the pulse with. Still, I have a few questions about it.

1) To do so, my system will get an interrupt everytime an edge is detected on my timer pin. Will this stop the uC from its tasks everytime an edge is detected?

2) Do I really need a timer to detect edges or is there some other way to get pulses width?

Thank you very much in advanced  

This topic has been closed for replies.
mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
November 29, 2024

Hello,

Maybe I suggest using PWM input with which you can measure the high pulse and the period. Maybe also using DMA timer request to receive a burst of pulse and then calculate all the pulse durations after..

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.

6 replies

mƎALLEm
mƎALLEmBest answer
ST Technical Moderator
November 29, 2024

Hello,

Maybe I suggest using PWM input with which you can measure the high pulse and the period. Maybe also using DMA timer request to receive a burst of pulse and then calculate all the pulse durations after..

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Associate II
November 29, 2024

Hello,

Thank you for your answer. Will I still get an interrupt everytime I get an edge on my PWM input?

Thank you very much in advanced.

mƎALLEm
ST Technical Moderator
November 29, 2024

No with DMA you will get an interrupt at the end of DMA transfer. For that you need to set the data to transfer > 1.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Andrew Neil
Super User
November 29, 2024

@NDicostanzo wrote:

my system will get an interrupt everytime an edge is detected on my timer pin. Will this stop the uC from its tasks everytime an edge is detected?  


An interrupt blocks software executing at lower priority.

So it won't block the hardware operations of stuff like the I2C and Ethernet peripherals.

This is why it's important to keep interrupt handlers as short (timewise) as possible

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
December 2, 2024

That's the point.

I cannot block all the other software instructions everytime I get an edge on my interrupt pin. Still, I have to measure time width of all the pulses.

I was considering to add another microcontroller for handling the with measurement operation, then send data via I2C to the main mcu which will be interrupted upon reception.

waclawek.jan
Super User
December 2, 2024

You can use DMA to store the captured timestamps to a buffer in RAM, and then process it later, whenever you see it fit.

JW