I spent the last few weeks working on a triggered high speed acquisition, and I think that my work is finally at a presentable level. And while experienced RedPitayans might be far from impressed by my few lines of code this project might be useful for other beginners like me, who are still trying to crawl from under our rocks.

The What:
I'm working on a program that would effectively turn my RP into a radiation spectrometer. The first stage - presented here - is a triggered acquisition ability. That means that RP continuously gathers input, until something interesting (say a high energy gamma photon crashing into a semiconductor detector) causes the input voltage to rise (or fall) above a certain threshold. At that time RP happily measures another N samples, and writes the whole thing down into a file. Then repeats the process as often as required, appending events to the file.

The Why:
You might ask: why not simply change the acquire.c to loop several times? That should do the job just as well, right?
It turns out that acquire is pretty slow, since it allows for more oscilloscope-related options and has a hard time sampling more than, say, 40 traces per second. My program is much faster, capable of sampling e.g. tens of thousands reasonably long traces per second.

and compile it. Just make sure you have the standard "fpga_osc" files nearby.

The How:
I tried to comment the code (trigger.c) as much as possible, so hopefully everyone will be able to figure out quickly what stuff is and how to adapt/upgrade the program to your needs. Still, feel free to ask, if there is anything unclear.

The Who:
Roger Daltrey, Pete Townshend on the guitar, John Entwistle on the bass and Keith Moon as the drummer.
As for the project: a thank you goes to Ales Bardorfer, John Smithe, Nils Roos and of course Matjaž Vencelj for your help so far.

many thanks for publishing your application. It is not usefull only in high energy gamma photon crashing into a semiconductor detector experiments. I try now to use your code in laser light reflection experiments form metal (gold and silver) nanoparticles in "pfysiological fluids".

My need is to sample 1024 to 4096 samples at 125MS/s with an externat trigger at >10kHz and simultaneously transfer the data through UDP. With your code and a standard UDP transfer, I can reach only 2kHz. This is limited by the time taken by the loop to get the data from the FPGA:

Hi, good to know people have the same purpose for this hardware as me .

So if I understand you correctly, you have set an internal trigger mechanism in the software to start recording when a rising edge (from your detector amplifier) exceeds a certain level? Does it behave like you expected?

I suppose you analyse the pulses afterwards using separate (off-line) peak shape analysis?

Thank you very much for the code of yours, Peter!
We are using this for an ultrasound pulse-echo application, so we need as much speed as possible. This is the fastest way we found it to be done thus far:

The way we do it is to dump the data from memory into TCP packets. (We tried with UDP packets, but data got lost. The TCP vs UDP speed was not significant.) This is a lot faster than going through for loops. The RAW data is then adjusted in LabVIEW instead of on the Red Pitaya.

We've also added input paramaters.

I am currently working on a way to store the data in 16 bit memory in the FPGA, but we are reaching the end of our bachelor thesis, so I have to prioritize writing a damn report now :/ If anyone finds a nice way to do this I would be very happy if you shared it This is my silly attempt thus far (red_pitaya_scope.v edited):

This is just a pure mess though... I have allmost no idea as to what I am doing since my FPGA skills are limited, and even more my Verilog skills. The idea was to load two sets of 16-bit data into the 32-bit memory instead of one... but this causes a lot of problem with control as to where the trigger happened, and the timing is off at some samples. (Data is stored in the wrong order).

Yes, that is correct, I have only implemented the first code I posted.

I am yet to find a good method of testing the rates I am getting, but if data is to be transfered from the Red Pitaya via ethernet this is the fastest method we have found thus far (TCP). UDP has been tested as well, but too many packets were lost. The rate has only been measured with a stop watch over a big sample and then calculating a mean value.

From what I understand this rate should be possible to easily double if data is stored in 16bit memory instead of 32bit memory in the FPGA, but my skills are far too limited at this time to achieve this.