PWM - usbduxsigma

1 view
Skip to first unread message

Ozan Ögunc

unread,
Jul 6, 2022, 9:54:19 AMJul 6
to Comedi: Linux Control and Measurement Device Interface
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;
}

Ian Abbott

unread,
Jul 6, 2022, 10:10:19 AMJul 6
to comed...@googlegroups.com, Ozan Ögunc
I'm not that familiar with the device[*], but those comedi_data_write()
calls are writing to a non-existent subdevice 4. It should be subdevice 3.

[*] Bernd Porr sent me one about a decade ago, but unfortunately it got
destroyed in an office fire!

--
-=( Ian Abbott <abb...@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-

Bernd Porr

unread,
Jul 6, 2022, 5:36:55 PMJul 6
to comed...@googlegroups.com
Oh yes. It should be subdevice 3. Can you try that?

/Bernd

bp1@bp1-Precision-WorkStation-T5400:~/nn$ comedi_board_info
overall info:
  version code: 0x00074c
  driver name: usbduxsigma
  board name: usbduxsigma
  number of subdevices: 4
subdevice 0:
  type: 1 (analog input)
  flags: 0x10119000
  number of channels: 16
  max data value: 16777215
  ranges:
    all chans: [-1.33333 V,1.33333 V]
  command:
    start: now|int
    scan_begin: timer
    convert: now
    scan_end: count
    stop: none|count
  command structure filled with probe_cmd_generic_timed for 1 channels:
    start: now 0
    scan_begin: timer 250000
    convert: now 0
    scan_end: count 1
    stop: count 2
subdevice 1:
  type: 2 (analog output)
  flags: 0x00125000
  number of channels: 4
  max data value: 255
  ranges:
    all chans: [0 V,2.5 V]
  command:
    start: now|int
    scan_begin: timer
    convert: now
    scan_end: count
    stop: none|count
  command structure filled with probe_cmd_generic_timed for 1 channels:
    start: now 0
    scan_begin: timer 1000000
    convert: now 0
    scan_end: count 1
    stop: count 2
subdevice 2:
  type: 5 (digital I/O)
  flags: 0x00030000
  number of channels: 24
  max data value: 1
  ranges:
    all chans: [0 V,5 V]
  command:
    not supported
subdevice 3:
  type: 12 (pwm)
  flags: 0x00020100
  number of channels: 8
  max data value: 512
  ranges:
    all chans: [0,1]
  command:
    not supported
bp1@bp1-Precision-WorkStation-T5400:~/nn$
www: http://www.berndporr.me.uk
http://www.tinnitustailor.tech
http://www.attys.tech
Mobile: +44 (0)7840 340069
Work: +44 (0)141 330 5237
University of Glasgow
School of Engineering
Rankine Building, Oakfield Avenue,
Glasgow, G12 8LT

Reply all
Reply to author
Forward
0 new messages