Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 5 months ago.
Strange behavior
With this new release, I encountered strange behaviors below. Both can be compiled and behaved as expected by using previous releases.
1) wait(float s) statement it looks that this statement really waits for 10 times more time than expected "s" seconds. For example, wait(5.0) seems wait for 50 seconds.
"wait_ms" also behaves same as "wait".
2) const float PI = 3.14; This declaration causes compilation error. Below error message is output. Expected an identifier in "I = 3.14;"
Question relating to:
2 Answers
7 years, 4 months ago.
I've tested that on mbed OS master:
uint32_t start = us_ticker_read(); wait(5.0); printf("Time: %u\n\r", us_ticker_read() - start);
I'm getting Time: 5000000 and it actually takes around 5 seconds using a stopwatch.
As to 2, that's because of arm_math.h which is included by default for mbed OS (due to IAR limitation and CLZ intrinsic), defining:
- define PI 3.14159265358979f so if you try defining variable of that name it's not going to work. I agree the name is unfortunet, it should use some sort of prefix (like M_PI is using). Hope that helps, Bartek
Thank you for your reply.
I think the essential problem is that "wait function" behaves differently under different OS releases. I've run below code under two OS releases.
pc.printf("mbed OS: %d.%d.%d Release\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); uint32_t start = us_time.read_us(); wait_ms(5); pc.printf("Elapsed time = %u\n", us_time.read_us());
The results are: (1) mbed OS: 5.5.1 Release Elapsed time = 61293
(2) mbed OS: 5.4.7 Release Elapsed time = 6471
Under previous OS release, I can get expected result. But "wait function" seems to wait about ten times longer time than it should .
Also, as to "define PI = 3.14.....", it's OK under previous OS Release but not under latest release.
posted by 01 Jul 20177 years, 4 months ago.
I though it *was once* the case that the global wait performed a spinning wait (running state) and that Thread::wait became the recommended API.
Looking at the source, then it seems sub ms delays are spinning and larger delays use Thread::wait
https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_wait_api_rtos.cpp
Have you tried waiting for less than 1ms?
I'm using LPC1768 board.
For wait(5.0) I've got new results, though they are the same as before.
mbed OS 5.5.1 -> elapsed time = 50011300 mbed OS 5.4.7 -> elapsed time = 5001406
Is there anything wrong with my use of "wait"? I wonder we should not use wait function.
posted by Misao Miyata 08 Jul 2017