-->
Page 4 of 6

Re: GPIO sampling speed?

PostPosted: Thu Feb 05, 2015 4:29 pm
by raz123
Fr4gg0r wrote:I did not expect my changes in C to make such a big difference. :D

Maybe you can try this version (should improve speed slightly)? https://github.com/jrahlf/nodemcu-firmw ... master/bin


Result: 64.17 Khz. So about 1 Khz faster than with the conditional branching.

I'm truly curious about how a fully C-sided function would fare? Functions such as:

output_gpio2_1()
output_gpio2_0()

Re: GPIO sampling speed?

PostPosted: Thu Feb 05, 2015 4:31 pm
by Fr4gg0r
I am gonna write you one, wait a sec.
Try this: https://github.com/jrahlf/nodemcu-firmw ... master/bin

Call "gpio.crazy_toggle(your_gpio)".
Should give maximum performance with the espressif API. Maybe it can be further increased by direct register access..
The method might cause a reset, because it does not clear the watchdog periodically.

Edit: I overlooked this link: viewtopic.php?p=1191#p1191 , that is probably faster than this code, using the api.

Can you post values with 80MHz and 160MHz? :D

Code: Select allstatic int crazy_gpio_toggle(lua_State* L){
  unsigned pin;
 
  uint32_t gpio_no = luaL_checkinteger( L, 1 );

  int bit_value = 0x0;
  uint32_t set_mask_0 = bit_value<<gpio_no;
  uint32_t clear_mask_0 = ((~bit_value)&0x01)<<gpio_no;
  uint32_t enable_mask_0 = 1<<gpio_no;
  uint32_t disable_mask_0 = 0;

  bit_value = 0x1;
  uint32_t set_mask_1 = bit_value<<gpio_no;
  uint32_t clear_mask_1 = ((~bit_value)&0x01)<<gpio_no;
  uint32_t enable_mask_1 = 1<<gpio_no;
  uint32_t disable_mask_1 = 0;

  uint32_t i;
  for(i = 10*1000*1000; i >= 0; i--){
    gpio_output_set(set_mask_0, clear_mask_0, enable_mask_0, disable_mask_0);
    gpio_output_set(set_mask_1, clear_mask_1, enable_mask_1, disable_mask_1);
    gpio_output_set(set_mask_0, clear_mask_0, enable_mask_0, disable_mask_0);
    gpio_output_set(set_mask_1, clear_mask_1, enable_mask_1, disable_mask_1);
    gpio_output_set(set_mask_0, clear_mask_0, enable_mask_0, disable_mask_0);
    gpio_output_set(set_mask_1, clear_mask_1, enable_mask_1, disable_mask_1);
    gpio_output_set(set_mask_0, clear_mask_0, enable_mask_0, disable_mask_0);
    gpio_output_set(set_mask_1, clear_mask_1, enable_mask_1, disable_mask_1);
    gpio_output_set(set_mask_0, clear_mask_0, enable_mask_0, disable_mask_0);
    gpio_output_set(set_mask_1, clear_mask_1, enable_mask_1, disable_mask_1);
    gpio_output_set(set_mask_0, clear_mask_0, enable_mask_0, disable_mask_0);
  }
}

Re: GPIO sampling speed?

PostPosted: Thu Feb 05, 2015 4:56 pm
by raz123
Fr4gg0r wrote:I am gonna write you one, wait a sec.
Try this: https://github.com/jrahlf/nodemcu-firmw ... master/bin

Call "gpio.crazy_toggle(your_gpio)".

Should give maximum performance with the espressif API. Maybe it can be further increased by direct register access..
The method might cause a reset, because it does not clear the watchdog periodically.


Results:

CPU @ 80 Mhz: 857.1 Khz
CPU @ 160 Mhz: 1.714 Mhz

Since it's a (really long) loop, the WDT runs out and the module does indeed restart. It's a neat test function. Definitely no real-world usage :)

Re: GPIO sampling speed?

PostPosted: Fri Feb 13, 2015 12:38 pm
by Fr4gg0r
Can you repeat the measurements with the new compile api in lua?