Hello,
I'm developing an ESP32 based DAC/driver for laser projectors. I'm getting pretty good performance in the main loop that runs via an interrupt (up to 70kHz). I'm also using direct register writes (instead of digitalWrite) to send data to the DACs.
But there are several user-settable variables that could change at any time (X/Y invert, scan speed, brightness, offsets, etc). Right now, I'm storing those in an NVRAM struct using Preferences (since I want the user-selected values to persist between sessions).
But is there a performance penalty in retrieving these NVRAM values to use when rendering the data in the main loop? Is there a better way to load these settings in spare register locations (they are mostly uint8/16/32) to cut down on the time to retrieve these values from NVRAM? Or is there essentially little or no difference?
Thank you.
Are any registers available for faster user variables?
-
- Posts: 7
- Joined: Tue May 10, 2022 2:58 pm
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Are any registers available for faster user variables?
If anything, it saves you a function call if you cache those variables locally.
-
- Posts: 7
- Joined: Tue May 10, 2022 2:58 pm
Re: Are any registers available for faster user variables?
Thanks. Perhaps some code examples below will help explain (I should have included this first).ESP_Sprite wrote: ↑Wed May 11, 2022 1:29 amIf anything, it saves you a function call if you cache those variables locally.
I'm creating a struct in memory and then calling GetPrefs() to populate that struct from NVRAM. I call this function once at system setup.
I'm then using prefs.current_settings.size, prefs.current_settings.invertX, prefs.current_settings.invertY, etc in the main loop.
It's these struct vars I'm wondering if there's a performance hit by doing it that way, or is there a faster way to access these variables?
Thanks.
- struct projector_settings_t {
- char state;
- float bright;
- uint8_t pattern,blanking,size;
- int16_t yoffset,xoffset;
- uint32_t target_scan_rate;
- boolean flipXY,invertX,invertY,optimize,initalized=false;
- };
- struct preferences_t {
- boolean flipOLED=true,StartWifi=false,StartBLE=true,StartSDCard=true;
- uint8_t frame_delay=0;
- projector_settings_t current_settings;
- projector_settings_t saved_settings;
- };
- preferences_t prefs;
- void GetPrefs() {
- preferences.begin("settings", false);
- preferences.getBytes("prefs", &prefs, sizeof(prefs));
- preferences.end();
- }
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Are any registers available for faster user variables?
No, this is pretty much optimal. This way, the data is stored in internal memory which runs at the CPU clock.
-
- Posts: 7
- Joined: Tue May 10, 2022 2:58 pm
Re: Are any registers available for faster user variables?
Great, thank you!ESP_Sprite wrote: ↑Thu May 12, 2022 1:36 amNo, this is pretty much optimal. This way, the data is stored in internal memory which runs at the CPU clock.
Who is online
Users browsing this forum: No registered users and 61 guests