Skip to main content
Associate II
September 27, 2024
Question

Issue with 12-Lead ECG Waveform Plotting and GUI Implementation on STM32

  • September 27, 2024
  • 5 replies
  • 6695 views

Dear STMicroelectronics Support Team,

I am currently working on a project using an STM32 microcontroller where I need to display a 12-lead ECG waveform. The display layout is configured in a 3x4 grid format, along with an R-1 waveform shrink. I have implemented an RTOS for managing the GUI rendering and data handling efficiently.

For the GUI, I am using the TouchGFX framework and have integrated dynamic graphs to plot the 12-lead ECG waveforms in real-time. The ECG module communicates with the STM32 via UART using interrupts to handle data reception.

However, I am facing issues with accurately plotting the ECG waveforms on the screen. The waveform representation seems to shrink or misalign, particularly in the R-1 section. Despite configuring tasks with adequate priorities and stack sizes for the GUI and ECG data, and ensuring the refresh rate is set to 4 ms, I am unable to achieve a stable display.

Could you please provide guidance on optimizing the dynamic graph display using TouchGFX or recommend any specific configurations in the STM32 settings that could resolve this issue? Any advice on fine-tuning the integration between the RTOS, UART, and TouchGFX would also be highly appreciated.

Your support and insights would be greatly valued.

Thank you.

5 replies

GaetanGodart
Technical Moderator
September 27, 2024

Hello @smj-11 ,

 

When you say R-1, do you mean R1 or "R minus 1"?
From what I have seen, ECG goes from R1 to R5.
But I do not think that is relevant for the question, because in the end it is always just data being displayed.

 

Can you share with me what you expect to see and what you actually have?

Can you also share your project maybe?

 

You say "refresh rate is set to 4 ms", which refresh rate is that? The ECG Data?
Why is it 4ms?

 

Regards,

Andrew Neil
Super User
September 27, 2024

@GaetanGodart wrote:

You say "refresh rate is set to 4 ms", which refresh rate is that? The ECG Data?
Why is it 4ms?


Indeed.

A human heart rate isn't going to be over 220 beats per minute - so under 4 per second.

So a refresh rate of 4ms is going to be over 1000 "refreshes" (whatever they may be) per beat!

Seems a tad excessive?

 

https://en.wikipedia.org/wiki/Heart_rate#Maximum_heart_rate

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.
GaetanGodart
Technical Moderator
September 27, 2024

Ok but most TouchGFX screens refresh rate is 60 ticks per second so 16,6 ms.

I do not know what smj is using to display the framebuffer rendered by TouchGFX.

Andrew Neil
Super User
September 27, 2024

@smj-11 wrote:

The ECG module communicates with the STM32 via UART using interrupts to handle data reception.

However, I am facing issues with accurately plotting the ECG waveforms on the screen. The waveform representation seems to shrink or misalign


Are you sure that the display problems aren't down to problems in the comms link ... ?

ie, data is getting corrupted before reaching the display - and the display is accurately showing what it receives?

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.
smj-11Author
Associate II
September 28, 2024

Hi Gaetan,

Thank you for the clarification.

The display I’m using is a 10.1-inch RGB panel connected to the STM32H753 microcontroller. The frame buffer is managed using external SDRAM with a stride width of 1280 to match the display resolution.

Regarding the refresh rate, I’m aware that most TouchGFX displays operate at 60 frames per second, corresponding to 16.6 ms per frame. However, for the ECG application, I aimed for a higher GUI update rate of 4 ms to match the UART data reception rate and avoid latency in displaying rapidly changing waveforms. This is where the inconsistency might be occurring, as the graph might not be able to keep up with the rapid updates.

Framebuffer Configuration:
The framebuffer is updated dynamically using a dedicated DMA transfer triggered by VSYNC interrupts. This is configured to avoid tearing or misalignment. However, I suspect the current refresh rate mismatch could be causing the shrinking or compression of the ECG waveforms.

Could you suggest a better way to handle this, such as a method to buffer data temporarily and update the screen at a more stable rate (e.g., every 16.6 ms) while maintaining smooth waveform visualization?

Let me know if I should provide further technical details or share the project setup.

Thank you for your continued support!

Andrew Neil
Super User
September 28, 2024

@smj-11 wrote:

I aimed for a higher GUI update rate of 4 ms to match the UART data reception rate and avoid latency in displaying rapidly changing waveforms. 


But, surely, ECG waveforms don't change that rapidly?

(see previous post)

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.
smj-11Author
Associate II
September 28, 2024

I am currently working on an ECG monitoring project using an STM32H7 microcontroller with TouchGFX for the graphical interface. I need to visualize ECG waveforms at a 4 ms interval, and I use the Dynamic Graph Widget in TouchGFX to achieve this. However, I require some guidance on the optimal way to handle the data refresh rate and synchronization with my system.

Key Project Details:

  • Microcontroller: STM32H7 series
  • Graphical Library: TouchGFX
  • Data Rate: ECG data is received via UART every 4 ms
  • Display Update Rate: The display needs to refresh and render each ECG data point at this 4 ms interval
  • Graph Widget: Dynamic Graph Widget in TouchGFX

Current Implementation:

  • I am receiving ECG data through UART and storing it in a FreeRTOS message queue. The data is processed and parsed into the corresponding ECG leads (I, II, III, V1-V6, etc.).
  • The system is using a queue to buffer the data, and I update the graph at regular intervals.
  • The TouchGFX task is responsible for updating the UI, and I am using the Dynamic Graph Widget to visualize the ECG waveform.

Challenges:

  1. How can I ensure smooth and real-time rendering of ECG waveforms at the required 4 ms interval using the Dynamic Graph Widget? Are there any best practices or examples for synchronizing data updates at such a high frequency?
  2. What is the best way to handle dynamic data input and ensure that the display refreshes efficiently without missing any data points or causing performance issues?
  3. Are there any specific configuration settings or optimization techniques in TouchGFX that I should be aware of to achieve this?
Andrew Neil
Super User
September 28, 2024

@smj-11 wrote:

 I need to visualize ECG waveforms at a 4 ms interval, ?


But Why?

That doesn't make sense - for both the reasons @MM..1 said, and the ones I gave earlier.

You also didn't say how you've verified that the UART comms is free of errors & losses ...

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.
GaetanGodart
Technical Moderator
September 30, 2024

Thank you for the extra information.

 

Could you share a set of data that creates the issue so I can try to reproduce it.

 

The issue happens only on the bottom graph?
Not on the 1st, 2nd or 3rd graph?
If so, what happens when you try to plot the data from the dataset that creates the issue on graph 1, 2 or 3?

 

Regards,

smj-11Author
Associate II
September 30, 2024

The issue happens across all 13 dynamic graphs, not just the bottom one. So, it’s not limited to a particular graph or position.

I’m using a UART ECG module to receive data, and I think it might be a timing issue. When I plot broader waves like square or sine waves, they appear smooth. But as the frequency increases, the shape of the waves starts to change, leading to the same inconsistent peaks and distorted waveforms.

GaetanGodart
Technical Moderator
September 30, 2024

Do you have a picture of this behavior?

When you increase the frequency what do you do?

  1. Do you only increase the frequency of the data fetch and keep the display at 4ms, so sometimes it will not add a data point to the graph?
  2. Do you increase the frequency of the data fetch and increase the refresh rate of the screen?
  3. Do you keep the data fetch at at the same speed and increase the refresh rate of the screen only?

 

Regards,