Precise timing needed (ex. for IR decoding)

zerog2k
Posts: 6
Joined: Mon Mar 02, 2015 2:40 am

Re: Precise timing needed (ex. for IR decoding)

Postby zerog2k » Fri Mar 06, 2015 10:42 pm

Maybe there is a better way to control low level timer through registers, etc, but dont see any good documentation on this yet - I would like to know too ;)

I had to decode a very noisy signal from 433MHz ASK RX module, so I did it with interrupts and capturing/measuring rise/fall time differences in uS with system_get_time in order to decode pulse widths.

I'm still working on it:
https://gist.github.com/zerog2k/00bad44d59bcd7937420

I think my ISR is quite heavy, but it works for the most part. Still tuning it, but I think i would have rather implemented this with a uS resolution timer: use interrupts to wait for sync header, then fire a short interval timer to read known number of signal states at regular interval (in uS), then when signal is done, I know that the next signal will come in 18 seconds - stop interrupts and sleep for 17 seconds before turning on interrupts and watching for next sync header.

raz123
Posts: 13
Joined: Tue Feb 24, 2015 9:14 am

Re: Precise timing needed (ex. for IR decoding)

Postby raz123 » Sat Mar 07, 2015 5:02 am

zerog2k wrote:Maybe there is a better way to control low level timer through registers, etc, but dont see any good documentation on this yet - I would like to know too ;)


You're using the SDK's GPIO_INPUT_GET function which is quite slow. Direct register usage for read/writes is explained here: http://www.esp8266.com/viewtopic.php?f=13&t=273

jcmvbkbc
Posts: 13
Joined: Fri Oct 24, 2014 7:27 pm

Re: Precise timing needed (ex. for IR decoding)

Postby jcmvbkbc » Sat Mar 07, 2015 5:06 am

raz123 wrote:
zerog2k wrote:Maybe there is a better way to control low level timer through registers, etc, but dont see any good documentation on this yet - I would like to know too ;)


You're using the SDK's GPIO_INPUT_GET function which is quite slow. Direct register usage for read/writes is explained here: http://www.esp8266.com/viewtopic.php?f=13&t=273

As a side note, you can have up to twice as fast GPIO control if you specify -mno-serialize-volatile in gcc flags.

raz123
Posts: 13
Joined: Tue Feb 24, 2015 9:14 am

Re: Precise timing needed (ex. for IR decoding)

Postby raz123 » Sat Mar 07, 2015 9:05 am

jcmvbkbc wrote:As a side note, you can have up to twice as fast GPIO control if you specify -mno-serialize-volatile in gcc flags.


Oh? Using what GPIO control method? I tried your recommendation and I'm still doing 6 mhz outputs; no changes.
See: http://imgur.com/FzdnY5X

jcmvbkbc
Posts: 13
Joined: Fri Oct 24, 2014 7:27 pm

Re: Precise timing needed (ex. for IR decoding)

Postby jcmvbkbc » Sat Mar 07, 2015 3:31 pm

raz123 wrote:
jcmvbkbc wrote:As a side note, you can have up to twice as fast GPIO control if you specify -mno-serialize-volatile in gcc flags.


Oh? Using what GPIO control method? I tried your recommendation and I'm still doing 6 mhz outputs; no changes.
See: http://imgur.com/FzdnY5X

Changing GPIO registers directly. Without -mno-serialize-volatile gcc emits memw instruction before each volatile memory write.
Overall gcc may not be very good at optimizing register access, so you should look at the code to see what it does.
You can try the following snippet that makes two GPIO12 pulses:

Code: Select all

asm volatile (
"s32i %0, %1, 4\n\t"
"s32i %0, %1, 8\n\t"
"s32i %0, %1, 4\n\t"
"s32i %0, %1, 8"
: : "r"(0x00001000), "r"(0x60000300) : "memory");

jcmvbkbc
Posts: 13
Joined: Fri Oct 24, 2014 7:27 pm

Re: Precise timing needed (ex. for IR decoding)

Postby jcmvbkbc » Sun Mar 08, 2015 1:45 am

raz123 wrote:
jcmvbkbc wrote:As a side note, you can have up to twice as fast GPIO control if you specify -mno-serialize-volatile in gcc flags.


Oh? Using what GPIO control method? I tried your recommendation and I'm still doing 6 mhz outputs; no changes.
See: http://imgur.com/FzdnY5X

Sorry, brain fart. CPU is obviously fast enough to do two commands in half period time of 110ns, so extra memw's shouldn't matter.

costaud
Posts: 138
Joined: Fri Oct 24, 2014 7:40 pm

Re: Precise timing needed (ex. for IR decoding)

Postby costaud » Wed Mar 11, 2015 2:26 am

piotrva wrote:Dear Espressif,

The os_timer has a resolution of one ms - it is too much for more precise operations, like IR signal (RC5 etc.) decoding.
Is there any way to get an interrupt at 50us resolution or to get a tick count at 50us resolution?

Now I am to design an IR signal repeater (aka universal IR pilot controlled by network) and I do not want to use any extra components (ex. microcnotroller, external timer).

Kind regards
Peter


If you need to get the interval between two gpio interrupt, use the system api system_get_time() to calculate the relative time.(us)
If you want to use a os_timer api to arrange a us timer event, use system_timer_reinit at the beginning of user_init and call os_timer_arm_us .

Who is online

Users browsing this forum: MSN [Bot] and 9 guests