Arduino Forum

Using Arduino => Microcontrollers => Topic started by: skyjumper on Jan 27, 2012, 09:08 am

Title: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 27, 2012, 09:08 am
Hi All...

Well my Saleae Logic 16 has arrived!  What a nice piece of hardware! if only I could get it to work :-(

How do you guys hook your logic analyzers up? I have an I2C device on my board. I put some jumper wires (the kind normally used with breadboards) into the header positions for SCK, SCL (analog 4 and 5) and GND and hooked them up the the analyzer. Started the analyzer sampling, started a sketch that moved some I2C data and.... Nothing :-(

Is there a trick to this?
Title: Re: Help using logic analyzer on Arduino
Post by: bperrybap on Jan 27, 2012, 10:46 am
I don't have the 16 but the original Logic.
I often use the same male/male breadboard jumper wires to connect
the analyzer to the Arduino.

When you say "Nothing" do you mean it samples and you see nothing but solid high or low
or does not never sample?
Are you using any triggers?

If you don't use any triggers, it may fill its buffers before anything happens
or you may need to zoom way out to see the transitions.

Doesn't i2c need the pullups to work?
Try something other than i2c, maybe look at the serial port lines and send some data.
It's kind of cool to see the wave forms and the serial decode.

--- bill


Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 27, 2012, 11:59 am
Well I figured out what I did. I The Logic 16 has two 8 port connectors. I plugged the connector into the one ont eh right, which is channels 9 through 16. I was looking for data on channels 1 and 2. Silly me.

Now I just get even pulses.

I2C does need pullups, on the bus. The board has those. So I think i should be seeing valid data. Maybe the wires are too long or something. I can try SPI and see what happens.

Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 27, 2012, 01:51 pm
If the LA triggers you will see something. As I2C idles high do you have a falling edge trigger set?

______
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 27, 2012, 05:36 pm

If the LA triggers you will see something. As I2C idles high do you have a falling edge trigger set?



Ah, that was the problem! As soon as i set the falling trigger I get data. Thanks Rob!
Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 28, 2012, 12:58 am
Good, an LA is by far the most useful tool for this type of work IMO. They should be compulsory :)

______
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 28, 2012, 06:11 am

Good, an LA is by far the most useful tool for type of work IMO. They should be compulsory :)



Now I need to learn more about the I2C protocol. Its handy being able to tap on to the I2C and/or SPI bus via the Arduino headers. I wish I had access to a nice o scope, it would be cool to see how square the signals are on this board. 

I looked at the bit scope, thinking at first for the $300 cost of the Logic 16 that the bit scope, with two analog inputs, was a better idea. But then you add the cost of a half way descent probe and a few other things that were needed, and I decided just to get the logic analyzer.

So then I looked at Logic vs Logic 16. The 16 is twice the price! But once you look into it, its much, much more than twice the analyzer. The software is the same and that's a good thing. The hardware, however, is better than just 8 more channels. The Logic 16 not only adds 8 channels, but they are protected, they can read from a very low voltage up to 5 volts. The data t the PC is buffered, so sampling at high rates can be done with a busy PC without missing data. And, it can sample at a much higher rate than the 8 channel version. The case is a work of art, black aluminum. The bottom has a rubbery base that keeps it from sliding around. The probes seem good quality and you get 16 of them, plus two 8-wire harnesses, plus the USB cable all in a very nice case.

I really had to convince myself to part with the extra $150 above the Logic, but after watching a few reviews on YouTube, I did it, although still begrudgingly. Now that it's here, I'm glad I did.

I'll do a full review after I learn a bit more about how to use it. Over the next few weeks I need to write some I2C code. I already took a crack at it, and quickly realized that without being able to see what's on the bus, I'm not going to get far. So now I have no excuse!

Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 28, 2012, 07:11 am
Quote
without being able to see what's on the bus, I'm not going to get far.

People develop whole protocols without an LA, buggered if I know how as it's the difference between knowing what's happening and guessing what's happening.

A scope is good as well, those waveforms aren't as nice in the real world as they look on an LA screen :) But in general things work at the physical hardware level these days, it's getting the data flow and higher-level timing right that's the issue.

Quote
I'll do a full review after I learn a bit more

Look forward to it.


_____
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: cappy2112 on Jan 29, 2012, 07:35 am

Hi All...

Well my Saleae Logic 16 has arrived!  What a nice piece of hardware! if only I could get it to work :-(

How do you guys hook your logic analyzers up? I have an I2C device on my board. I put some jumper wires (the kind normally used with breadboards) into the header positions for SCK, SCL (analog 4 and 5) and GND and hooked them up the the analyzer. Started the analyzer sampling, started a sketch that moved some I2C data and.... Nothing :-(

Is there a trick to this?



I too bought a Logic 16, it's a nice little analyzer.

The software could use more T markers, as well as bookmarks. There isn't supposed to be an update until mid year.
The triggering options are a bit confusing, but Salea said they were planning on addressing that too.
Title: Re: Help using logic analyzer on Arduino
Post by: hardcore on Jan 29, 2012, 11:08 am
It really is not that good a value.
$300 for 16 channels at 12.5Mhz

when you can get 34 at 500 mhz for 80 bucks more
http://www.pctestinstruments.com/ (http://www.pctestinstruments.com/)

If it was $100 then fine it would be a good solid product, but to be honest it's not even going to keep up with an arduino because you will need to sample at least at two times the clock rate, giving you a max of 4-8 channels.



Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 29, 2012, 01:15 pm
That Logicport is a real nice gadget but I think it's a little "old school", by that I mean that fast and wide with limited sample memory was how we used to have LAs when we had to debug fast timing issues.

For most people these days that is no longer the case, all the fast stuff is inside the chip, we're looking at port bit flipping and serial busses so I doubt there are many instances of having to sample at 2x the Ardiuno's 16Mhz.

That said I found that using very fast assembly language pulses for debugging can defeat the Saleae at times. OTOH being able to see short bursts of high-speed data occurring over 1sec apart is great.

The Logicport only has a 2048 deep buffer, I note that they have compression, do you know how long a sample it can take?

If I had the money I'd be be inclined to buy both, but as I seldom deal with fast logic these days the Saleae does the job. That may change with the new Due should we ever see them.

______
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: bperrybap on Jan 29, 2012, 08:03 pm


If I had the money I'd be be inclined to buy both, but as I seldom deal with fast logic these days the Saleae does the job. That may change with the new Due should we ever see them.

______
Rob


The Maple and Chipkit are real today; no need to wait on Due.
I have a Chipkit Uno32 and for some of the stuff I'm doing, the Saleae Logic (not Logic 16) is simply not fast enough.
Like using pin strobes/pulses for software profiling. They are simply too fast/short to see on the Logic without adding
in s/w delays.

But in general I agree that for most things I'm doing right now, it works just fine.

--- bill
Title: Re: Help using logic analyzer on Arduino
Post by: cappy2112 on Jan 29, 2012, 08:32 pm


the Saleae Logic (not Logic 16) is simply not fast enough.
Like using pin strobes/pulses for software profiling. They are simply too fast/short to see on the Logic without adding
in s/w delays.
But in general I agree that for most things I'm doing right now, it works just fine.
--- bill
[/quote]

I've used direct port writes on a 16Mhz Uno to trigger my Logic 16. It works fine.
I'm only using 2-3 channels on the Logic 16. The less channels that are used, the higher the sampling rate (within limits).
Title: Re: Help using logic analyzer on Arduino
Post by: bperrybap on Jan 29, 2012, 09:42 pm


Quote

the Saleae Logic (not Logic 16) is simply not fast enough.
Like using pin strobes/pulses for software profiling. They are simply too fast/short to see on the Logic without adding
in s/w delays.
But in general I agree that for most things I'm doing right now, it works just fine.
--- bill


I've used direct port writes on a 16Mhz Uno to trigger my Logic 16. It works fine.
I'm only using 2-3 channels on the Logic 16. The less channels that are used, the higher the sampling rate (within limits).



Its not the AVR at 16Mhz that is the issue.
It is the 80mz pic32 that can be too fast for the Logic sampling rates.

The ability to reuse the bandwidth of unused channels on the Logic 16 is great.
That gets quite a bit higher sampling rate when the number of channels is lower than
on the original Logic. Theoretically up to 100Mhz if only using two channels.

The part that I believe is very misleading is:
Quote
Logic16 can save as many as 10B samples,
letting you capture even the most elusive events.
No more dealing with frustratingly small sample buffers


To me there needs to be a big and better distinction between
"sample buffers" in the device which temporarily protects you against USB speed and latency issues,
and the size of the trace that can be stored on the PC.
The Logic 16 is not saving 10B samples, it is Logic 16 application s/w
running on the PC that can save up to 10B samples that it
gets from the Logic 16 via USB.

When streaming the sample data over USB,
USB2 is simply not fast enough to support high speed sampling on very many channels.
USB3 would be better.

What I'd like to see is allowing the Logic/Logic16 to run in either streaming mode, like it works today,
or in "snapshot" mode which is more
like a traditional analyzer which would allow much faster captures but for a much shorter
amount of time as limited by the internal buffer.

For some uses, even the existing limited buffers inside the Logic/Logic16 would be enough
to get pictures of special events, when used with multiple triggers.

--- bill
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 12:58 am
That seems like a nice analyzer, but I was not about to spend $400. Its bad enough I spent $300! Part of my thinking was that I'm not likely to use 16 channels, or even 8 channels. Mostly, I wanted to see what was happening when I write code for I2C and SPI, since its hard to debug code without knowing what its doing. So two or three channels, maybe 4, is what I need.

My other thinking was that I'll probably need a nice O scope some day, and if it comes to very high speed stuff, I'll use the O scope. But they are pricy, so it can wait.

I had not thought of using it for speed profiling, that's a great idea. One thing I was trying to figure out how to do was to see how quickly my code running on my board (a 16MHz 1284P based board) can respond to an and interrupt and close files on the SD card when power goes away. Now I realize I can throw a pin high when power goes away, another when I enter the ISR and another when the files are closed. This should be fun!

Title: Re: Help using logic analyzer on Arduino
Post by: cappy2112 on Jan 30, 2012, 01:08 am

I had not thought of using it for speed profiling, that's a great idea. One thing I was trying to figure out how to do was to see how quickly my code running on my board (a 16MHz 1284P based board) can respond to an and interrupt and close files on the SD card when power goes away. Now I realize I can throw a pin high when power goes away, another when I enter the ISR and another when the files are closed. This should be fun!


I used the Logic analyzer to profile my ISR response & latency time.

I was seeing 3-4 uS before the ISR got called, and ~6uS inside the ISR.
Oddly enough, getting back from the ISR to loop() took a horrible amount of time. I never understood why.
There were some posts about the ISR not clearing the interrupt flag. I tried clearing it in the ISR, but didn't reach any reasonable conclusions.

I'm starting to think it may be better to bite the bullet and ditch the Arduino safety net.
At the same time I'm not looking forward to bringing up a microcontroller from scratch.
Title: Re: Help using logic analyzer on Arduino
Post by: hardcore on Jan 30, 2012, 01:09 am

For most people these days that is no longer the case, all the fast stuff is inside the chip, we're looking at port bit flipping and serial busses so I doubt there are many instances of having to sample at 2x the Ardiuno's 16Mhz.

It is simply a requirement for sampling digital logic that you sample at at least 2* the speed of the levels you are looking at.
So even at 16Mhz you can change the outputs every 62ns.
On my recent project for reading a Nand-flash chip on a mega, I would have been sunk if I did not have the width & speed of the Logicport.

Quote

The Logicport only has a 2048 deep buffer, I note that they have compression, do you know how long a sample it can take?

Thats what triggers are for.....,but you will notice that most 'cheap' high speed logic analyzers  are the same, simply because to use external memory would require memory cycle speeds in the pico second range and that is what you pay for in the really high end HP market.
They claim that the compression is 2^33 to 1 at 200Mhz, above that then I guess the FPGA has not got enough time between samples to get it compressed.(It may be that if they had a really good VHDL programmer they could get an improvement)
Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 30, 2012, 01:11 am
Quote
Now I realize I can throw a pin high when power goes away, another when I enter the ISR and another when the files are closed.

That's how most people do it AFAIK. If you have the spare pins it's a non-intrusive way to debug.

I use a couple of macros

Code: [Select]
#ifdef CLIENT_ATmega328
#define PULSE0_PIN 8
#define PULSE1_PIN 9
#define PULSE0 asm("sbi 5,0\nnop\nnop\nnop\nnop\ncbi 5,0");  // PORTB bit 0, 328 Arduino D8
#define PULSE1 asm("sbi 5,1\nnop\nnop\nnop\nnop\ncbi 5,1");  // PORTB bit 1, 328 Arduino D9
#endif
#ifdef CLIENT_ATmega2560
#define PULSE0_PIN 10
#define PULSE1_PIN 11
#define PULSE0 asm("sbi 5,4\nnop\nnop\nnop\nnop\ncbi 5,4");  // PORTB bit 4, 2560 Arduino D10
#define PULSE1 asm("sbi 5,5\nnop\nnop\nnop\nnop\ncbi 5,5");  // PORTB bit 5, 2560 Arduino D11
#endif


Note the nops? They are there to widen the pulse because the Saleae isn't quite fast enough. I don't think I needed so many though, can't remember now.

This gets worse with faster chips as has been stated, so because this is such a useful technique I've added dedicated hardware to do this on my new Due design.

______
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 01:12 am


I used the Logic analyzer to profile my ISR response & latency time.

I was seeing 3-4 MS before the ISR got called, and ~6uS inside the ISR.
Oddly enough, getting back from the ISR to loop() took a horrible amount of time. I never understood why.
There were some posts about the ISR not clearing the interrupt flag. I tried clearing it in the ISR, but didn't reach any reasonable conclusions.

I'm starting to think it may be better to bite the bullet and ditch the Arduino safety net.
At the same time I'm not looking forward to bringing up a microcontroller from scratch.


Thanks for posting those numbers, that's very helpful.

I long ago decided that the "Arduino safetynet" was in the way. I'm bit by bit coding past it. Problem is, there are just sooooo many really handy libraries I'm using.
Title: Re: Help using logic analyzer on Arduino
Post by: bperrybap on Jan 30, 2012, 01:15 am

I had not thought of using it for speed profiling, that's a great idea. One thing I was trying to figure out how to do was to see how quickly my code running on my board (a 16MHz 1284P based board) can respond to an and interrupt and close files on the SD card when power goes away. Now I realize I can throw a pin high when power goes away, another when I enter the ISR and another when the files are closed. This should be fun!


Believe it or not, this is mostly what I've used a logic analyzer for during the past 25 years.
I've used many different pulse techniques, like a single pulse to enter a code block and a double pulse to exit
a code block. This works pretty good even on Logic with up to 8 profiling points.

I've also used 1 pin as marker strobe and then other pins to indicate a code.
For example, years and years ago I used to use a Parallel port for this.
The strobing code sets a code in 8 bits, then pulses the strobe.
On the analyzer you looked at the strobe to see your events, then looked at the 8 bit data to get a code number
to see which event it was. This gave up to 256 events that could be traced.
You can do the same on the AVR using multiple pins.

The beauty about using hardware strobes for profiling is that they add very little overhead.
(well if you avoid things like digitalWrite() to control the pins)

--- bill
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 01:16 am
Rob, thanks very much! I am looking to get very coarse measurements. Right now my board has a 1.5F super capacitor on it, hold up time is well over a second, probably close to 2 seconds. The cap takes a lot of time to charge. I am thinking I just need 200ms hold up time, so a smaller cap that charges faster. So a very coarse measurement, with a wide safety margin in case there is a card that is a real current hog.

Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 01:22 am


I use a couple of macros

Code: [Select]
#ifdef CLIENT_ATmega328
#define PULSE0 asm("sbi 5,0\nnop\nnop\nnop\nnop\ncbi 5,0");  // PORTB bit 0, 328 Arduino D8
#define PULSE1 asm("sbi 5,1\nnop\nnop\nnop\nnop\ncbi 5,1");  // PORTB bit 1, 328 Arduino D9
#endif




Rob, please forgive my ignorance of AVR ASM. I guess the instruction "sbi 5,0" sets port B bit 5 low, then "ncbi 5,0" sets it high? If so, why two separate instructions?
 
Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 30, 2012, 01:33 am
Quote
Nand-flash chip on a mega, I would have been sunk if I did not have the width & speed of the Logicport.

Agreed, and I may have similar issues soon interfacing with external SRAM.

Quote
3-4 MS before the ISR got called,

WTF? That's a heck of an interrupt latency. There must be something else at play there like somebody disabling ints for too long.

Quote
I guess the instruction "sbi 5,0" sets port B bit 5 low, then "ncbi 5,0" sets it high? If so, why two separate instructions?

Because it's a pulse, you set it high then set it low. You could also have a SET and CLEAR macro that each just did one of the instructions.

Re profiling...

Of course we can trigger and measure to get timing, we can do that 10 or more times and record the numbers but that's not a very good statistical sample.

Does anyone have a good way to, for example, run a test all day and get max, min, avg etc times?

______
Rob

Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 02:06 am
Because it's a pulse, you set it high then set it low. You could also have a SET and CLEAR macro that each just did one of the instructions.




No no, I understand its a pulse.

What I mean is, if sbi 5,0 sets it low, I would think sbi 5,1 would set it high? Why use different machine instructions?
Title: Re: Help using logic analyzer on Arduino
Post by: bperrybap on Jan 30, 2012, 02:12 am
sbi 5,0 to turn bit on then cbi 5,0 to turn bit off.  ;)
Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 30, 2012, 02:14 am
I see, they aren't write instructions in the normal sense, the 5 is the address of the register (PORTB is at address 5) and the 0 is the bit number.

The writing of a 1 or 0 is implied in the SBI and CBI instructions.

______
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 30, 2012, 02:16 am
Just in case people missed the question buried in post #22,

Does anyone have a good way to, for example, run a test all day and get max, min, avg etc times?

______
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: bperrybap on Jan 30, 2012, 02:45 am

Just in case people missed the question buried in post #22,

Does anyone have a good way to, for example, run a test all day and get max, min, avg etc times?

______
Rob



I've done that kind of stuff before but not using a logic analyzer.
I've profiled disk drivers in live running operating systems before and
used a combination of high resolution counter/timers, buffers and even some additional storage
to log the data in real time and then post process it all later.

Given the large storage capabilities in the Logic s/w, you might be able to run a trace for "a bit"
of time, then export the data and post process it to get the numbers you want.
The CSV export format looks pretty easy to parse.
Probably won't be able to import it into a spread sheet as things like MSFT Excel can only handle
65536 rows.

But even that only gets you a few minutes until you really slow down the sampling rate.
1Mhz gets you a few hours.

min and max might be much easier as for those you might be able to get away tracking those
in software. Depending on your timing and resolution needs, you could even use the
Arduino micros() call and then keep track of the min an max deltas. It is only two numbers
which for many situations won't add too much overhead to calculate and compare.
The extremes may actually be more important to know than the average.

--- bill
Title: Re: Help using logic analyzer on Arduino
Post by: cappy2112 on Jan 30, 2012, 03:07 am

Quote
3-4 MS before the ISR got called,

WTF? That's a heck of an interrupt latency. There must be something else at play there like somebody disabling ints for too long.


Sorry- that was a major typo. I've updated the original post. PLEASE RE-READ that post everyone!


Does anyone have a good way to, for example, run a test all day and get max, min, avg etc times?


The problem I am seeing with Arduino IDE 0023 on Windows XP, SP3 is that when the IDE is running with the console open for many hours,
there is a loss of communication to the Arduino. Red error messages are displayed in the lower half of the console.

Others have reported something similar.
I need to double check to make sure the screensaver or power management isn't kicking in and turning off the USB port.
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 03:19 am


The problem I am seeing with Arduino IDE 0023 on Windows XP, SP3 is that when the IDE is running with the console open for many hours,
there is a loss of communication to the Arduino. Red error messages are displayed in the lower half of the console.

Others have reported something similar.
I need to double check to make sure the screensaver or power management isn't kicking in and turning off the USB port.


I use TerraTerm.
Title: Re: Help using logic analyzer on Arduino
Post by: skyjumper on Jan 30, 2012, 03:21 am


Quote
3-4 MS before the ISR got called,

WTF? That's a heck of an interrupt latency. There must be something else at play there like somebody disabling ints for too long.


Sorry- that was a major typo. I've updated the original post. PLEASE RE-READ that post everyone!


Does anyone have a good way to, for example, run a test all day and get max, min, avg etc times?



Haha... When I read that, I read it as uS to begin with... Funny how our brains do those things...
Title: Re: Help using logic analyzer on Arduino
Post by: cappy2112 on Jan 30, 2012, 03:27 am



I used the Logic analyzer to profile my ISR response & latency time.

I was seeing 3-4uS before the ISR got called, and ~6uS inside the ISR.
Oddly enough, getting back from the ISR to loop() took a horrible amount of time. I never understood why.
There were some posts about the ISR not clearing the interrupt flag. I tried clearing it in the ISR, but didn't reach any reasonable conclusions.

I'm starting to think it may be better to bite the bullet and ditch the Arduino safety net.
At the same time I'm not looking forward to bringing up a microcontroller from scratch.



Thanks for posting those numbers, that's very helpful.


I'm sure you understand this but for those who don't...

The ~6uS of ISR time is mostly due to what I'm doing in the ISR. This is not a specification by any means, and is actually quite long for a typical ISR.
My application doesn't need very fast response.
Title: Re: Help using logic analyzer on Arduino
Post by: graynomad on Jan 30, 2012, 03:29 am
Small typo. BIG difference :)

Quote
The extremes may actually be more important to know than the average.

Exactly, in a system that has to respond within say 100uS the only thing that matters is if it ever takes > 100uS and it would be nice to stress test for 2 days and see if it ever happens.

I suppose that can be done with timed triggers if that feature is available, but average times in a function and other profiling is useful as well.

I'm just wondering if it's worth adding some hardware to allow a plug-in debugger to help with this, of interest to maybe < 1% of Arduino users but an interesting project.

____
Rob
Title: Re: Help using logic analyzer on Arduino
Post by: cappy2112 on Jan 30, 2012, 03:32 am



The problem I am seeing with Arduino IDE 0023 on Windows XP, SP3 is that when the IDE is running with the console open for many hours,
there is a loss of communication to the Arduino. Red error messages are displayed in the lower half of the console.

Others have reported something similar.
I need to double check to make sure the screensaver or power management isn't kicking in and turning off the USB port.


I use TerraTerm.


We use that too, but going back and forth between the IDE to compile & download, then having to close the com port is a pain.
For an overnight run while monitoring the UART is just fine.

BTW- there is a virtual com port software called com0cm which creates virtual com ports, so that multiple apps can *effectively* use the same com ports at the same time.
Obviously there is some stream multiplexing going on, but when it works it makes life easy.

I haven't been able to get it working yet- but others have figured it out.