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!
Executing command sequence from memory
-
- Posts: 1441
- Joined: Sat Jun 07, 2014 12:49 pm
- Location: Königswinter
Re: Executing command sequence from memory
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 ?
Or maybe I misunderstand you and you are actually talking about scpi calls ?
-
- Posts: 8
- Joined: Wed Feb 17, 2016 7:27 pm
Re: Executing command sequence from memory
Hi, thank you for the reply. The code I was executing was as follows
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.
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;
}
-
- Posts: 1441
- Joined: Sat Jun 07, 2014 12:49 pm
- Location: Königswinter
Re: Executing command sequence from memory
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.
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.
-
- Posts: 8
- Joined: Wed Feb 17, 2016 7:27 pm
Re: Executing command sequence from memory
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.
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.
-
- Posts: 15
- Joined: Thu Feb 04, 2016 10:42 am
Re: Executing command sequence from memory
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.
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.
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