I am currently having a problem and wanted to ask you.
I tried to setup and configure a pwm drive by using usbduxsigma. I have
a current driver, but I do not get a signal from the usbduxsigma. Below
is my code. It compiles fine, but without any output.
1. The example file pwm_0.c is simply taken from the
"code-examples/pwm.c". It compiles alright. It also runs. However, when
I connect the oscilloscope to any of these outputs, no signal can be seen.
Gnd = pin 9 of the 15 pin connector
PWM = pin 1-8 ( all eight pins are checked)
2. The system log notes that the usb connection is successful:
usb 1-3: new high-speed USB device number 8 using xhci_hcd
usb 1-3: New USB device found, idVendor=13d8, idProduct=0020,
bcdDevice= 0.00
usb 1-3: New USB device strings: Mfr=0, Product=0, SerialNumber=0
comedi comedi0: ADC_zero = 800166
comedi comedi0: driver 'usbduxsigma' has successfully
auto-configured 'usbduxsigma'.
I would be very happy if you could help.
Thank you for your time and consideration.
Kind regards,
OZAN
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <string.h>
int main(int argc, char *argv[])
{
int ret,i,help;
comedi_insn insn;
lsampl_t d[5];
comedi_t *device;
int freq;
int duty;
device = comedi_open("/dev/comedi0");
if(!device){
fprintf(stderr,"Could not open comedi\n");
exit(-1);
}
insn.insn=INSN_CONFIG;
insn.data=d;
insn.subdev=3;
insn.chanspec=CR_PACK(0,0,0);
for(i=1; i<argc; ++i)
{
if(!strcmp(argv[i], "-on")) {
d[0] = INSN_CONFIG_ARM;
d[1] = 0;
//d[1] = 1; // Gürsoy
insn.n=2;
ret=comedi_do_insn(device,&insn);
if(ret < 0){
fprintf(stderr,"Could sw on:%d\n",ret);
exit(-1);
}
}
if(!strcmp(argv[i], "-off")) {
d[0] = INSN_CONFIG_DISARM;
d[1] = 0;
insn.n=1;
ret=comedi_do_insn(device,&insn);
if(ret < 0){
fprintf(stderr,"Could sw on:%d\n",ret);
exit(-1);
}
}
if(!strcmp(argv[i], "-duty")) duty = atoi(argv[i+1]);
if(!strcmp(argv[i], "-help")) help = 1;
}
if(help)
{
printf("----------------------------------------------\n");
printf("-on/-off \t Turn PWM on/off\n");
printf("-freq \t \t Adjust frequency\n");
printf("-duty \t \t Adjust duty cycle\n");
printf("----------------------------------------------\n");
exit(0);
}
printf("-duty =%d\n", duty );
int channel=0;
// it's 0..511
comedi_data_write(device,
4,
channel,
0,
0,
duty);
comedi_data_write(device,
4,
channel+1,
0,
0,
400);
comedi_data_write(device,
4,
channel+2,
0,
0,
100);
comedi_data_write(device,
4,
channel+3,
0,
0,
200);
return 0;
}