Timing Problem when using Event Group and Timers

Yes, You are right. Only that Particular Group Event bit is erased in case “xClearOnExit” is “True” in case of “xEventGroupWaitBits” Function call.

I found that “xEventGroupSetBits” is triggered x times but only half of the time, the Event Group bit is not getting set. I could also observed that this is happening because this bit is getting cleared at the end of Function Call “xEventGroupSetBits”.

see below Pic.
I have added three Counters: -

  1. Counter20ms1_Timer_A → Counting the number of times the Function “xEventGroupSetBits” is triggered.
  2. Counter20ms1_Timer_B → Counting the number of times the Group event bit is actually set.
  3. ClearbitCount → Counting the number of times the Group Event bit is cleared in the function call “xEventGroupSetBits”.

You can see that Counter20ms1_Timer_A = Counter20ms1_Timer_B + ClearbitCount.
Can you let me know when this bit is cleared in the Function and If you can figure something out from my observation.

Kind Regards

Did you mean to post this to an existing support thread?

I assume it is in continuation to this post - Timing Problem when using Event Groups and Timers

What is the priority of the timer task? Make it the highest priority so that nothing can run clear the bit set by xEventGroupSetBits.

I assume it is in continuation to this post → Yes, Sorry I was trying to send you a DM.

What is the priority of the timer task? Make it the highest priority so that nothing can run clear the bit set by xEventGroupSetBits → Yes, I have the maximum number of priorities as 5, Timer Task Priority is the highest i.e. 4 and the 20ms Task has the priority as 3. I am still facing the Problem.

Please see below PIC: -

Kind Regards

Looking at your previous image, uxBitsToClear must be zero for you as you are you are passing xClearOnExit as pdFLASE to xEventGroupWaitBits.

eventCLEAR_EVENTS_ON_EXIT_BIT flag should not be set on this line - FreeRTOS-Kernel/event_groups.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub and it should remain unset on this line too - FreeRTOS-Kernel/event_groups.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub

Can you try to trace how is this becoming set on the second line? If you are not able to debug that, drop me a DM with you email and we can setup a debug session. To drop a DM, click on the image next to my display name aggarg and then click Message in the popup.

@aggarg
I was Passing pdFLASE to xClearOnExit in xEventGroupWaitBits and clearing the Event bit using xEventGroupClearBits as shown in below pic but you said that this is not correct in the previous posts (This was resolving my Issue).

Now I am passing pdTRUE to xClearOnExit in xEventGroupWaitBits and I have the Issue as seen in the below Pic. Just FYI : The Event Group bit is getting cleared in xEventGroupSetBits in the below pic.

image

Dropping the Software for you.
OS_Test.zip (1.1 MB)

Thank You

I did not say that it was not correct. I said that your explanation was incorrect. More specifically, when you set xClearOnExit to pdTRUE, only the bits you are waiting for get cleared. And therefore, the following line in your previous explanation is incorrect -

When you set xClearOnExit to pdTRUE, your clearBitCount variable is expected to increase. The reason that you see it increased only half the time is because your task is running slow and is not calling xEventGroupWaitBits enough number of times. It should be easy to verify by removing the delay loops from the task. If it is determined, it is a CPU performance issue as I suggested before.

Just for confirming, when I run the code on my platform, here are the results:

image

→ Got it
Q1) Can I use this method for my Real-Time Application??
Q2) If CPU Performance issue is the problem than why is the execution proper in case of the above implementation where I pass pdFALSE to xClearOnExit in xEventGroupWaitBits and then clear the Event bit using xEventGroupClearBits. I should be facing the same Issue?

Yes, It can be CPU performance issue.
→ When I remove the Delay Loop, I can see no problem.
Q3) When I have the Delay loop of 5ms or use non blocking RTOS Delay of 5ms using vTaskDelay(), I am still facing the same Issue in both the cases → Why can I still see the issue in case I add non-blocking delay??
Q4) I have only a single task of 20ms having a 5ms non-blocking delay as runnable using vTaskDelay() → Should this cause a CPU overload??
Q5) The CPU performance Issue you are talking about is CPU Overload??

image
Q6) Why Counter20ms1_Timer_B is 0. It should be same asCounter20ms1_Task to my understanding?

Q1) Can I use this method for my Real-Time Application??

Yes, if it suits your application need.

Q2) If CPU Performance issue is the problem than why is the execution proper in case of the above implementation where I pass pdFALSE to xClearOnExit in xEventGroupWaitBits and then clear the Event bit using xEventGroupClearBits. I should be facing the same Issue?

How are you verifying that?

Q3) When I have the Delay loop of 5ms or use non blocking RTOS Delay of 5ms using vTaskDelay(), I am still facing the same Issue in both the cases → Why can I still see the issue in case I add non-blocking delay??

It does not matter what type of delay you use. Bottom line is that your task is not able to call xEventGroupWaitBits enough number of times.

Q4) I have only a single task of 20ms having a 5ms non-blocking delay as runnable using vTaskDelay() → Should this cause a CPU overload??
Q5) The CPU performance Issue you are talking about is CPU Overload??

It is not overload but speed.

Q6) Why Counter20ms1_Timer_B is 0. It should be same asCounter20ms1_Task to my understanding?

No - every time when timer callback sets the bit by calling xEventGroupSetBits, if finds the corresponding task waiting and therefore clears the bit (because clear on exit is true). So there is no case where the bit is not cleared upon return from xEventGroupSetBits.

@aggarg Thank You so much for your Patience :smiley:.

→ I am verifying this by performing the same Counter Test by enabling and disabling xClearOnExit. You can see both the tests in the Pics below.

  1. xClearOnExit is enabled and Issue can be seen.

  2. xClearOnExit is disabled and Event group bit is erased using xEventGroupClearBits. Issue cannot be seen. If there was a CPU Performance Issue and xEventGroupWaitBits are missing. Then, Counter20ms1_Timer_A should be not same as Counter20ms1_Task

→ What does this mean(Speed Issue)?
→ The CPU is currently operating at 80MHz speed, Does this mean that we cannot use a high execution time runnable in our Task or we cannot such small TICK time(1ms) ??
→ Should I try to increase the clock for configCPU_CLOCK_HZ and test?? → (I increased the CPU Clock to 120MHz from 80MHz but still saw the same Issue)
→ What can be done to solve this Issue??

Kind Regards

I get the following with xClearOnExit set to pdFALSE:
image

However, these results depends a lot on timing and therefore, can vary between platforms. To get a detailed understanding of what is going on your platform, you should use a tool like Tracelyzer.

What does this mean(Speed Issue)?

Assuming that my guess is correct, what I mean is that the CPU is taking more time to execute code in task and as a result, wait bits is not called enough number of times.

Sure I will do that and send you the results. Thank You

Thanks. Get the traces for both the cases (i.e. xClearOnExit set to pdFALSE and pdTRUE) and share.