Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading 16-bit ports
#1
Hi All,

I am trying to capture data from an Advantech PCI-1710 DAS card and am having a little trouble. The data I am trying to read resides in two 8-bit wide registers, but I find that only the first one I read is valid (ie I can see it change as my A/D input changes). Here is my full program listing

'A program to validate the A/D capabilites of an Advantech PCI-1710
'DAS card.

CONST b = &HE400 'pci-1710 base address
CONST a2dlow = b + 0 'result low byte
CONST a2dhigh = b + 1 'result high byte
CONST a2drange = b + 2 'channel range
CONST a2dmuxstart = b + 4 'mux scan start channel
CONST a2dmuxstop = b + 5 'mux scan stop channel
CONST a2dcontrol = b + 6 'a/d control bits
CONST a2dstatus = b + 7 'a/d interrupt and FIFO status
CONST a2dinterrupt = b + 8 'clear interrupt
CONST a2dfifo = b + 9 'clear FIFO

OUT a2dmuxstart, 0 'channel 0
OUT a2dmuxstop, 0 'channel 0
OUT a2drange, 4 'range [-10,+10]
OUT a2dmuxstart, 0 'added due to confusion regarding setting
OUT a2dmuxstop, 0 'the gain before the mux channels

OUT a2dcontrol, 0 'disable int and sw trigger
OUT a2dfifo, 0 'clear fifo
OUT a2dinterrupt, 0 'clear interrupt

DO
OUT a2dcontrol, 17 'enable int and sw
OUT a2dlow, 0 'start conversion
WAIT a2dstatus, 8 'wait for interrupt
OUT a2dcontrol, 1 'disable int

PRINT INP(a2dhigh), INP(a2dlow)

PLAY "n0"
PLAY "L64T255"

OUT a2dinterrupt, 0 'clear interrupt
OUT a2dfifo, 0 'clear fifo

LOOP UNTIL INKEY$ <> ""

What I would like to be able to do is read a2dhigh and a2dlow in one operation (they are stored in a 16-bit wide fifo) to see if that fixes the problem. Is there any way to grab 16-bits in one operation using QB? Sorry if this is a simplistic question but I am a QB n00b. Any help would be greatly appreciated...
Reply
#2
Hi, It seems noone has replied to your post for a long time =P. Your question is simplistic. But the h/w part has made it quite difficult. I think here is the problem.

PRINT INP(a2dhigh), INP(a2dlow).

IMHO, you are actually reading from two different ports. Try reading from the same port i.e. 0xE400.

low% = INP(&HE400)
high% = INP(&HE400)

I think that should solve your problem.
Reply
#3
Yeah,

Thanks for the reply. Unfortunately I have already tried a double read from the same address with no success. What happens is that you get one valid byte (say I am double reading the low% byte, then I get a good low%) followed by garbage.

I am sure the answer to this problem is quite simple, but I am currently cannot see the woods for the trees!
Reply
#4
Hrm...have you looked up the example for INP function in qb 7.1's help? It has a example which does something similar that you want to do but with the pc-speaker. I think i have tried reading the hibyte and lobyte using a double read and it works. You should study that example and maybe you'll get some idea from it =).
Reply
#5
Thanks for the tip - I am using QB 4.5 so will try to track down the example and have a look at it...
Reply
#6
http://qbasicnews.com/qboho/qckinp.shtml
That should do. :wink:
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#7
BTW I forgot to ask you what is "Advantech PCI-1710 DAS card" this card?
Reply
#8
Its just a cheap 12-bit A/D card that also had two D/A channels onboard as well as 16 channels of digitial I/O. Made by a company called Advantech.
Reply
#9
Have you tried finding Linux drivers for it? They are mostly written in C/C++, so you could see some actual code. It will give you some idea.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)