B4R Question Time difference with CalSubPlus instruction

Gerardo Tenreiro

Active Member
Licensed User
Hello again
Continué con el programa que usa comunicación RS-485 y usé la instrucción CallSubPlus para deshabilitar la habilitación de transmisión. parte del codigo es este:
' Activa Transmision.
En_Tx_Encoder.DigitalWrite(True)
' Envia los Datos
PS1.Write(B)
' DesActiva Transmision despues de 3 ms
CallSubPlus("EN_TX1_Off",3,0)
The intention is that 3ms after starting to send information, the RS-485 will switch to reception mode.
The result is variable, normally it deactivates in 2.49ms, other times in 2.51 and other times in any other value.
copia adjunta del analizador

1683288701202.png


The program contains much more code, I could understand that it is delayed but not that it is ahead.
This signal is important since depending on the length of the telegram I have to allocate enough time for all the Bits to be transmitted by RS-485
This is the plane of this communication.
1683288877951.png

Any suggestions or advice on this?
Thank you so much
 

Attachments

  • 1683288361289.png
    1683288361289.png
    51.2 KB · Views: 79

Gerardo Tenreiro

Active Member
Licensed User
For such accuracy you should combine CallSubPlus with DelayMicroseconds. Start with CallSubPlus with 2ms and then measure the actual time and use DelayMicroseconds. It will block other execution but hopefully the CallSubPlus will leave enough cycles for the other tasks.
Thanks Erel for the advice, in this application I have a lot of communications (4 RS-485, 12 SPI, 6 I2C and 1 TFT over SPI) and I'm pushing the ESP32 to the limit so I can't waste time with DELAYs.

My real problem is the repeatability of the CallSubPlus instruction, I don't care if assigning 3ms is 2.5ms or 3.5ms. The important thing is that they are always the same times. The RS-485 EN_TX signal makes the change between reception and transmission, so that if it is transmitting for a short time, some bits stop being sent and if it is active for a long time, the fastest slaves begin to respond without the RS-485 being present. in reception mode.

It would be very interesting to have a CallSubPlus instruction in us instead of ms, so I understand that the precision would be higher even within the same error.

At the moment, adjusting very carefully, I have the 4 RS-485 communications in the serial ports of the ESP32, it is maintaining very high transfer rates with minimum error levels of less than 1% and the error is always due to the control of the transmission line. both ports that value changes.

Aprovecho para deciros que el trabajo realizado en B4R es impresionante y os animo a seguir avanzando, si es posible a un nivel inferior para que podamos tener un control más directo sobre el ESP32.

Thank you so much:D:D:D
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4R maintains a queue of tasks. CallSubPlus adds a scheduled task to the queue. The queue is processed whenever the single thread is free to process the queue. This means that you should expect some inaccuracies and changing the time unit will not really matter.
Combining CallSubPlus with DelayMicroseconds can increase the accuracy.
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
B4R mantiene una cola de tareas. CallSubPlus agrega una tarea programada a la cola. La cola se procesa siempre que el subproceso único está libre para procesar la cola. Esto significa que debe esperar algunas imprecisiones y cambiar la unidad de tiempo realmente no importará.
La combinación de CallSubPlus con DelayMicroseconds puede aumentar la precisión.

Thanks for the pointers, I am modifying all the code so that the operating system manages more free time. I've removed the loops and am trying to run everything by time calls and with value changes through the statements.
' Activa Interrupcion de Cambio de Estado PE_Encoder
PE_Pin_Encoder.AddListener ("G_PE_Encoder")
I am also trying to toggle the operations so that they do not coincide in time, I have to read devices and write them every 10ms, short telegrams from 3 to 6 BYTE, so while one of the serial ports is writing I try to make the other port be at the same time. plug. I am also doing this with CallSubPlus calls. After broadcasting on one port, I launch the deferred call to the other port.



The improvements are important.

Attached Graph of the times obtained over 5ms of activation of EN_TX

1683455331307.png


The time remains very stable at 4.6ms. i hardly varies in time.

The communication improved its quality to 98.3% in a period of one hour with communications every 10ms.

This level is more than enough.

Thank you so much
 
Upvote 0
Top