Problem with precision of us timer

clinkme
Posts: 3
Joined: Sun Dec 20, 2015 1:13 am

Problem with precision of us timer

Postby clinkme » Thu Dec 31, 2015 2:03 pm

I've some problems with the precision of the microseconds timer (NON-OS SDK).
I use it for Infrared sender engine. For example, for Panasonic
IR protocol the smallest pulse length should be 432us.
In the real program they differs slightly every time (438, 439, 455us),
but sometimes (and very often) ESP8266 fires the us timer after 707us instead
(checked with logic analyzer).
It is very big difference for the pulse, and the command is not parsed.

I'm executing system_timer_reinit() at the begining of user_init() function.
I also defined USE_US_TIMER. I am using os_timer_arm_us everytime. All timer functions
are in IRAM (no ICACHE_FLASH attribute).
The IR carrier is generated from I2SO_WS source (thus no cpu clocks earned at all),
so that should not affect the program flow.

I agreed that the time of execution of timer callback function is nowhere guaranteed,
but why so big delays?
It seems, that with this anti-precision the us timers are useless in total!!

Here is it:

Code: Select all

+3502 -1748 +445 -445 +438 -1302 +439 -455 +441 -439 +438
-439 +438 -439 +438 -439 +439 -438 +439 -439 +438 -439 +707 -439 ......
                                                       ^^^^^
                                                                                    That is!
+438 -439 +438 -439 +439 -1301 +439 -439 +438 -439 +438 -439 +438 -439 +439
-438 +439 -439 +438 -439 +438 -439 +438 -439 +439 -1301 +439 -439 +438 -439
+438 -439 +438 -439 +439 -438 +708 -438 .............
                             ^^^^^
                               

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: Problem with precision of us timer

Postby ESP_Faye » Mon Jan 04, 2016 4:33 pm

Hi,

os_timer_arm is not precise, it depends on other tasks whose priority is higher.

You can use hardware timer in NMI mode, refer to hw_timer.c.

Please notice that hardware timer can not be used with PWM at the same time.

Thanks for your interest in ESP8266 !

clinkme
Posts: 3
Joined: Sun Dec 20, 2015 1:13 am

Re: Problem with precision of us timer

Postby clinkme » Mon Jan 04, 2016 8:17 pm

Hm, That is first I do - using hardware timer.
Interesting, that hardware timer also works without delays from FRC1_SOURCE (not in NMI mode!).
Why?

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: Problem with precision of us timer

Postby ESP_Faye » Tue Jan 05, 2016 6:15 pm

Hi,

NMI is more precise than FRC1, FRC1 may be effected by WiFi.

Thanks for your interest in ESP8266 !

Who is online

Users browsing this forum: No registered users and 16 guests