Page 1 of 1

delay function problem

Posted: Sun Apr 30, 2017 2:20 pm
by howard123
Hello all

Not sure if this should be in the bug report but I am having strange behaviour when using the delay function in conjunction with a UART.

As you can see from the flowcode image a 4mS delay is placed between UART sends but on the logic analyser image, measuring target hardware, it is actually 2mS. This is with a baud rate of 9600. Changing the baud rate to a higher speed makes the delay longer and it gets close to 4mS at 115200.

My clock is defined correctly at 16MHz.

Many thanks
Howard

FC 7.2.0.5
PIC18F46K22
flowcode.JPG
flowcode.JPG (51.32 KiB) Viewed 4968 times

Re: delay function problem

Posted: Mon May 01, 2017 3:09 pm
by Bachman
The flowchart command sends the charaters to a buffer (SW, HW, both?) then waits 4 ms, the main process does not wait for the UART module to finish the job. This is why you see more pause at higher UART baudrate. I think.
Delay time.jpg
Delay time.jpg (36.14 KiB) Viewed 4952 times

Re: delay function problem

Posted: Wed May 03, 2017 10:33 am
by howard123
Thanks I understand now
regards
howard

Re: delay function problem

Posted: Wed May 03, 2017 11:02 am
by Benj
Hi Howard,

If you wanted to wait until the UART byte has finished being sent before starting your delay then you could use this following C code in a C icon.

UART Channel 1

Code: Select all

while (TXSTA1bits.TRMT);
UART Channel 2

Code: Select all

while (TXSTA2bits.TRMT);