[comedi] PWM - usbduxsigma

Ozan Ă–gunc <[email protected]> Wed, 6 Jul 2022 06:54:18 -0700 (PDT)
Newsgroups gmane.linux.comedi
Message-ID <[email protected]>
------=_Part_8764_965262139.1657115658867
Content-Type: multipart/alternative; 
	boundary="----=_Part_8765_757363224.1657115658867"

------=_Part_8765_757363224.1657115658867
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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=20
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 =3D pin 9 of the 15 pin connector

    PWM =3D 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=3D13d8, idProduct=3D0020,
bcdDevice=3D 0.00
     usb 1-3: New USB device strings: Mfr=3D0, Product=3D0, SerialNumber=3D=
0
     comedi comedi0: ADC_zero =3D 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;
 =20
  int freq;
  int duty;
 =20
  device =3D comedi_open("/dev/comedi0");
  if(!device){
    fprintf(stderr,"Could not open comedi\n");
    exit(-1);
  }
 =20
  insn.insn=3DINSN_CONFIG;
  insn.data=3Dd;
  insn.subdev=3D3;
  insn.chanspec=3DCR_PACK(0,0,0);
 =20
  for(i=3D1; i<argc; ++i)
    {
      if(!strcmp(argv[i], "-on")) {
    d[0] =3D INSN_CONFIG_ARM;
    d[1] =3D 0;
    //d[1] =3D 1;    // G=C3=BCrsoy
    insn.n=3D2;
    ret=3Dcomedi_do_insn(device,&insn);
    if(ret < 0){
      fprintf(stderr,"Could sw on:%d\n",ret);
      exit(-1);
            }
      }
     =20
      if(!strcmp(argv[i], "-off")) {
    d[0] =3D INSN_CONFIG_DISARM;
    d[1] =3D 0;
            insn.n=3D1;
            ret=3Dcomedi_do_insn(device,&insn);
            if(ret < 0){
              fprintf(stderr,"Could sw on:%d\n",ret);
              exit(-1);
            }
      }

      if(!strcmp(argv[i], "-duty")) duty =3D atoi(argv[i+1]);
      if(!strcmp(argv[i], "-help")) help =3D 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 =3D%d\n", duty );
 =20
  int channel=3D0;
  // it's 0..511
  comedi_data_write(device,
            4,=20
            channel,
            0,
            0,
            duty);
  comedi_data_write(device,
            4,=20
            channel+1,
            0,
            0,
            400);
  comedi_data_write(device,
            4,=20
            channel+2,
            0,
            0,
            100);
  comedi_data_write(device,
            4,=20
            channel+3,
            0,
            0,
            200);
 =20
  return 0;
}

--=20
You received this message because you are subscribed to the Google Groups "=
Comedi: Linux Control and Measurement Device Interface" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
comedi_list/97da856b-025f-49df-b810-9e17c4c006b5n%40googlegroups.com.

------=_Part_8765_757363224.1657115658867
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div><div>I am currently having a problem and wanted to ask you.<br></div><=
div><br></div><div>I tried to setup and configure a pwm drive by using usbd=
uxsigma. I have</div><div>a current driver, but I do not get a signal from =
the usbduxsigma. Below&nbsp;</div><div>is my code. It compiles fine, but wi=
thout any output.</div><div><br></div><div>1. The example file pwm_0.c is s=
imply taken from the</div><div>"code-examples/pwm.c". It compiles alright. =
It also runs. However, when</div><div>I connect the oscilloscope to any of =
these outputs, no signal can be seen.</div><div><br></div><div>&nbsp; &nbsp=
;&nbsp;Gnd =3D pin 9 of the 15 pin connector</div><div><br></div><div>&nbsp=
; &nbsp;&nbsp;PWM =3D pin 1-8&nbsp; ( all eight pins are checked)</div><div=
><br></div><div>2. The system log notes that the usb connection is successf=
ul:</div><div><br></div><div>&nbsp; &nbsp; &nbsp;usb 1-3: new high-speed US=
B device number 8 using xhci_hcd</div><div>&nbsp; &nbsp; &nbsp;usb 1-3: New=
 USB device found, idVendor=3D13d8, idProduct=3D0020,</div><div>bcdDevice=
=3D 0.00</div><div>&nbsp; &nbsp; &nbsp;usb 1-3: New USB device strings: Mfr=
=3D0, Product=3D0, SerialNumber=3D0</div><div>&nbsp; &nbsp; &nbsp;comedi co=
medi0: ADC_zero =3D 800166</div><div>&nbsp; &nbsp; &nbsp;comedi comedi0: dr=
iver 'usbduxsigma' has successfully</div><div>auto-configured 'usbduxsigma'=
.</div></div><div><br></div><div>I would be very happy if you could help.<b=
r></div><div><br></div><div><div>Thank you for your time and consideration.=
</div><div>Kind regards,</div><div>OZAN</div></div><div><br></div><div><br>=
</div><div>#include &lt;stdio.h&gt;<br>#include &lt;comedilib.h&gt;<br>#inc=
lude &lt;fcntl.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;stdlib.h&=
gt;<br>#include &lt;errno.h&gt;<br>#include &lt;getopt.h&gt;<br>#include &l=
t;ctype.h&gt;<br>#include &lt;string.h&gt;<br><br><br>int main(int argc, ch=
ar *argv[])<br>{<br>&nbsp; int ret,i,help;<br>&nbsp; comedi_insn insn;<br>&=
nbsp; lsampl_t d[5];<br>&nbsp; comedi_t *device;<br>&nbsp; <br>&nbsp; int f=
req;<br>&nbsp; int duty;<br>&nbsp; <br>&nbsp; device =3D comedi_open("/dev/=
comedi0");<br>&nbsp; if(!device){<br>&nbsp; &nbsp; fprintf(stderr,"Could no=
t open comedi\n");<br>&nbsp; &nbsp; exit(-1);<br>&nbsp; }<br>&nbsp; <br>&nb=
sp; insn.insn=3DINSN_CONFIG;<br>&nbsp; insn.data=3Dd;<br>&nbsp; insn.subdev=
=3D3;<br>&nbsp; insn.chanspec=3DCR_PACK(0,0,0);<br>&nbsp; <br>&nbsp; for(i=
=3D1; i&lt;argc; ++i)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; if(!strcmp=
(argv[i], "-on")) {<br>&nbsp; &nbsp; d[0] =3D INSN_CONFIG_ARM;<br>&nbsp; &n=
bsp; d[1] =3D 0;<br>&nbsp; &nbsp; //d[1] =3D 1; &nbsp; &nbsp;// G=C3=BCrsoy=
<br>&nbsp; &nbsp; insn.n=3D2;<br>&nbsp; &nbsp; ret=3Dcomedi_do_insn(device,=
&amp;insn);<br>&nbsp; &nbsp; if(ret &lt; 0){<br>&nbsp; &nbsp; &nbsp; fprint=
f(stderr,"Could sw on:%d\n",ret);<br>&nbsp; &nbsp; &nbsp; exit(-1);<br>&nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp;=
 &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; if(!strcmp(argv[i], "-off")) {<br>&=
nbsp; &nbsp; d[0] =3D INSN_CONFIG_DISARM;<br>&nbsp; &nbsp; d[1] =3D 0;<br>&=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; insn.n=3D1;<br>&nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; ret=3Dcomedi_do_insn(device,&amp;insn);<br>&nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; if(ret &lt; 0){<br>&nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; fprintf(stderr,"Could sw on:%d\n",ret);<br>&nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit(-1);<br>&nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nb=
sp; if(!strcmp(argv[i], "-duty")) duty =3D atoi(argv[i+1]);<br>&nbsp; &nbsp=
; &nbsp; if(!strcmp(argv[i], "-help")) help =3D 1;<br>&nbsp; &nbsp; }<br>&n=
bsp; if(help)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; printf("----------=
------------------------------------\n");<br>&nbsp; &nbsp; &nbsp; printf("-=
on/-off \t Turn PWM on/off\n");<br>&nbsp; &nbsp; &nbsp; printf("-freq \t \t=
 Adjust frequency\n");<br>&nbsp; &nbsp; &nbsp; printf("-duty \t \t Adjust d=
uty cycle\n");<br>&nbsp; &nbsp; &nbsp; printf("----------------------------=
------------------\n");<br>&nbsp; &nbsp; &nbsp; exit(0);<br>&nbsp; &nbsp; }=
<br>&nbsp; printf("-duty =3D%d\n", duty );<br>&nbsp; <br>&nbsp; int channel=
=3D0;<br>&nbsp; // it's 0..511<br>&nbsp; comedi_data_write(device,<br>&nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; channel,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp; duty);<br>&nbsp; comedi_data_write(device,<br>&nbsp; &nbsp; &nbs=
p; &nbsp; &nbsp; &nbsp; 4, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ch=
annel+1,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
400);<br>&nbsp; comedi_data_write(device,<br>&nbsp; &nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; 4, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channel+2,<br>=
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 100);<br>&nb=
sp; comedi_data_write(device,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
4, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; channel+3,<br>&nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbs=
p; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 200);<br>&nbsp; <br>&nbs=
p; return 0;<br>}<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Comedi: Linux Control and Measurement Device Interface&quot; group.<br=
 />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">comedi_=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/comedi_list/97da856b-025f-49df-b810-9e17c4c006b5n%40googlegroups=
.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/ms=
gid/comedi_list/97da856b-025f-49df-b810-9e17c4c006b5n%40googlegroups.com</a=
>.<br />

------=_Part_8765_757363224.1657115658867--

------=_Part_8764_965262139.1657115658867--