Polling AI



  • Hello,

    I was wondering what the max frequency is at which I can poll for the AI values using the API. I have tried setting the interval field to 0.01 s but the value does not seem to be updated as fast. There is a field called "continuous" (set to false by default) inside the AI class…can that be used somehow?

    Thanks,



  • Hello,

    I was wondering what the max frequency is at which I can poll for the AI values using the API. I have tried setting the interval field to 0.01 s but the value does not seem to be updated as fast. There is a field called "continuous" (set to false by default) inside the AI class…can that be used somehow?

    Thanks,



  • Hello,

    the sampling frequency depends on the conversion bit resolution according to this table:
    12 = 12 bit (240 SPS max)
    14 = 14 bit (60 SPS max)
    16 = 16 bit (15 SPS max)
    18 = 18 bit (3.75 SPS max)

    The default setting in evok is 18bits which is equal to 3.75 samples per second. Then there is another setting 'interval in evok for each analog input device which tells evok how often to read the value from the IC in seconds. So you can set it to eg 0.1s and eg 16bit resolution to get value 10times per second.

    Br,
    Tomas



  • Hi, I have bits set to 12 and interval set to 0.05, but the values I am reading don't seem to be updated as fast. Sample data I collected (see below) show the values I got from the REST server (polled every 100 millisecond); the blocking time is the time it took the client to connect to the server and get the response in micro seconds. Could there be something I am missing? Thanks again,

    2.0932308217819; blocking time: 10141
    2.0876637185325; blocking time: 5678
    0.0000000000000; blocking time: 8232
    0.0000000000000; blocking time: 5773
    0.0000000000000; blocking time: 4641
    2.0876637185325; blocking time: 5349
    0.0000000000000; blocking time: 6085
    0.0000000000000; blocking time: 7838
    2.0876637185325; blocking time: 7954
    0.0000000000000; blocking time: 7921
    0.0000000000000; blocking time: 7401
    2.0876637185325; blocking time: 7654
    2.0876637185325; blocking time: 7345
    2.0876637185325; blocking time: 5139
    2.0876637185325; blocking time: 4779
    2.0876637185325; blocking time: 4566
    0.0000000000000; blocking time: 5295
    0.0000000000000; blocking time: 5440
    2.0876637185325; blocking time: 5345
    2.0876637185325; blocking time: 5295
    0.0000000000000; blocking time: 5589
    0.3562946079629; blocking time: 5032
    2.0876637185325; blocking time: 4711
    2.0876637185325; blocking time: 4524
    0.0000000000000; blocking time: 4565
    2.0876637185325; blocking time: 5659
    2.0876637185325; blocking time: 5535
    0.0000000000000; blocking time: 7976
    0.0000000000000; blocking time: 7526
    2.0876637185325; blocking time: 7189



  • Hello,

    could you provide the testing script you are using? The time of reading of analog inputs also depends on other ICs that are connected to the I2Cbus thus if the bus is bussy doing some work for other devices than the reading might not be so fast as requested.

    And then there is the interval parameter of each device which is compared in every run of the internal loop which could be too pretty dangerous because it may cause the bus to be overwhelmed with all the commands.

    I would test it with eg 14 and 16bits resolutions and see what it can do. Actually we did not planned the api and the whole unipi for that fast operations…



  • If your project requires precise timing, you might be interested in the REX Control System, which is perfectly suited for fast algorithms:
    http://www.rexcontrols.com/rex-control- ... spberry-pi



  • You can also try setting the speed of I2C bus to 400000 - edit/add /boot/config.txt file with dtparam=i2c_baudrate=400000



  • Thanks. My initial test shows that the values I got after I set the baudrate are good. I also tried making the following change to config.py on line 179

     ai = unipig.AnalogInput(circuit, mcai, channel, bits=bits, gain=gain,
                                            continuous=True, interval=interval, correction=correction, rom=eeprom,
                                            corr_addr=corr_addr)
    ```Just changed default value of continuous to be "true" instead of false, and then set the interval in the /etc/evok.conf to 0 (otherwise I the values I read are null). The results I got after doing this are also good. I am comparing the values I read using evok to the values I read by using the pigpio library. I am not sure what is going on…


  • This is what I have found out. There is no need to change anything in the python code. Changing the baud rate from 100k to 400k is helpful because to get 240 samples of 12 bits each per second needs a speed of 100k+. This is how I use the evok rest service in C++ code for anyone interested:

    https://github.com/meongit/evok_restful ... eading.cpp



  • Hey everybody,

    very cool i didnt knew that the evok api is also available for C++
    Where do you find the src of the evok api for C++?
    And thanks for sharing!!

    Best regards,
    Martin M.