I2C SPI USB CAN eSPI Cable Testing View All Quick Start Guides User Manuals Software Downloads Knowledge Base Videos Case Studies App Notes White Papers Sales Support About Us
Products Blog Sales Support Contact Search
How Does Latency Prevent an Automated Script from Running Correctly when using the Aardvark I2C/SPI Host Adapter?
Rena Ayeras

Synchronized Clocks

Image by Geralt

Question from the Customer:

We are using the Aardvark I2C/SPI Host Adapter to program SPI devices. We successfully completed the first two stages of verifying the software. However, we are having issues with the third stage – automating the process. There was no activity, which was verified on an oscilloscope.

Stage 1: We executed the following commands with the Control Center Serial Software:

07 03 (initial)

08 02 (HIGH set)

0B 01 (PWM set)

15 FF (DUTY set)

Both the GUI and the oscilloscope showed it was functioning correctly.

Stage 2: To automate that process, we wrote a script with Aardvark Software API for continuous execution. At this stage, we only included the Initial and HIGH set commands, which worked correctly:

<adapter>

<configure i2c="1" spi="1" gpio="0" tpower="1" pullups="0"/>

<spi_bitrate khz="125"/>

<spi_config polarity="rising/falling" phase="setup/sample" bitorder="msb" ss="active_low"/>

<spi_write ss="0" count="2" radix="16">07 03</spi_write>

<spi_write ss="0" count="2" radix="16">08 02</spi_write>

<spi_write ss="0" count=“2” radix="16">0B 01</spi_write>

<spi_write ss="0" count=“2” radix="16">15 FF</spi_write>

</adapter>

Stage 3: We added the last two commands for PWM set and DUTY set:

<adapter>

<configure i2c="1" spi="1" gpio="0" tpower="1" pullups="0"/>

<spi_bitrate khz="125"/>

<spi_config polarity="rising/falling" phase="setup/sample" bitorder="msb" ss="active_low"/>

<spi_write ss="0" count="2" radix="16">07 03</spi_write>

<spi_write ss="0" count="2" radix="16">08 02</spi_write>

<spi_write ss="0" count=“2” radix="16">0B 01</spi_write>

<spi_write ss="0" count=“2” radix="16">15 FF</spi_write>

</adapter>

This is where we saw no activity on the oscilloscope. Can you explain what causes such problems? What changes can we make to automate this entire process?

Response from Technical Support:

Thank you for your questions! There are latencies that could affect the performance of your script. For your project, we have two recommendations:

  • With your current script, add sleep time to compensate for latencies.
  • For faster execution with far less latency, replace the Aardvark adapter with the Promira Serial Platform.

Add Sleep to the Automated Script

There are factors of speed and latency that can affect a script’s performance:

  • The operating system of the host computer queues all outgoing USB transfer requests until the next USB frame period. The frame period is about 2 ms. If the application attempts executing several transactions in rapid sequence, there can be a timing conflict. There may be a need for a 2 ms delay between each transaction to function within the scheduling delays from the operating system.
  • The write (or read) call must be completed before the next API call. Each time this function is called, a 2 ms round-trip latency is incurred. This is caused by the full-speed USB link between the host computer and the Aardvark adapter.
  • The target device may also require a delay to commit the write (or read) to a specific address. The datasheet of the target device should provide this information. For information about the Aardvark adapter, refer to the section SPI signaling characteristics in the Aardvark I2C/SPI Host Adapter User Manual

To compensate for the latencies and timing requirements, we recommend adding sleep before and after the last two commands as shown below:

<adapter>

<configure i2c="1" spi="1" gpio="0" tpower="1" pullups="0"/>

<spi_bitrate khz="125"/>

<spi_config polarity="rising/falling" phase="setup/sample" bitorder="msb" ss="active_low"/>

<spi_write ss="0" count="2" radix="16">07 03</spi_write>

<spi_write ss="0" count="2" radix="16">08 02</spi_write>

<sleep ms="10"/>

<spi_write ss="0" count=“2” radix="16">0B 01</spi_write></P

<spi_write ss="0" count=“2” radix="16">15 FF</spi_write>

<sleep ms="10"/>

</adapter>

Please note, “10 ms” is an example. As previously stated, refer to the device datasheet to see how much delay is needed.

Automate with Greater Speed and Flexibility

For your project, we recommend using the Promira Serial Platform. This tool uses Ethernet, and Ethernet over USB, which provides a faster interface with this host computer. The Promira platform also operates at higher speeds than the Aardvark adapter.

For Promira Software API I2C/SPI Active functions, there is also the advantage of queuing and shifting multiple commands to the target device at once. For information about queuing, please refer  Section 5.5.3 Queuing of the Promira Serial Platform I2C/SPI Active User Manual.

We hope this answers your questions. Additional resources that you may find helpful include the following:

If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.