Access to IO's in a fast way

Topics about the Hardware of Revolution Pi
Post Reply
RTI GWF
Posts: 4
Joined: 10 Mar 2025, 14:09

Access to IO's in a fast way

Post by RTI GWF »

Hi Together

I am currently trying to write a Python application on our RevPi compact. Yes, I now know that the compact is no longer supported, but I wasn't aware of this when I bought it.

To the point. Most of the application is not time-critical, but within one execution, a pulse measurement is made via the digital IOs. Now, on the data sheet(https://revolutionpi.com/documentation/ ... g%C3%A4nge) it says that the analogue inputs are sampled with a maximum of 125ms and the digital ones can manage a fast 250us. Perfect, I thought. But now I'm trying to access the digital IOs relatively quickly, and I'm having a difficult time with it.

What I have tried:
1. Via the revpimodio2 (revpi.io.DI_0.value). The problem here is that the minimum cycle time is 5ms. When I read out the IOs via this, they are only updated every max. 5ms. And if I run the whole application with the 5ms, I keep encountering the exceeding error. At the moment, I only lower the cycle time for the measurement and then raise it again.
2. A quasi direct readout via “/dev/piControl0” the process image. Here, the limit seems to be 1ms (from test runs). Unfortunately, I don't understand where this comes from, or whether it can be changed to be faster? Does anyone here have any input? What controls how often the process image is written to piControl0?

What I also don't understand:
3. What is the use of a maximum possible hardware rate of 250us if I have no direct and fast access to the IO's in the SW to read it out? Or does I simply not see how to access it?

How do you access your IO's in a fast way?

Thank you for your help :D

Greetings Raphael
User avatar
nicolaiB
KUNBUS
Posts: 1014
Joined: 21 Jun 2018, 10:33
Location: Berlin
Contact:

Re: Access to IO's in a fast way

Post by nicolaiB »

Hi Raphael,

can you please share your Code / an example how to access the IOs? As alternative to revpimodio2 you can access the IOs directly via gpiod / iio sysfs.

Nicolai
RTI GWF
Posts: 4
Joined: 10 Mar 2025, 14:09

Re: Access to IO's in a fast way

Post by RTI GWF »

nicolaiB wrote: 23 Apr 2025, 08:45 can you please share your Code / an example how to access the IOs?
Hi Nicolai

Sorry for the long delay for an answer. Sure I can. Overall, it's rather simple but nested in some different functions, that's why I try to post here more a cuttogether of the essentials:

Code: Select all

All in Python 3.11.9
...
    fd = os.open("/dev/piControl0", os.O_RDONLY | os.O_NONBLOCK)
    INPUT_BYTE_OFFSET = 2
    revpi.cycletime = conf.revpi_fast_cycletime   # set cycletime to 5ms
    
    while time.time() <= start_proc_time + conf.testing_time:
    	stopflag_watchdog()
    	os.lseek(fd, INPUT_BYTE_OFFSET, os.SEEK_SET)
    	data = os.read(fd, 1)
    	pulses = [(data[0] >> bit) & 1 == 1 for bit in range(4)]    # <- reads the Digi_IN 0-3
    	airflow_over_time.append(round(hyd_T_station.airflow_sens.value, 3))   # Some analogue read-outs over a class that uses revpimod2
        pressure_over_time.append(round(hyd_T_station.pressure_sens.value, 3))   # Some analogue  read-out over a class that uses revpimod2
        
        # Make sure it will be recorded in a constant interval
        meas_dur = time.time() - start_meas_time
        if conf.puls_test_interval > (meas_dur + 0.0001):
            # 0.0001 = aprox shift from code below after sleep.
            time.sleep(conf.puls_test_interval - (meas_dur + 0.0001))
        
        ...
      
    revpi.cycletime = conf.revpi_normal_cycletime # set cycletime to 30ms
    close_io_file(fd)
    ...   
Overall, it does not more than read out IO's and control the interval times + record these. So rather simple stuff. But still what I don't understand is even if the cycletime is 5ms I can read out at approx 1ms. So the "/dev/piControl0" file is updated faster? Can I control the cycle time in which the piControl0 is updated?
nicolaiB wrote: 23 Apr 2025, 08:45 As alternative to revpimodio2 you can access the IOs directly via gpiod / iio sysfs.
Ok, that also sounds like an alternative. Can you share a code snippet on how to do that? I was (probably based on a GBT request) of the opinion that I cannot access the GPOI's directly on a RevPi. When I can, I don't need to lower the cycle time on the module and could read out the digital IO's directly. Is this the reason in the datasheet stands the 250us for digital IO's?

Thanks for the support.
Greetings Raphael
RTI GWF
Posts: 4
Joined: 10 Mar 2025, 14:09

Re: Access to IO's in a fast way

Post by RTI GWF »

nicolaiB wrote: 23 Apr 2025, 08:45 Hi Raphael,

can you please share your Code / an example how to access the IOs? As alternative to revpimodio2 you can access the IOs directly via gpiod / iio sysfs.

Nicolai
Hi Nicolai and forum

Any Updates/Input to this topic? I would really appreciate it.

Greetings Raphael
Post Reply