ESP8266 Developer Zone The Official ESP8266 Forum 2015-03-11T02:26:06+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=200 2015-03-11T02:26:06+08:00 2015-03-11T02:26:06+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=987#p987 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
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 .

Statistics: Posted by costaud — Wed Mar 11, 2015 2:26 am


]]>
2015-03-08T01:45:36+08:00 2015-03-08T01:45:36+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=960#p960 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
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.

Statistics: Posted by jcmvbkbc — Sun Mar 08, 2015 1:45 am


]]>
2015-03-07T15:31:59+08:00 2015-03-07T15:31:59+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=956#p956 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
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:

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");

Statistics: Posted by jcmvbkbc — Sat Mar 07, 2015 3:31 pm


]]>
2015-03-07T09:05:11+08:00 2015-03-07T09:05:11+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=954#p954 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
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

Statistics: Posted by raz123 — Sat Mar 07, 2015 9:05 am


]]>
2015-03-07T05:06:27+08:00 2015-03-07T05:06:27+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=951#p951 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
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.

Statistics: Posted by jcmvbkbc — Sat Mar 07, 2015 5:06 am


]]>
2015-03-07T05:02:21+08:00 2015-03-07T05:02:21+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=950#p950 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
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

Statistics: Posted by raz123 — Sat Mar 07, 2015 5:02 am


]]>
2015-03-06T22:42:13+08:00 2015-03-06T22:42:13+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=945#p945 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>

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.

Statistics: Posted by zerog2k — Fri Mar 06, 2015 10:42 pm


]]>
2015-03-06T03:43:24+08:00 2015-03-06T03:43:24+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=933#p933 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
jcmvbkbc wrote:
rudi wrote:@jcmvbkbc
do you know how much / when overflow ( register bit ) can read , too?
have me a interupt for this?
can we trigger this?


I'm not sure what you're asking, my guess is the questions are

- how long is CCOUNT SR? -- it's 32 bits



ok, i take %lu for this 32bit value

jcmvbkbc wrote:
- is overflow of CCOUNT detectable? -- no, there's nothing that can tell you about an overflow. No interrupt, no overflow bit.


ok, i understand

jcmvbkbc wrote:
- is there an interrupt for CCOUNT? Yes, there is a number of CCOMPARE SRs. You can write a value there and then an IRQ will be raised once CCOUNT reaches that value.


this is the point, txs,
then thinked right,
i helped me with primitive counter and compare the ticks time to time
i have try to make a interupt to a variable , if change , then trigger
i was not sure, is there an interupt or other

thank you!

jcmvbkbc wrote:
For more details please see xtensa ISA book (e.g. http://0x04.net/~mwk/doc/xtensa.pdf ), 4.4.6 Timer interrupt option.


ok - yes know from the book - will study the point again and try to go on over CCOMPARE SRs and IRQ's
thank you jcmvbkbc!

btw,
if you have an example for CCOMPARE SRs and IRQ's like you think how to do this will helpfull.
i will try too - will update here if i have a functionally work

Best wishes!
rudi ;-)

btw

i test, because was searching a trigger, counter, overflow...
with this as primitive code
and note all values in a shema


Code:


..
t1 = system_get_time();     // API get time
// start
tick1 = get_ccount();       // Spezial Register CCOUNT get and save
while (mtick < 10 )
{
asm ("nop");
mtick++;
}

t2 = system_get_time();     // API get time
tickdiff = tick2 - tick1;   // How much Ticks used
..
..




and my shema was
"loops" x 2 x 2 = value + while "loops - 1 " = ticks

so i test..

while (mtick < 30 )
30 x 2 x 2 = 120 + while 30 - 1 = 149
Bingo! calculated was right..

40 x 2 x 2 = 160 + while 40 - 1 = 199
Bingo!

50 x 2 x 2 = 200 + while 50 - 1 = 249
Bingo!

60 x 2 x 2 = 240 + while 60 - 1 = 299
Bingo!

70 x 2 x 2 = 280 + while 70 - 1 = 349
Bingo!

80 x 2 x 2 = 320 + while 80 - 1 = 399
Bingo!

90 x 2 x 2 = 360 + while 90 - 1 = 449
Bingo!



100 x 2 x 2 = 400 + while 100 - 1 = 499

UPS! calculated was 499 but ticks was 598

so i have think, have we a overrun / trigger ?

so i make step by step

in ( ) this is the calculated soll

91 = 454 ticks (91*2*2+while 91-1=454)
92 = 459 ticks (92*2*2+while 92-1=459)
93 = 464 ticks (93*2*2+while 93-1=464)
94 = 469 ticks (94*2*2+while 94-1=469)
95 = 474 ticks (95*2*2+while 95-1=474)

~~~~~~~~~~~~~~~ ok ~~~~~~~~~~~~~
then..

96 = 574 ticks (96*2*2+while 96-1=479)
97 = 580 ticks (97*2*2+while 97-1=484)
98 = 586 ticks (98*2*2+while 98-1=489)
99 = 592 ticks (99*2*2+while 99-1=494)
100 = 598 ticks (100*2*2+while 100-1=499)

in this case allways 6 ticks more like value before
in paste time, allways 5 ticks more.

between 95 and 96 loops there is a swap / more ticks

96*2*2+while 96-1 + 100-1

a overflow from 100 ticks and a difference from 6 ticks

so i test again:

will it be difference if test will be 95 + 96 = 191 loops?
test

190 = 1138 ticks (190*2*2+while 190-1 + 190 - 1 = 1038 )
195 = 1168 ticks (195*2*2+while 195-1 + 195 - 1 = 1168 )
200 = 1198 ticks (200*2*2+while 200-1 + 200 - 1 = 1198 )
..
1200 ....= 7198 ( = 7198 )

no all ok, but why is a difference betwenn
95 and 96

while.. true ticks ,,,,,,,,,,,,,,,calculated ticks
95 = 474 ticks (95*2*2+while 95-1=474)
96 = 574 ticks (96*2*2+while 96-1=479)

i have think - then perhabs a possible way for a register bit

sorry for many text :)
i test many things / think's
:)

Statistics: Posted by rudi — Fri Mar 06, 2015 3:43 am


]]>
2015-03-06T00:58:30+08:00 2015-03-06T00:58:30+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=932#p932 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
rudi wrote:
@jcmvbkbc
do you know how much / when overflow ( register bit ) can read , too?
have me a interupt for this?
can we trigger this?

I'm not sure what you're asking, my guess is the questions are
- how long is CCOUNT SR? -- it's 32 bits
- is overflow of CCOUNT detectable? -- no, there's nothing that can tell you about an overflow. No interrupt, no overflow bit.
- is there an interrupt for CCOUNT? Yes, there is a number of CCOMPARE SRs. You can write a value there and then an IRQ will be raised once CCOUNT reaches that value.

For more details please see xtensa ISA book (e.g. http://0x04.net/~mwk/doc/xtensa.pdf ), 4.4.6 Timer interrupt option.

Statistics: Posted by jcmvbkbc — Fri Mar 06, 2015 12:58 am


]]>
2015-03-05T22:42:26+08:00 2015-03-05T22:42:26+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=931#p931 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
jcmvbkbc wrote:
piotrva wrote:Is there any way to get an interrupt at 50us resolution or to get a tick count at 50us resolution?

You can read CCOUNT special register. It increments every clock tick, i.e. every 12.5ns with 80MHz clock.
You can read it with the following function:

Code:

static inline unsigned get_ccount(void)
{
        unsigned r;
        asm volatile ("rsr %0, ccount" : "=r"(r));
        return r;
}


yes, played last time with this,
http://www.mikrocontroller.net/topic/358654#new

@jcmvbkbc
do you know how much / when overflow ( register bit ) can read , too?
have me a interupt for this?
can we trigger this?
:)



Code:


..
static inline unsigned get_ccount(void);
..



static inline unsigned get_ccount(void)
{
        unsigned r;
        asm volatile ("rsr %0, ccount" : "=r"(r));
        return r;
}



void user_init(void)

{

while(1)

{

char ticks1 [32];
char ticks2 [32];

unsigned tick1;
unsigned tick2;
unsigned tickdiff;


tick1 = get_ccount();       // Spezial Register CCOUNT call and save
tick2 = get_ccount();       // Spezial Register CCOUNT call and save
tickdiff = tick2 - tick1;   // how much ticks was used

// 1. Register CCOUNT formated transfer to Variable
os_sprintf(ticks1, "%lu", tick1);
// 2. Register CCOUNT formated transfer to Variable + Diff Value
os_sprintf(ticks2, "%lu %lu", tick2, tickdiff);


// ich hab neben dem OLED am SPI auch ein MCP23S17 über SPI am ESP8266
// und betreibe ein einfaches 16 Zeichen x 2 Display daran
// daher ganz simple LCD Ausgabe anstatt Uart

// i have used a MCP23S17 ( SPI Portexpander ) with ESP8266 and use a 8bit LCD for Display
// LCD output for ticks, uart0 for Debug prints
//

lcdCmd(clearDisplay);       // LCD Command Clear Display
lcdGoto(0);                 // LCD Command Go Postion 0
lcdWriteString(ticks1);     // LCD Print Register CCOUNT Total Ticks
lcdGoto(0x40);              // LCD Command Go Postion 0x40 (second row)
lcdWriteString(ticks2);     // LCD Print Register CCOUNT total Ticks

os_delay_us(10 *1000*1000); // Pause : for me to read value at LCD

lcdCmd(ClearDisplay);       // LCD Command Clear Display


} // while
} // user_init








little playing how good optimize compiler..

Code:


..
tick1 = get_ccount();       // Spezial Register CCOUNT Abruf und Übertrag
os_delay_us(1);
tick2 = get_ccount();       // Spezial Register CCOUNT Abruf und Übertrag
tickdiff = tick2 - tick1;   // Wieviel Ticks verbraucht
..

// tickdiff 122




..

Code:



..

tick1 = get_ccount();       // Spezial Register CCOUNT Abruf und Übertrag
os_delay_us(2);
tick2 = get_ccount();       // Spezial Register CCOUNT Abruf und Übertrag
tickdiff = tick2 - tick1;   // Wieviel Ticks verbraucht

..

//tickdiff 194





makes fun

Code:


..

tick1 = get_ccount();       // Spezial Register CCOUNT Abruf und Übertrag
os_delay_us(1);
os_delay_us(1);
tick2 = get_ccount();       // Spezial Register CCOUNT Abruf und Übertrag
tickdiff = tick2 - tick1;   // Wieviel Ticks verbraucht

..

// tickdiff 243





1 Mikrosekunden [µs] = 1 000 Nanosekunden [ns]
http://www.einheiten-umrechnen.de/einheiten-rechne...

test 1
one delay 1µs between = 122 ticks
122 ticks zu je 12.5 ns = 1525 µs

./. + 525 µs


test 2
one delay 2µs between = 194 ticks
144 ticks zu je 12.5 ns = 1800 µs

./. - 200 µs


test 3
2 delays with each delay 1µs between = 243 ticks
243 ticks zu je 12.5 ns = 3037,5 µs


./. + 1037.5 µs



more tests:
http://www.mikrocontroller.net/topic/358654#4014599


best wishes
;-)
_1_praezisestimingccount_controll_system_get_time.jpg

_1_praezisestimingccount_controll_system_get_time_ASM.jpg

Statistics: Posted by rudi — Thu Mar 05, 2015 10:42 pm


]]>
2015-03-05T17:15:10+08:00 2015-03-05T17:15:10+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=928#p928 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]> Statistics: Posted by delong_z — Thu Mar 05, 2015 5:15 pm


]]>
2015-02-15T22:18:07+08:00 2015-02-15T22:18:07+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=743#p743 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]> EDIT:
Finally I decided to use STM32F05x as a IR controller - the ESP's PWM cannot achieve 26/38/40kHz and as I do not want to do it with os_delay_us() i will use STM32 as a slave SPI.

Maybe in next SDK's release there will be an option to generate interrupts at us resolution.

Statistics: Posted by piotrva — Sun Feb 15, 2015 10:18 pm


]]>
2015-02-15T18:35:03+08:00 2015-02-15T18:35:03+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=737#p737 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>

Code:

#ifdef USE_US_TIMER
#define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0)
#endif
#define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1)

Will test it.

Statistics: Posted by piotrva — Sun Feb 15, 2015 6:35 pm


]]>
2015-02-15T11:43:48+08:00 2015-02-15T11:43:48+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=732#p732 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
piotrva wrote:
Thank you for the answer - it can be a kind of workaround - of course faster timer interrupt would be better, but maybe I will manage to capture IR data using this data & GPIO interrupt & timer interrupt as idle guard.


uint32 system_get_time(void); CAN provide a relative time count in us. Use it to get the expire between two gpio interrupt .

Statistics: Posted by costaud — Sun Feb 15, 2015 11:43 am


]]>
2015-02-14T23:40:43+08:00 2015-02-14T23:40:43+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=726#p726 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]> Statistics: Posted by piotrva — Sat Feb 14, 2015 11:40 pm


]]>
2015-02-14T20:48:49+08:00 2015-02-14T20:48:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=724#p724 <![CDATA[Re: Precise timing needed (ex. for IR decoding)]]>
piotrva wrote:
Is there any way to get an interrupt at 50us resolution or to get a tick count at 50us resolution?

You can read CCOUNT special register. It increments every clock tick, i.e. every 12.5ns with 80MHz clock.
You can read it with the following function:

Code:

static inline unsigned get_ccount(void)
{
        unsigned r;
        asm volatile ("rsr %0, ccount" : "=r"(r));
        return r;
}

Statistics: Posted by jcmvbkbc — Sat Feb 14, 2015 8:48 pm


]]>
2015-02-14T06:52:29+08:00 2015-02-14T06:52:29+08:00 https://bbs.espressif.com:443/viewtopic.php?t=200&p=721#p721 <![CDATA[Precise timing needed (ex. for IR decoding)]]>
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

Statistics: Posted by piotrva — Sat Feb 14, 2015 6:52 am


]]>