Executing command sequence from memory

Just about everything about Red Pitaya
Post Reply
oliverburrow
Posts: 8
Joined: Wed Feb 17, 2016 7:27 pm

Executing command sequence from memory

Post by oliverburrow » Wed Mar 16, 2016 7:08 pm

I've been using a Red pitaya to try do useful things in a lab setting. To do this I've been using the API commands in C. I've noticed the commands have about a 70 us delay between issuing commands and their execution.

What do I need to do to be able to load a sequence of commands into memory, and execute them? One of the applications I have in mind would use the GPIO pins as digital control, ideally on the microsecond time scale or better, with the ability to issue commands simultaneously, e.g. turning pin 1 and 2 on at the same time with microsecond timing.

Any advice would be appreciated!

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Executing command sequence from memory

Post by Nils Roos » Wed Mar 16, 2016 9:20 pm

Could you give a code example with which to observe the latency ? There is practically zero overhead in the C API functions that address the GPIOs.

Or maybe I misunderstand you and you are actually talking about scpi calls ?

oliverburrow
Posts: 8
Joined: Wed Feb 17, 2016 7:27 pm

Re: Executing command sequence from memory

Post by oliverburrow » Mon Mar 21, 2016 3:33 pm

Hi, thank you for the reply. The code I was executing was as follows

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "redpitaya/rp.h"

int main (int argc, char **argv) {

	// Initialization of API
	if (rp_Init() != RP_OK) {
		fprintf(stderr, "Red Pitaya API init failed!\n");
		return EXIT_FAILURE;
	}

	rp_DpinSetDirection(RP_DIO7_N,RP_OUT);

	for(int i = 0 ; i < 1e1;i++){
		rp_DpinSetState(RP_DIO7_N, RP_HIGH);
		usleep(10);
		rp_DpinSetState(RP_DIO7_N, RP_LOW);
		usleep(40);
	}

	// Releasing resources
	rp_Release();

	return EXIT_SUCCESS;
}

I measured the result on an oscilloscope and the time on is 75.6 us and 0 V is 105.8 us, where I wanted it to be 10 us on and 40 us 0 V.

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Executing command sequence from memory

Post by Nils Roos » Mon Mar 21, 2016 9:31 pm

Well, you can't really expect precision timing with usleep(). It is guaranteed to wait at least the amount of time given - unless a signal interrupts it - but may wait longer, depending on system load, the resolution of the system timer, etc.

Try just toggling the pin without sleeping - I did and got a constant frequency of about 1MHz, so the actual latency of the API call is somewhere close to 500ns.

oliverburrow
Posts: 8
Joined: Wed Feb 17, 2016 7:27 pm

Re: Executing command sequence from memory

Post by oliverburrow » Tue Mar 22, 2016 1:04 pm

Ok, that's good to know. Could you recommend a method of dead time into the sequence reliably then? For example, to create the pulse of 10 microseconds on, 40 microseconds off as I was trying to do?

Ideally I would like to be able create a sequence in a buffer to implement them commands at specific times, even simultaenously. I've seen this done before, with a different FPGA dev board, but I'm unsure of how it was implemented. If you could point me in the right direction on how to begin doing this, I would be very grateful.

Thank you for your help so far.

Ubix2014
Posts: 15
Joined: Thu Feb 04, 2016 10:42 am

Re: Executing command sequence from memory

Post by Ubix2014 » Tue Mar 22, 2016 8:27 pm

2 oliverburrow

Up to me, the best way to make such a pulse generator is to modify the FPGA code. With this you will get the highest precision. The pulse generator can be based on two counters: one for the pulse duration, the second for the pulse period. Then, you have to decide how you want to specify the values of these two counters. You can hardcode them in the Verilog code. This is the simplest solution, but requires new synthesizing of the FPGA code if you need to change the counters' values. Better way is to use some unused registers in, for example, house keeping module. This will also require to write some new C code and rebuilding the API library.

Another solution is to embed the pulse generator in the existing modules, like PID, and use PID parameters to control the pulse generator. For example, Kp of PID11 can be used for the pulse duration, Ki for the pulse period. In this case, you only need to change the FPGA code and you will be able to control your pulse generator with the Web Application. Not very elegant solution, but Ok if you need something urgently.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 130 guests