ESP32 16bit variable count, unifying output port bits

For general Flowcode discussion that does not belong in the other sections.
Post Reply
miggarc
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

Post by miggarc »

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

ESP32 Unifying non contiguous port bits for output 16bit data (two 8 bit ports)_ _.jpg
ESP32 Unifying non contiguous port bits for output 16bit data (two 8 bit ports)_ _.jpg (26.05 KiB) Viewed 3300 times


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
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

BenR
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

Post by BenR »

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.
Convert.jpg
Convert.jpg (36.9 KiB) Viewed 3320 times

Using an output icon we mask off the bits we want to control using our 32-bit variable.
Output.jpg
Output.jpg (36.21 KiB) Viewed 3321 times

Here's a project with a macro to take the 16-bit value and output to the port so you can reuse as required.
Convert16-bit to 32-bit port.fcfx
(8.44 KiB) Downloaded 190 times

miggarc
Posts: 52
Joined: Mon Jan 04, 2021 8:08 pm
Has thanked: 7 times
Been thanked: 4 times

Re: ESP32 16bit variable count, unifying output port bits

Post by miggarc »

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

Many thanks in advance,


Miguel Garcia,
Electronic Systems Developer

miggarc
Posts: 52
Joined: Mon Jan 04, 2021 8:08 pm
Has thanked: 7 times
Been thanked: 4 times

Re: ESP32 16bit variable count, unifying output port bits

Post by miggarc »

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:
ESP32 Unifying non contiguous.fcfx
(33.6 KiB) Downloaded 199 times

Next is the Flowcode target compilation message:
ESP32 Unifying non contiguous.msg.txt
(15.34 KiB) Downloaded 182 times

If more files are needed please inform me.

Lots of thanks in advance,

Miguel

Many thanks in advance,


Miguel Garcia,
Electronic Systems Developer

BenR
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

Post by BenR »

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.

Code: Select all

TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;
You will also need to go into the Project Options -> Supplementary Code and add this line to the definitions.

Code: Select all

#include "soc/rtc_wdt.h"

miggarc
Posts: 52
Joined: Mon Jan 04, 2021 8:08 pm
Has thanked: 7 times
Been thanked: 4 times

Re: ESP32 16bit variable count, unifying output port bits

Post by miggarc »

Thanks for your intervention.

The problem is exactly what you're saying .

Many thanks in advance,


Miguel Garcia,
Electronic Systems Developer

Post Reply