Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring frequency of an I2C clock

I'm looking for some ideas here because I'm having a bit of difficulty figuring out how I can do this in Labview.

 

I'm trying to measure the frequency of the clock on an I2C bus. We have two speeds it could be running at - 50kHz and 100kHz and we want to make sure our software bug fix is driving the bus at the correct rate. This can be done with a digital oscilloscope, but we would like to automate it.

 

This page here http://www.ni.com/white-paper/7111/en talks about measuring the frequency of a digital signal by counting pulses of a known signal, using the unknown as a trigger. There's a vi here http://zone.ni.com/devzone/cda/epd/p/id/5013 that does this in LV.

 

The problem with I2C is that the clock stays high until a write command comes in, which messes up the freqency measurement. The other issue is that during our I2C writes, we want the frequency at 50kHz, and during the reads, at 100kHz. So I need a way of differentiating between the two.

 

I have an idea of how to do this on paper. For those unfarmiliar with I2C, there are two lines: a data and a clock. A write is when the data line is pulled low while the clock is high (start bit) and ends when the data line is pulled high while the clock is high (stop bit). A read is when you have a start bit followed by some data, and then another start bit, some data, and then a stop bit.

 

The way to do it then, is:

 

Don't do anything until the first stop bit, so we know we're not in the middle of a read.

If there is a start bit, measure the clock for write frequency.

If there is a second start bit, measure the clock for read frequency.

If there is a stop bit, stop measuring.

 

I thought digital pattern triggering would help me out here, but it seems my device (9411) doesn't support it.

 

Anyway, I look forward to some thoughts.

 

I also have a 9221 AI, but even at 800kS/s, it doesn't seem to be fast enough to give a good picture of the signals.

 

 

       

0 Kudos
Message 1 of 4
(6,671 Views)

I think I've come up with a (temporary?) solution. I take frequency measurements of the signal for about 5-10 seconds. I then histogram the data, and make sure that I have a statistically significant number of measurements at 50kHz and 100kHz. So far that appears to be the case. If I revert to an older version of our software, then I only get a peak at 100kHz.

 

It still would be nice to be able to only trigger measurements when the dataline goes low while the clock is high.

0 Kudos
Message 2 of 4
(6,656 Views)

Hi TheBouleOfFools,

 

What chassis are you using to connect to your 9411?  Whether it is a cRIO or cDAQ chassis will impact the best methodology for triggering.

 

Also, are you hoping to continuously measure this frequency or is this a single sample application?

Andrew T.
National Instruments
0 Kudos
Message 3 of 4
(6,651 Views)

I have a cDAQ-9188 chassis. I'm not sure how to answer the other question. I want to get a number of measurements for the write frequency and take an average. Currently I have my program take continuous samples to update a histogram.

 

The more I look into it, the more I feel I am running into a limitation with my hardware, and I may need to use a real time platform.

0 Kudos
Message 4 of 4
(6,648 Views)