Go Down

Topic: Help using logic analyzer on Arduino (Read 10410 times) previous topic - next topic

cappy2112

#15
Jan 30, 2012, 01:08 am Last Edit: Jan 30, 2012, 03:04 am by cappy2112 Reason: 1

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.

hardcore


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)

graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

skyjumper



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.

bperrybap


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

skyjumper

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.


skyjumper



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?
 

graynomad

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

Rob Gray aka the GRAYnomad www.robgray.com

skyjumper

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?

bperrybap

sbi 5,0 to turn bit on then cbi 5,0 to turn bit off.  ;)

graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

bperrybap


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

cappy2112


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.

skyjumper



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.

Go Up