Multitasking ?

Code tips and tricks for beginners
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Multitasking ?

Post by cicciocb »

Thanks for the advices, I'll try to improve in the future
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Multitasking ?

Post by cicciocb »

I'm doing some testing with the DS18B20
The goal is to improve the command without breaking the existing syntax.
Initially I planned to introduce a new command but I think I found a good compromise.

This should be the final syntax

Code: [Local Link Removed for Guests]

ret$ = TEMPR$(pin, [id], [resolution])
The function continue to work as before (as documented in the help file)

Additionally, the parameter "resolution' can be provided (from 9 to 12 bits).
The resolution determine the minimal increment of temperature and also the conversion time (see table below)
image.png
if the resolution is ignored, it default to 12 as before.

The novelty is now the async mode :
Giving 0 as ID, starts the conversion on all the DS18B20 sensors connected without waiting for the answer

For example

Code: [Local Link Removed for Guests]

ret$ = TEMPR$(2, 0) ' starts an async read on the pin 2
The result will be the string "START"

Then, it will be possible to read the devices as below

Code: [Local Link Removed for Guests]

ret1$ = TEMPR$(2, 1) 'read the 1st sensor on the pin 2
ret2$ = TEMPR$(2, 2) 'read the 2nd sensor on the pin 2
In this case, if the value is not yet available (during the conversion time) the result will be "WAIT' that will be replaced by the good value at the end of the conversion.

To restart another conversion, the same command must be executed

Code: [Local Link Removed for Guests]

ret$ = TEMPR$(2, 0) ' starts an async read on the pin 2
What do think ?
Comments ?
You do not have the required permissions to view the files attached to this post.
rmsta
Posts: 32
Joined: Sat Feb 20, 2021 9:36 am
Location: Sindelfingen, Germany
Has thanked: 132 times
Been thanked: 9 times

Re: Multitasking ?

Post by rmsta »

Really good proposal for time critical applications and easy to understand !
I think for many projects (also mine) the paramter "resolution" will be most beneficial.
Hopefully it will be available soon :-)
Rainer
MarioL
Posts: 20
Joined: Sun Mar 21, 2021 8:38 am
Has thanked: 249 times
Been thanked: 33 times

Re: Multitasking ?

Post by MarioL »

Hi,
if i understand correctly in async mode and with the following code
no waiting time for conversion, no lost time.
(all sensors convert simultaneously, 750ms required, ESP is free)
It's very cool and suitable if many sensors are employed and hight resolution is needed

Se ho capito bene, in modalità asincrona e col seguente codice non c'e da attendere il tempo di conversione, quindi non c'e tempo perso.
(tutti i sensori convertono contemporaneamente nei 750ms e l'ESP è libero di effettuare altre operazioni)
Questo è il massimo se si impiegano molti sensori ed è richiesta la risoluzione a 12 bit.

Code: [Local Link Removed for Guests]

code:

ret$ = TEMPR$(2, 0) ' starts of async conversion  on the pin 2 for first read

gosub lbl_draw_page
onHtmlReload draw_page
'other code lines
timer0 1000, lbl_read_temp  
wait

lbl_read_temp:
 ret1$ = TEMPR$(2, 1) 'read the 1st sensor on the pin 2
 ret2$ = TEMPR$(2, 2) 'read the 2nd sensor on the pin 2
 ret1$ = TEMPR$(2, 3) 'read the 3st sensor on the pin 2
 ret2$ = TEMPR$(2, 4) 'read the 4nd sensor on the pin 2
 ret$ = TEMPR$(2, 0) ' starts an async conversion  on the pin 2 for next read
return
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Multitasking ?

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Jan 23, 2023 9:25 pm Hi,
if i understand correctly in async mode and with the following code
no waiting time for conversion, no lost time.
(all sensors convert simultaneously, 750ms required, ESP is free)
It's very cool and suitable if many sensors are employed and hight resolution is needed

Se ho capito bene, in modalità asincrona e col seguente codice non c'e da attendere il tempo di conversione, quindi non c'e tempo perso.
(tutti i sensori convertono contemporaneamente nei 750ms e l'ESP è libero di effettuare altre operazioni)
Questo è il massimo se si impiegano molti sensori ed è richiesta la risoluzione a 12 bit.

Code: [Local Link Removed for Guests]

code:

ret$ = TEMPR$(2, 0) ' starts of async conversion  on the pin 2 for first read

gosub lbl_draw_page
onHtmlReload draw_page
'other code lines
timer0 1000, lbl_read_temp  
wait

lbl_read_temp:
 ret1$ = TEMPR$(2, 1) 'read the 1st sensor on the pin 2
 ret2$ = TEMPR$(2, 2) 'read the 2nd sensor on the pin 2
 ret1$ = TEMPR$(2, 3) 'read the 3st sensor on the pin 2
 ret2$ = TEMPR$(2, 4) 'read the 4nd sensor on the pin 2
 ret$ = TEMPR$(2, 0) ' starts an async conversion  on the pin 2 for next read
return
Yes, what you say is correct, I just need to test with several devices at the same time
BeanieBots
Posts: 315
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 168 times
Been thanked: 102 times

Re: Multitasking ?

Post by BeanieBots »

Looks like a good compromise between full one-wire functionality and ease of use.
Just to be clear, does TEMPR$(2,0) start the conversion on ALL DS18B20's connected to GPIO.2 and is it normal(3-wire) powered mode or parasitic(2-wire) mode?
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Multitasking ?

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Jan 24, 2023 9:30 am Looks like a good compromise between full one-wire functionality and ease of use.
Just to be clear, does TEMPR$(2,0) start the conversion on ALL DS18B20's connected to GPIO.2 and is it normal(3-wire) powered mode or parasitic(2-wire) mode?
I need to continue the testing (I tested with only one DS12B20 so far) but the conversion should start on all the devices at the same time.
So far I tested only in normal mode but it should work also in parasitic mode
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Multitasking ?

Post by cicciocb »

I can confirm that it works as expected (I tested on an ESP32-S3).
Will be in the next release
BeanieBots
Posts: 315
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 168 times
Been thanked: 102 times

Re: Multitasking ?

Post by BeanieBots »

Any chance we might see it for 8266 as well?
User avatar
cicciocb
Site Admin
Posts: 1889
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 405 times
Been thanked: 1260 times
Contact:

Re: Multitasking ?

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Jan 27, 2023 5:30 pm Any chance we might see it for 8266 as well?
I'll try to include the changes also in the ESP8266
Post Reply