As the title says... Chat on...

User avatar
By raz123
#9099
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()
User avatar
By Fr4gg0r
#9100 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);
  }
}
User avatar
By raz123
#9105
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 :)