So I'm just out of college and sort of bummed by the lack of expensive EE equipment. I'm a CompE without a scope, logic analyzer, or any of the other $1000+ tools from the lab.
I came up with a quick solution for the logic analyzer and first test look like works pretty decently. I'm thinking it might be a cool project if there was a decent GUI attached.
From what I can tell, I can capture short bursts of data up to 206kHz.
Quick question, though: has anyone encountered problems where really long arrays crash a program? There are a million ways to change this for more compression, but at present I can only store up to about 175 logic changes before I start getting garbage or crashes.
It looks like the problem is caused by the 875 bytes consumed by your array of logic_structs . The chip only has 1k of ram and some of that is used by the arduino start up code.
Your struct consists of 5 bytes (Boolean is a byte), you could increase your array size by using 15 bits for cycle and 1 bit for the logic level. This would increase the max array size to around from 175 to around 440. But it would reduce the maximum value of cycles to 32k If this is an approach that you want to take and your not already familiar with bitfields, have a look at using that to manage the data in your structure.
It looks like the code has not changed, I am not sure if yikes128 is still around.
It may work as is if you have a board with 2k of RAM (a 328 controller).
But bear in mind this is limited to a single channel at a maximum data rate of around 200kHz
But bear in mind this is limited to a single channel at a maximum data rate of around 200kHz
Udo's in the playground seems somewhat better in the task (though more difficult to follow, and you need to use the avr tools directly according to the comments to get it into your arduino); it uses an unrolled loop in assembler to sample a single port (D) quickly 1024 times upon a trigger on one of the pins (via a bitmask), then prints the results to the serial port.
Personally, it seems like a better option, even if it is more difficult to follow; I think if you took it, made some modifications to it, added on a button interface and a KS0108 GLCD gui - you would have a very nice little low-cost logic analyzer...
One thing it does seem to lack is any form of inter-sample timing; it is basically digitizing the port as fast as possible, each sample "in between" time is the number of clock cycles for each "set" of sampling instructions in the unrolled loop (it turns off the interrupts during the sampling phase, I think, so they don't cause issues, then turns them back on after it is done).
It looks like it was written for the 168; I am not sure if you would need to modify anything for the 328 (you could increase the sample buffer, though).
I just added a reply to http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1269604194 about an interesting alternative
for the logic analyser (I think).
Being an Arduino newbie I am not sure if there is a good match between the arduino and this thing, but there might be.
am I correct that on an 16mhz avr, this unrolled code
takes an st (2 clockcycli) and in (1 clockcycle) instruction, meaning a sample rate of 16/(2+1) Mhz ?
and therefore covering less than a millisecond in a 1024 byte buffer ?
am I correct that on an 16mhz avr, this unrolled code
takes an st (2 clockcycli) and in (1 clockcycle) instruction, meaning a sample rate of 16/(2+1) Mhz ?
and therefore covering less than a millisecond in a 1024 byte buffer ?
I haven't looked at it in-depth (that is, I haven't looked at how long each instruction takes, etc) - but if your numbers are correct, then yes, the sample period is going to be very short. Note that I believe it was done with a 168, with a 328 you could "double" the length (I think). Still, not a lot of time.
Potentially, you could dump the samples to an SD card, but I am not sure how you would glue the assembler together with the SD library (or if you would have to write your own assembler version?). Another alternative would be a serial EEPROM.
Udo's code is really a sampler, and not a strict analyzer; that is, it doesn't store timing information between transistions, it just stores whatever it grabs. But the same kind of system (an unrolled assembler loop) could potentially be used, only store the data on the transistion of any pin in the port (via an interrupt handler), and keep track of the time between interrupts (not sure if this can be done in an interrupt handler, though)...
just to be clear, that link I posted tells about a digital scope, not a logic analyzer.
@cr0sh, thanks ! I need such a sampler for another purpose, and after I did the math it seems is is even too fast for me. so I can probably loop and avoid the asm stuff.
One beginners question : is there a read operation which reads a whole port (8 pins) in sketch ? ReadByte() or something ? it is imperative I read all 8 (or 4) bits at the exact same time.
One beginners question : is there a read operation which reads a whole port (8 pins) in sketch ? ReadByte() or something ? it is imperative I read all 8 (or 4) bits at the exact same time.
With regard to my quick hack analyzer / sampler: I changed it to make it available from the IDE. However I did not try it. Hopefully I made no typos...
Since it allocates 1K for the buffer and serial needs some space as well you need a 328 or 644 to run it. Otherwise you need to make the buffer smaller.
And one more thought: it is only reasonable if you have way more time than money. As already mentioned you can get much better ones for little money.
And one more thought: it is only reasonable if you have way more time than money. As already mentioned you can get much better ones for little money.
I still think taking your code (or a version of it), and marrying it up to the KS0108 with some kind of simple button interface would make for a neat project; kinda a complement to the seeedstudio o-scope...
I'll put it on my project list. This does not imply that I will start it anytime soon. But maybe later ... The main issue is that KS0108 takes way to many pins.
I'll put it on my project list. This does not imply that I will start it anytime soon. But maybe later ... The main issue is that KS0108 takes way to many pins.
I am not asking -you- necessarily to do this; just that I think it would be an interesting project for someone to take on. While your expertise in the existing code is a foundation, I don't mean to imply that I think only you could do it, or that you must do it at some point. If I had the time myself, I would tackle it (and I may yet still, who knows?).
As far as the KS0108 taking up extra pins, from what I have seen, it should be possible to make an Arduino (well, as an embedded ATMega) control the KS0108 using a library, and communicate the control protocol to it over SPI or I2C. I believe there are enough pins left over for such an interface, or even a simple bit-bang serial port.
One ATMega would handle the sampling, one would handle the screen/graphic rendering, and perhaps a third would handle user input (to leave the first with as much RAM as possible for the sample buffer).
Expertise with my code is not really needed. It just fills a 1k buffer. However I would not use two processors. Either a bigger CPU with more pins or a serial LCD should be used. Anything else is just complicating matters in my opinion. Once additional chips come into play DRAM and counters come to mind. But then it would immediately become just another logic analyzer project.