[comedi] PWM configuration on advantech PCI1760
Federico Alfatti <[email protected]> Mon, 19 Dec 2022 07:11:20 -0800 (PST)
| Newsgroups | gmane.linux.comedi |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_3718_493979409.1671462680476
Content-Type: multipart/alternative;
boundary="----=_Part_3719_76029824.1671462680476"
------=_Part_3719_76029824.1671462680476
Content-Type: text/plain; charset="UTF-8"
Hello everybody,
I hope that there is someone here that can help me.
I am trying to generate a PWM signal from the advantech PCI1760 card. I am
using Ubuntu 22.04.1 LTS.
Running the following code:
/sbin/modprobe comedi
/sbin/modprobe pci1760
/usr/sbin/comedi_config /dev/comedi0 pci1760
The last command returns that the device is already configured.
At this point, taking inspiration from the pwm.c file from comedilib demo
folder, I am trying to configure the PWM channel via instructions and then
sending a comedi_data_write, but it seems to not accept my inputs: the
function comedi_do_insn always returns error, no matter what INSN_CONFIG I
am using.
The device is correctely installed because I am able to both read and write
on the other two DI/DO subdevices. However, I reckon I might be missing
something on the INSN_CONFIG command for the pwm.
I attach the comedi_board_info results and the code I am running.
The "max data value" associated with the PWM subdevice 2 is 0, which seems
strange to me: for my understanding, this value should represent the
maximum resolution for the PWM, which in this specific case should be 2^16
(65535).
Lastly, I read a "SDF_MODE0: can do mode 0". This should be an indication
to the possible counter mode, UP_COUNTER? Is there something that I am
missing or that I am not configuring?
Is there anybody that could help, or that have some specific experience
with the PWM control of this board? It would be really useful since I am
struggling on this problem, and I am not able to find any documentation
that could help me.
Thank you very much for your time,
Kind regards,
Federico
//////////////////// comedi_board_info -v ////////////////////////
overall info:
version code: 0x00074c
driver name: adv_pci1760
board name: adv_pci1760
number of subdevices: 4
subdevice 0:
type: 3 (digital input)
flags: 0x00010000
SDF_READABLE:subdevice can be read
number of channels: 8
max data value: 1
ranges:
all chans: [0 V,5 V]
command:
not supported
subdevice 1:
type: 4 (digital output)
flags: 0x00020000
SDF_WRITABLE:subdevice can be written
number of channels: 8
max data value: 1
ranges:
all chans: [0 V,5 V]
command:
not supported
subdevice 2:
type: 12 (pwm)
flags: 0x00000080
SDF_MODE0:can do mode 0
number of channels: 2
max data value: 0
ranges:
all chans: [0,1]
command:
not supported
subdevice 3:
type: 0 (unused)
//////////////////////////////PROGRAM/////////////////////////////////////////
#include <stdio.h>
#include <comedilib.h>
#define N_SAMPLE 3
char *filename="/dev/comedi0";
comedi_t *device;
int subdevice = 2;
int channel = 0;
int aref;
int range = 0;
int main(int argc, char *argv[])
{
lsampl_t data[N_SAMPLE];
int ret, i;
int n_channels, n_range;
device = comedi_open(filename);
if(!device){
printf("E: comedi_open(\"%s\") NOT SUCCESSFUL",filename);
}
/*Configure PWM*/
comedi_insn insn;
data[0] = INSN_CONFIG_ARM;
data[1] = 0;
insn.subdev = subdevice;
insn.insn = INSN_CONFIG;
insn.n = 3;
insn.chanspec = CR_PACK(channel, range, 0);
insn.data = data;
ret = comedi_do_insn(device,&insn); //This command is always returning -1
printf("\n\nconfig arm %d\n\n",ret);
/* Activate PWM */
ret = comedi_data_write(device,subdevice,channel,0,0,10); //This command is
always returning -1
printf("write %d\n\n",ret);
comedi_close(device);
return 0;
}
--
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 email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/comedi_list/bd8b69a4-3d3d-478a-917c-7e739bc3da13n%40googlegroups.com.
------=_Part_3719_76029824.1671462680476
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello everybody, <div>I hope that there is someone here that can help =
me. </div><div><br></div><div>I am trying to generate a PWM signal fro=
m the advantech PCI1760 card. I am using Ubuntu 22.04.1 LTS. </div><di=
v>Running the following code: </div><div><br></div><div>/sbin/mo=
dprobe comedi</div><div>/sbin/modprobe pci1760</div><div>/usr/sbin/comedi_c=
onfig /dev/comedi0 pci1760</div><div><br></div><div>The last command return=
s that the device is already configured. </div><div><br></div><div>At =
this point, taking inspiration from the pwm.c file from comedilib demo fold=
er, I am trying to configure the PWM channel via instructions and then send=
ing a comedi_data_write, but it seems to not accept my inputs: the function=
comedi_do_insn always returns error, no matter what INSN_CONFIG I am using=
. </div><div><br></div><div>The device is correctely installed because=
I am able to both read and write on the other two DI/DO subdevices. Howeve=
r, I reckon I might be missing something on the INSN_CONFIG command for the=
pwm. </div><div>I attach the comedi_board_info results and the code I=
am running. </div><div>The "max data value" associated with the PWM s=
ubdevice 2 is 0, which seems strange to me: for my understanding, this valu=
e should represent the maximum resolution for the PWM, which in this specif=
ic case should be 2^16 (65535). </div><div><br></div><div>Lastly, I re=
ad a "SDF_MODE0: can do mode 0". This should be an indication to the possib=
le counter mode, UP_COUNTER? Is there something that I am missing or =
that I am not configuring?</div><div><br></div><div>Is there anybody that c=
ould help, or that have some specific experience with the PWM control of th=
is board? It would be really useful since I am struggling on this problem, =
and I am not able to find any documentation that could help me. </div>=
<div><br></div><div>Thank you very much for your time, </div><div>Kind=
regards, </div><div><br></div><div>Federico </div><div><br></div=
><div>//////////////////// comedi_board_info -v ////////////////////////</d=
iv><div><br></div><div><div><div>overall info:</div><div> version cod=
e: 0x00074c</div><div> driver name: adv_pci1760</div><div> boar=
d name: adv_pci1760</div><div> number of subdevices: 4</div><div>subd=
evice 0:</div><div> type: 3 (digital input)</div><div> flags: 0=
x00010000</div><div> SDF_READABLE:subdevi=
ce can be read</div><div> number of channels: 8</div><div> max =
data value: 1</div><div> ranges:</div><div> all chans: [=
0 V,5 V]</div><div> command:</div><div> not supported</d=
iv><div>subdevice 1:</div><div> type: 4 (digital output)</div><div>&n=
bsp; flags: 0x00020000</div><div> SDF_WRI=
TABLE:subdevice can be written</div><div> number of channels: 8</div>=
<div> max data value: 1</div><div> ranges:</div><div> &nb=
sp; all chans: [0 V,5 V]</div><div> command:</div><div> =
not supported</div><div>subdevice 2:</div><div> type: 12 (pwm)</div><=
div> flags: 0x00000080</div><div> S=
DF_MODE0:can do mode 0</div><div> number of channels: 2</div><div>&nb=
sp; max data value: 0</div><div> ranges:</div><div> all =
chans: [0,1]</div><div> command:</div><div> not supporte=
d</div><div>subdevice 3:</div><div> type: 0 (unused)</div><br></div><=
/div><div><br></div><div>//////////////////////////////PROGRAM/////////////=
////////////////////////////</div><div><br></div><div><div>#include <std=
io.h></div><div>#include <comedilib.h></div><div>#define N_SAMPLE =
3</div><br><div>char *filename=3D"/dev/comedi0";</div><div>comedi_t *device=
;</div><div>int subdevice =3D 2;</div><div>int channel =3D 0;</div><div>int=
aref;</div><div>int range =3D 0;</div><br><div>int main(int argc, char *ar=
gv[])</div><div>{</div><div>lsampl_t data[N_SAMPLE];</div><div><br></div><d=
iv>int ret, i;</div><div><br></div><div>int n_channels, n_range;</div><br><=
div>device =3D comedi_open(filename);</div><div>if(!device){</div><div>prin=
tf("E: comedi_open(\"%s\") NOT SUCCESSFUL",filename);</div><div>}</div><br>=
<div>/*Configure PWM*/</div><div>comedi_insn insn;</div><br><div>data[0] =
=3D INSN_CONFIG_ARM;</div><div>data[1] =3D 0;</div><div> </div=
><div> insn.subdev =3D subdevice;</div><div> insn=
.insn =3D INSN_CONFIG;</div><div> insn.n =3D 3;</div><div>&nbs=
p; insn.chanspec =3D CR_PACK(channel, range, 0);</div><div> &n=
bsp; insn.data =3D data;</div><br><div>ret =3D comedi_do_insn(device,&i=
nsn); //This command is always returning -1</div><div>printf("\n\nconfig ar=
m %d\n\n",ret);</div><br><div>/* Activate PWM */</div><div>ret =3D comedi_d=
ata_write(device,subdevice,channel,0,0,10); //This command is always return=
ing -1</div><div>printf("write %d\n\n",ret);</div><br><div>comedi_close(dev=
ice);</div><div>return 0;</div><div>}</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Comedi: Linux Control and Measurement Device Interface" 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/bd8b69a4-3d3d-478a-917c-7e739bc3da13n%40googlegroups=
.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/ms=
gid/comedi_list/bd8b69a4-3d3d-478a-917c-7e739bc3da13n%40googlegroups.com</a=
>.<br />
------=_Part_3719_76029824.1671462680476--
------=_Part_3718_493979409.1671462680476--