Re: [comedi] PWM - usbduxsigma
Ian Abbott <[email protected]> Wed, 6 Jul 2022 15:10:15 +0100
| Newsgroups | gmane.linux.comedi |
|---|---|
| Organization | MEV Ltd. |
| Message-ID | <[email protected]> |
On 06/07/2022 14:54, Ozan =C3=96gunc wrote:
> I am currently having a problem and wanted to ask you.
>=20
> 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.
>=20
> 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=
.
>=20
> =C2=A0 =C2=A0=C2=A0Gnd =3D pin 9 of the 15 pin connector
>=20
> =C2=A0 =C2=A0=C2=A0PWM =3D pin 1-8=C2=A0 ( all eight pins are checked)
>=20
> 2. The system log notes that the usb connection is successful:
>=20
> =C2=A0 =C2=A0 =C2=A0usb 1-3: new high-speed USB device number 8 using xh=
ci_hcd
> =C2=A0 =C2=A0 =C2=A0usb 1-3: New USB device found, idVendor=3D13d8, idPr=
oduct=3D0020,
> bcdDevice=3D 0.00
> =C2=A0 =C2=A0 =C2=A0usb 1-3: New USB device strings: Mfr=3D0, Product=3D=
0, SerialNumber=3D0
> =C2=A0 =C2=A0 =C2=A0comedi comedi0: ADC_zero =3D 800166
> =C2=A0 =C2=A0 =C2=A0comedi comedi0: driver 'usbduxsigma' has successfull=
y
> auto-configured 'usbduxsigma'.
>=20
> I would be very happy if you could help.
>=20
> Thank you for your time and consideration.
> Kind regards,
> OZAN
>=20
>=20
> #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>
>=20
>=20
> int main(int argc, char *argv[])
> {
> =C2=A0 int ret,i,help;
> =C2=A0 comedi_insn insn;
> =C2=A0 lsampl_t d[5];
> =C2=A0 comedi_t *device;
>=20
> =C2=A0 int freq;
> =C2=A0 int duty;
>=20
> =C2=A0 device =3D comedi_open("/dev/comedi0");
> =C2=A0 if(!device){
> =C2=A0 =C2=A0 fprintf(stderr,"Could not open comedi\n");
> =C2=A0 =C2=A0 exit(-1);
> =C2=A0 }
>=20
> =C2=A0 insn.insn=3DINSN_CONFIG;
> =C2=A0 insn.data=3Dd;
> =C2=A0 insn.subdev=3D3;
> =C2=A0 insn.chanspec=3DCR_PACK(0,0,0);
>=20
> =C2=A0 for(i=3D1; i<argc; ++i)
> =C2=A0 =C2=A0 {
> =C2=A0 =C2=A0 =C2=A0 if(!strcmp(argv[i], "-on")) {
> =C2=A0 =C2=A0 d[0] =3D INSN_CONFIG_ARM;
> =C2=A0 =C2=A0 d[1] =3D 0;
> =C2=A0 =C2=A0 //d[1] =3D 1; =C2=A0 =C2=A0// G=C3=BCrsoy
> =C2=A0 =C2=A0 insn.n=3D2;
> =C2=A0 =C2=A0 ret=3Dcomedi_do_insn(device,&insn);
> =C2=A0 =C2=A0 if(ret < 0){
> =C2=A0 =C2=A0 =C2=A0 fprintf(stderr,"Could sw on:%d\n",ret);
> =C2=A0 =C2=A0 =C2=A0 exit(-1);
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> =C2=A0 =C2=A0 =C2=A0 }
>=20
> =C2=A0 =C2=A0 =C2=A0 if(!strcmp(argv[i], "-off")) {
> =C2=A0 =C2=A0 d[0] =3D INSN_CONFIG_DISARM;
> =C2=A0 =C2=A0 d[1] =3D 0;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 insn.n=3D1;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ret=3Dcomedi_do_insn(device,&i=
nsn);
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if(ret < 0){
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr,"Could s=
w on:%d\n",ret);
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 exit(-1);
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> =C2=A0 =C2=A0 =C2=A0 }
>=20
> =C2=A0 =C2=A0 =C2=A0 if(!strcmp(argv[i], "-duty")) duty =3D atoi(argv[i+=
1]);
> =C2=A0 =C2=A0 =C2=A0 if(!strcmp(argv[i], "-help")) help =3D 1;
> =C2=A0 =C2=A0 }
> =C2=A0 if(help)
> =C2=A0 =C2=A0 {
> =C2=A0 =C2=A0 =C2=A0 printf("-------------------------------------------=
---\n");
> =C2=A0 =C2=A0 =C2=A0 printf("-on/-off \t Turn PWM on/off\n");
> =C2=A0 =C2=A0 =C2=A0 printf("-freq \t \t Adjust frequency\n");
> =C2=A0 =C2=A0 =C2=A0 printf("-duty \t \t Adjust duty cycle\n");
> =C2=A0 =C2=A0 =C2=A0 printf("-------------------------------------------=
---\n");
> =C2=A0 =C2=A0 =C2=A0 exit(0);
> =C2=A0 =C2=A0 }
> =C2=A0 printf("-duty =3D%d\n", duty );
>=20
> =C2=A0 int channel=3D0;
> =C2=A0 // it's 0..511
> =C2=A0 comedi_data_write(device,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 4,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 channel,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 duty);
> =C2=A0 comedi_data_write(device,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 4,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 channel+1,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 400);
> =C2=A0 comedi_data_write(device,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 4,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 channel+2,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 100);
> =C2=A0 comedi_data_write(device,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 4,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 channel+3,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 200);
I'm not that familiar with the device[*], but those comedi_data_write()=20
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=20
destroyed in an office fire!
--=20
-=3D( Ian Abbott <[email protected]> || MEV Ltd. is a company )=3D-
-=3D( registered in England & Wales. Regd. number: 02862268. )=3D-
-=3D( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=3D-
-=3D( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=3D-
--=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/a9e014c4-8959-7802-1058-bf38674fd7e2%40mev.co.uk.