Jitter / Latency in DIO Outputs

Topics about the Software of Revolution Pi
Post Reply
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39
Answers: 0

Jitter / Latency in DIO Outputs

Post by imerledragon »

Hello everyone,

I am using a RevPi Core 3+ with a MIO module and I am trying a simple test application with 7 segment LED (like this https://raspi.tv/wp-content/uploads/201 ... up_700.jpg)
Basically I want to display multiplexed 7 segment LED but switching them alternatively every 5ms. The problem is that I have a lot of jitter (up to 15ms!).

So I did a very simple program in Go and the same with Python (pseudo-code):

while True:
output(1, True)
sleep(0.005) # 5ms
output(1, False)

I have so much jitter that I think something is wrong somewhere. The same code with standard rpi GPIO works steadily.
The experiment were done by writing at the offset in /dev with Go (there is no buffer for the write but maybe there is one in your driver?) and used RevPiModIO in python.

I then tried to slow down everything (about 100ms sleep) and what I see is that writing Digital Output and Analog Output have different latency so the AnalogOutput is set sometime after the DIO is set.

for {
u.Write(AnalogOutputLogicLevel_OFFSET, outBytesDigit_1)
u.Write(DigitalOutput_OFFSET, outBytesDO_1_ON_ONLY)
time.Sleep(5 * time.Milliseconds)

u.Write(AnalogOutputLogicLevel_OFFSET, outBytesDigit_2)
u.Write(DigitalOutput_OFFSET, outBytesDO_2_ON_ONLY)
time.Sleep( 5 * time.Milliseconds)
}

I do not expect nano or microseconds but 5ms sounds pretty high (https://codeandlife.com/2012/07/03/benc ... pio-speed/)
Understanding this is not a pico but still I am confused why 2 successive write are done with up to 25ms delay in between?

Is there any buffer that can be deactivated to get something similar to standard GPIO? I though the RT kernel would help but it's worse than the standard RaspberryPi OS with GPIO.

Any help or idea would be helpful!
Torpi
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39
Answers: 0

Re: Jitter / Latency in DIO Outputs

Post by imerledragon »

Addition to previous post: I have been wondering of any IRQ might help so did a test using /dev/rtc with "github.com/cleroux/rtc"
This works for 2 to 20Hz but at 200Hz I got between 100 and 200 randomly. On a Pico I would use Timer interrupts or something similar but I am not sure if anything similar could be used with the RevPi?

Torpi
User avatar
p.rosenberger
KUNBUS
Posts: 89
Joined: 03 Jul 2020, 11:07
Answers: 1

Re: Jitter / Latency in DIO Outputs

Post by p.rosenberger »

Hi Tropi,

the PiBridge can't support low latencies. As all RevPi modules use the PiBridge they will never give you latencies of 5ms or below.

Best Regards,
Philipp
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39
Answers: 0

Re: Jitter / Latency in DIO Outputs

Post by imerledragon »

Hello Philipp,

thank you for the clarification.
Now, say I have multiple DIO modules and want to write output from 2 module at the same time, is there any chance the 2 successive write will be <50ms?

Write(DigitalOutput_Module1_Offset, outBytes1)
Write(DigitalOutput_Module2_Offset, outBytes2)

I don't really care about the latency between the instruction and the output but what I need is that both modules would change their output at the same time.
Is there any way to achieve that?

Thank you,
Torpi
User avatar
p.rosenberger
KUNBUS
Posts: 89
Joined: 03 Jul 2020, 11:07
Answers: 1

Re: Jitter / Latency in DIO Outputs

Post by p.rosenberger »

Hi Torpi,

sorry even that can not be guaranteed. The piControl kernel module will read the process image in a loop. You will have a race condition with the piControl reading the values and your application writing the values. It might work most of the time, but it can not be guaranteed that the first value is written in one cycle and the 2nd value is written in the next. I'm currently not sure how long the cycletimes are and if it might work out for your usecase even if the writes will be split up in two cycles.

Best regards,
Philipp
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39
Answers: 0

Re: Jitter / Latency in DIO Outputs

Post by imerledragon »

hum...

So my understanding is there is no way to lock the process for my 2 writes? I would definitely been interested by the cycletime to check if 2 cycles would be ok.
An alternative would be an external shift register but my understanding is that there is no way to get a hardware state machine and bit-banging would again be the same problem.

Do you have any pointer where to check for the cycle time?

Thanks!
Torpi
User avatar
dirk
KUNBUS
Posts: 1949
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: Jitter / Latency in DIO Outputs

Post by dirk »

Hi here is it - RevPiIOCycle see here
https://revolutionpi.com/pictory-neues- ... rect=en_US
imerledragon
Posts: 18
Joined: 30 Sep 2021, 02:39
Answers: 0

Re: Jitter / Latency in DIO Outputs

Post by imerledragon »

Thank you so much! Seems the default is 6 ms. I will play with it and see if that solves my issue.
Thanks again!
Post Reply