CubeCell micros() function


Can anyone point me out of how to add micros() function to CubeCell please? (same as micros() function in Arduino library)

there is a ticket on github for that request open:

Just added two examples: micros and millis.

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

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.


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.

Interesting. This could explain why my attempts at serial data timing with the PWM sub system needed some tweaking. My error was closer to 1.1%. Would the 1.7% you mention be fairly consistent, or would it vary from device to device? Also, what is the source of this error? Is the 48mHz derived from a PLL?

The problem is the error is not fairly consistent for each device. So can’t simply correct the error by doing the difference. We are trying to calibrate via RTC clock.

48MHz is the ASR6501’s system frequency, the reason is because of the ASR6501 chips’ hardware problem, it’s didn’t provide a very accurate system clock.

Thanks for the prompt reply.

Please tell me about how to add micros() function for cubecell. I see micros() function in micros.ino but didn’t see micros function library.


micros function read the register of ASR6501 directly, so it don’t have a library.

This does not answer darking2539’s question, I’m afraid.
I have the very same problem: Your example uses a micros() function that is declared nowhere. It should be in Arduino.h as this is the only file that’s included by your program, but obviously it isn’t.
I have freshly installed the latest CubeCell Board package in Arduino IDE 1.8.12 and had stumbled upon the problem when testing out the basic LoRaWAN example that tries to include the Adafruit NeoPixel library.
Any help greatly appreciated. Maybe simply the source code of your micros() (and also millis()) function? Plus, in a future version of the board package, a corrected Arduino.h file :wink:

the micros() function is declared in the ASR_Arduino.h file.

it is better to use the github version, this one is allways newer than the board manager version.

@wasn had provided the right answer, the micros() function declared in the ASR_Arduino.h, and the Arduino.h has called the ASR_Arduino.h.


If you guys using the micros() function just for the one wire RGB LED (WS2812, SK6812, etc.), I’m sure the original Adafruit NeoPixel library will not work!


If you had looked into the Adafruit NeoPixel library, you will find that library had made adjust for different MCUs. For example, in order to achieve timing of several microseconds.

  • For some low speed MCU, the MCU’s system clock (system ticker) can’t provide enough fast time for microseconds, so it use more efficient assemble language.
  • For some fast speed MCU, ESP32 etc, the 240MHz system clock is too fast for microsecond, so it use code (software) simulation a microsecond timer.

CubeCell is much younger than the Adafruit NeoPixel library, that library didn’t add CubeCell support, so I have to modify the basic layer source code, find out a way that can suitable for CubeCell write data to RGB LED via one wire.

Just updated a library for WS2812 RGB cycle, this example will make sense about how to use the CubeCell’s RGB library.

1 Like

So, the solution to successfully run the included examples is to

  1. not install the released board package but instead use the Github version and
  2. uninstall an already existing Adafruit NeoPixel library.

(frankly speaking, I think choosing a different library name for the modified NeoPixel lib would be a better solution for the time being, as switching to other target architectures requires re-installing the original library again.)

Thanks Aaron, I just pulled the latest version and saw that you renamed the NeoPixel library :smiley:

…but somehow I do not manage it to get the micros() example working. The declaration is included, but the linker complains it cannot find the implementation…

(one further problem: the random() functions with one and two arguments usually found in Arduino are not yet implemented. Shall I open an issue?)

Yes, just for now, new release will be generate next week with ASR6502 series release.

I should rename the library earlier, but I was too lazy. :joy:

Of course :grinning: