Hi
I'mm working with ESP32 DEVKIT.
I will need to count up on a 16 bit variable ( Uint ), lets suppose variable V, and output its contents to portA of ESP32 .
As its bits (numbering) aren't all contiguous ones,
I was thinking to:
output
the Less Significant Byte of variable V ( V0 V1 V2 V3 V4 V5 V6 V7 )
to ( D1 D2 D3 D4 D5 D21 D22 D23 ) respectively .
and output
Most Significant Byte of variable variable V ( V8 V9 V10 V11 V12 V13 V14 V15 )
to ( D12 D13 D14 D15 D16 D17 D18 D19 ) respectively .
like this
I can preview this may imply perhaps some shifting and calculations and probably isolating the LSB and MSB of variable V ,
but I have not a clear view on how to implement it .
Question is :
Can someone put some light here, by giving here some ideas / tips on how to achieve this.
NOTES:
Variable V will be incremented at a speed as high as the
ESP32/flowcode permits so, it should be available on ESP12 above
mentioned bits, as soon as possible...
Writing to the PORT should be done without changing any other existing bits, besides the mentioned ones.
lots of thanks in advance,
Miguel
ESP32 16bit variable count, unifying output port bits
-
- Posts: 52
- http://meble-kuchenne.info.pl
- Joined: Mon Jan 04, 2021 8:08 pm
- Has thanked: 7 times
- Been thanked: 4 times
ESP32 16bit variable count, unifying output port bits
Last edited by miggarc on Fri Sep 10, 2021 1:53 pm, edited 2 times in total.
Many thanks in advance,
Miguel Garcia,
Electronic Systems Developer
-
- Matrix Staff
- Posts: 1895
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 491 times
- Been thanked: 664 times
Re: ESP32 16bit variable count, unifying output port bits
Hello Miguel,
You probably want the output bits to all come on at the same time so we will first do all the rearrangement of the bits before outputting to the port.
First we get the bits from the 16-bit variable and rearrange them into the right place in a 32-bit variable.
Using an output icon we mask off the bits we want to control using our 32-bit variable.
Here's a project with a macro to take the 16-bit value and output to the port so you can reuse as required.
You probably want the output bits to all come on at the same time so we will first do all the rearrangement of the bits before outputting to the port.
First we get the bits from the 16-bit variable and rearrange them into the right place in a 32-bit variable.
Using an output icon we mask off the bits we want to control using our 32-bit variable.
Here's a project with a macro to take the 16-bit value and output to the port so you can reuse as required.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: ESP32 16bit variable count, unifying output port bits
Hi BenR
Really lots of thanks.
Now I've got a clear idea and the principle behind this kind of bit manipulation...
I'll analyze in detail your answer so I can apply it to any other cases in the future.
I'll try it today evening .
Miguel
Really lots of thanks.
Now I've got a clear idea and the principle behind this kind of bit manipulation...
I'll analyze in detail your answer so I can apply it to any other cases in the future.
I'll try it today evening .
Miguel
Many thanks in advance,
Miguel Garcia,
Electronic Systems Developer
Re: ESP32 16bit variable count, unifying output port bits
Hi BenR (or any other one that could help me).
The help about the macro you gave me above helped a lot.
Problem is:
It works absolutely fine in simulation but, although it compiles to target (ESP32 DEVKIT) with no errors (only warnings),
in real life it does not run (no leds, "no nothing"...) .
And... Yes... Target ( ESP32DEVKIT ) works with other flowcode flowcharts.
I attached the flowcode file here:
Next is the Flowcode target compilation message:
If more files are needed please inform me.
Lots of thanks in advance,
Miguel
The help about the macro you gave me above helped a lot.
Problem is:
It works absolutely fine in simulation but, although it compiles to target (ESP32 DEVKIT) with no errors (only warnings),
in real life it does not run (no leds, "no nothing"...) .
And... Yes... Target ( ESP32DEVKIT ) works with other flowcode flowcharts.
I attached the flowcode file here:
Next is the Flowcode target compilation message:
If more files are needed please inform me.
Lots of thanks in advance,
Miguel
Many thanks in advance,
Miguel Garcia,
Electronic Systems Developer
-
- Matrix Staff
- Posts: 1895
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 491 times
- Been thanked: 664 times
Re: ESP32 16bit variable count, unifying output port bits
Hi Miguel,
Thanks for letting us know, investigating for you now.
edit. The problem seems to be to do with your initial writes to PortA, you've not enabled the masking and so all the PortA pins are written to including the pins that work with the device flash memory and this is causing the program not to run correctly.
Removing these initial PortA writes and the program is now running correctly.
Please note that as you are using a tight loop with no delays the ESP32 watchdog is kicking in and potentially causing a reset. To avoid the reset simply add this line of C code into your loop to keep the watchdog timer happy.
You will also need to go into the Project Options -> Supplementary Code and add this line to the definitions.
Thanks for letting us know, investigating for you now.
edit. The problem seems to be to do with your initial writes to PortA, you've not enabled the masking and so all the PortA pins are written to including the pins that work with the device flash memory and this is causing the program not to run correctly.
Removing these initial PortA writes and the program is now running correctly.
Please note that as you are using a tight loop with no delays the ESP32 watchdog is kicking in and potentially causing a reset. To avoid the reset simply add this line of C code into your loop to keep the watchdog timer happy.
Code: Select all
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;
Code: Select all
#include "soc/rtc_wdt.h"
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel