Daqctl
daqctl is a userspace driver utility to manage the data acquisition core in the FPGA.
File:Daqctl-diagram.png |
Overview
Using daqctl you can have data acquisition control over TCP. The core allows you to set 2 different frequencies
Usage
Help
Usage: daqctl [OPTION] ... Technologic Systems ADC-7558 core userspace driver utility. Example: daqctl --server --speed=13khz --chan=0-3,5,7 --gain2x=5 -i, --irq=N Use IRQ N as ADC IRQ (30) -s, --speed=FREQ Use FREQ as default sample frequency (1000) -c, --chan=CHANS Sample only channels CHANS (0-15) -x, --exttrig=PIN Override --speed and use external trigger instead -g, --gain2x=CHANS Use high-gain setting on CHANS -l, --cloop=CHANS Enable 4-20 ma current loops on CHANS -d, --server Daemonize and run as server -I, --bind=IPADDR Bind server to IPADDR -p, --connect=HOST Connect to remote daqctl service at HOST -P, --dumpcsv Output acquired samples as CSV text -b, --dumpbin Output acquired samples as raw binary -1, --single Print one sample's values -D, --pwm=PWMSPEC Sets PWM outputs according to PWMSPEC -h, --help This help --irq-on-change=PIN Flush when digital input PIN (0-7) changes --irq-on-glitch=PIN Flush when digital input PIN (0-7) glitches --irq-on-high=PIN Flush while digital input PIN (0-7) is high --irq-on-low=PIN Flush while digital input PIN (0-7) is low --irq-on-quadrature Flush when a quadrature counter changes value --irq-on-quad-dir Flush when quadrature changes direction --irq-on-counter Flush when a monitored edge counter changes --irq-on-any-change Flush when any digital input changes --max-irq-rate=NSAM IRQ at most every NSAM (1,4,16,64) samples --max-irq-rate-always Always interrupt at max rate --min-irq-rate=HZ Minimum IRQ rate HZ (1000,500,100,0) --min-irq-rate-always Always interrupt at min rate
Examples
Even without writing code, you can do simple operations like sampling ADC or controlling the PWM channels.
For sampling ADC to a CSV file:
daqctl -c 1-4 -P
Turn all 7 PWM channels (0-6) off (0% duty) (OUT1-OUT4 external and pins 23, 21, and 25 on the JTAG header) and set default PWM
daqctl --pwm=0-6:0%@100hz
Programming with libdaqctl
We provide a library for the end user called libdaqctl that you can use to interact with the daqctl TCP server.
This board has one timer that you can easily set by ms or hz, and you can set the duty cycle by hz or percent. The configurable timer will support a maximum 131071hz. If you need another timer you can also use the ADC sample rate which is a static 2khz. You can use this by 'OR'ing in the value with the duty cycle.
Note: If you change the PWM frequency for one channel with the configurable timer, it will change it for any other channels using it.
Variable and ADC sample rates
This example shows using the configurable frequency and the ADC sample frequency on different channels, as well as sampling ADC channels 1 and 2.
#include <stdio.h>
#include <strings.h>
#include "libdaqctl.h"
void daq_print(struct daqctl *dq)
{
int i;
for(i = 3; i < 5; i++)
{
printf("chan%i=%i\n", i, dq->last[i]);
}
}
int main(int argc, char **argv)
{
int sk;
int i;
struct daqctl dq;
bzero(&dq, sizeof(dq));
// You can pass any arguments as you could to
// the daqctl application here. This example only samples
// ADC channels 1 and 2
sk = daqctl_connect("127.0.0.1", "--chan=4-5");
// Set channel 0 to 1khz with a duty cycle of 500khz
daqctl_setoutput(sk, 0, PWM_FREQ(0x1000) | PWM_DUTY(0x500));
// Set channel 1 to 2khz from ADC core
daqctl_setoutput(sk, 1, PWM_DUTY_PCT(100) | PWM_FREQ_IS_SAMPLERATE);
for(;;)
{
dq.fd = sk;
daqctl_process(&dq);
daq_print(&dq);
}
}
Controlling a Servo
In this example I've wired 5v in to OUT1+ (from JTAG pin 26 on the TS-7558), as well as the servo's + wire. OUT- and servo- are connected, and the servo's GND is plugged into one of the ground connectors in P2. The desired behavior is that the servo will rotate back and forth between maximum and minimum and reverting to neutral when a ctrl+c / SIGINT is sent to the application.
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include "libdaqctl.h"
int sigint_rec = 0;
void sigint_cb(int sig);
int main(int argc, char **argv)
{
char *host;
if(argc < 2)
host = "127.0.0.1";
else
host = argv[1];
int daqfd = daqctl_connect(
host,
"--pwm=0:100%@20ms");
assert(daqfd != 0);
signal(SIGINT, sigint_cb);
for(;;)
{
printf("Maximum\n");
daqctl_setoutput(daqfd, 0, PWM_DUTY(0x199)); // 2ms
sleep(1);
if(sigint_rec)
break;
printf("Minimum\n");
daqctl_setoutput(daqfd, 0, PWM_DUTY(0x51)); // 1ms
sleep(1);
if(sigint_rec)
break;
}
printf("Neutral\n");
daqctl_setoutput(daqfd, 0, PWM_DUTY(0xF5)); // 1.5ms
sleep(1);
close(daqfd);
return 0;
}
void sigint_cb(int sig)
{
sigint_rec = 1;
}