-->
Page 1 of 2

HOWTO: use NeoPixel library at 160MHz

PostPosted: Fri Sep 11, 2015 3:21 am
by SteveSpencer
While experimenting with a NeoPixel strip, I discovered that the library appears not to work if you target 160MHz rather than the stock 80MHz. After a little digging, I discovered that providing I didn't call show in the setup function, it worked thereafter.

Digging around in the core code, rather than the library, I realised that code in setup runs at 80MHz, while code in loop runs at the faster speed.

Rather than modify the core to change this, I added the following into my setup function:
Code: Select all#if defined(ESP8266)
extern void preloop_update_frequency();
#endif
void setup()
{
#if defined(ESP8266)
     preloop_update_frequency();
#endif

// rest of code as usual.

}


This resolves the issue. What was happening was that the setup code was calling 'show' and stretching the pulses it sent by a factor of two, which I saw as turning the 0 bits into 1 bits.

A more appropriate fix might be to change core_esp8266_main.cpp from:

Code: Select allstatic void loop_wrapper() {
    static bool setup_done = false;
    if(!setup_done) {
        setup();
        setup_done = true;
    }
    preloop_update_frequency();
    loop();
    esp_schedule();
}


to

Code: Select allstatic void loop_wrapper() {
    static bool setup_done = false;
    preloop_update_frequency();
    if(!setup_done) {
        setup();
        setup_done = true;
    }
    loop();
    esp_schedule();
}


I confess, however, I do not know whether this might adversely affect other timer/frequency based stuff.

Re: HOWTO: use NeoPixel library at 160MHz

PostPosted: Thu Sep 17, 2015 3:59 pm
by freedom2000
Hi,

Please could you explain where this function is declared : preloop_update_frequency

and how to use it ?

I understand that it allows to increase the CPU freq to 160 MHz but how ?

Thanks
JP

Re: HOWTO: use NeoPixel library at 160MHz

PostPosted: Wed Sep 30, 2015 9:50 am
by SteveSpencer
Hi JP

The function is part of the Arduino core for ESP8266.
When you compile a sketch (to keep the Arduino terminology), one of the things you can specify is the CPU speed, either 80MHz or 160MHz. Since a number of other things can cause the CPU clock to be dropped back to 80MHz (apparently), this function is used internally wrapping around your loop function to ensure that the CPU is running faster if that's what you wanted.

Hope that helps.

Steve

Re: HOWTO: use NeoPixel library at 160MHz

PostPosted: Wed Sep 30, 2015 2:23 pm
by freedom2000
Thank you Steve

It's clear now
JP