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

User avatar
By RichardS
#9021 Have we been able to keep the ESP8266 at 160Mhz constant or does it still fall back to 80Mhz due to some binary blob call?

Richard.
User avatar
By Fr4gg0r
#9081 Wow, 4x times the speed.
Someone should port the interpreter from nodelua. ;)
Can you also check how much free heap there is in nodelua?
User avatar
By raz123
#9094
admin wrote:Have we been able to keep the ESP8266 at 160Mhz constant or does it still fall back to 80Mhz due to some binary blob call? Richard.


Not sure. I have tried WiFi listing and it remained at 160 Mhz.

Fr4gg0r wrote:Wow, 4x times the speed.
Someone should port the interpreter from nodelua. ;)
Can you also check how much free heap there is in nodelua?


After some more investigation, the speed increase seen in nodelua might have had to do with the way it handles variables.
In this thread, dvv recommended using local variables. Here is the code that he suggested testing:

Code: Select alldo
  local mode, write, OUTPUT = gpio.mode, gpio.write, gpio.OUTPUT
  mode(2, OUTPUT)
  for i = 1,10 do
    write(2, 1)
    write(2, 0)
  end
end


Doing so gave the following results (CPU @ 80 Mhz in all cases):

~52 kHz on the nodelua 20150120 firmware (gpio pin = 4)
~51 kHz on the nodemcu 20150127 firmware (gpio pin = 4)
~63 kHz on the jrahlf 20150127 fork (gpio pin = 2)
User avatar
By Fr4gg0r
#9096 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
I removed the conditional branching for the gpio level check and also when you pass an invalid gpio number, it will not print a failure but just do nothing (still safe though).

Some notes on nodelua's code:
-It does not check the level value -> if you pass anything greater than 1 it might set other gpios or even crazy things may happen.
-It does not support gpio16, and therefore can omit 1 additional runtime check.

Code: Select allstatic int lgpio_write( lua_State* L )
{
  unsigned level;
  unsigned pin;
 
  pin = luaL_checkinteger( L, 1 );
  //MOD_CHECK_ID( gpio, pin );
  level = luaL_checkinteger( L, 2 );
  level = level & 0x1; //remove conditional branching
  //if ( level!=HIGH && level!=LOW )
  //  return luaL_error( L, "wrong arg type" );
  int success = platform_gpio_write(pin, level);
  //CHECK_GPIO_SUCCESS(pin, success);
  return 0; 
}