HelTecAutomation / CubeCell-Arduino

Heltec CubeCell Series (based on ASR6501, ASR6502 chip) Arduino support.
247 stars 138 forks source link

micros() function missing in Arduino.h #54

Closed oscaropenness closed 4 years ago

oscaropenness commented 4 years ago

For using ultrasonic sensors, accurate (microsecond) time measurements are necessary. The micros() function seems currently not implemented in the board definition for the ArduinoIDE. Using the implemented millis() function is unfortunately not precise enough.

Can the micros() function be implemented in Arduino.h as well?

heyderpaez commented 4 years ago

I have the same issue. I have not even been able to execute the basic examples for HTCC-AB01 due to the error of the micros () function.

lnlp commented 4 years ago

This appears to be a bug and really should be fixed for compatibility with the basics of the Arduino framework.

OstertagM commented 4 years ago

I have same problem

kkalbaugh commented 4 years ago

Also having the same issue with Lorawan example getting the error in Adafruit_NeoPixel.h and using a dallas DS18B20. I have Adafruit NeoPixel v1.3.5 installed.

In file included from C:\Arduino\hardware\CubeCell\ASR650x-Arduino\libraries\LoRa\src\LoRaWan_APP.cpp:3:0:

C:\Arduino\libraries\Adafruit_NeoPixel/Adafruit_NeoPixel.h: In member function 'boolean Adafruit_NeoPixel::canShow() const':

C:\Arduino\libraries\Adafruit_NeoPixel/Adafruit_NeoPixel.h:234:58: error: 'micros' was not declared in this scope boolean canShow(void) const { return (micros()-endTime) >= 300L; }
Heltec-Aaron-Lee commented 4 years ago

Just added two examples: micros and millis.

micros The micros function uses the internal system ticker (48MHz timer), this timer of ASR6501 is not accurate, as tested, it has 1.7% error. image

The delay in the example is 1000ms, ideally, the output value here should be 1000000.

But look at the printed time stamp, each print have 20 - 22ms error. It means the actual delay(1000); spend 1020 - 1022ms. Because the delay uses internal system ticker too.

So the error is (1020000 - 1002735) / 1020000 ≈ 1.7%

That’s why I didn’t use system ticker for LoRaWAN operations. Another problem is the system ticker can’t run during the deep sleep period, wake up from deep sleep will make the micros back to 0.

millis image

The millis function uses external 32.768KHz RTC clock, it a very accurate timer, and can run during the deep sleep period. As the picture has shown, it’s the same with the delay time.

But the minimum period is 1/32768 ≈ 30us, can’t be the source of micros.

Heltec-Aaron-Lee commented 4 years ago

This problem also talk here: http://community.heltec.cn/t/cubecell-micros-function/985/3