libftdi Archives

Subject: FW: FTDI 4232H and TI ADS7871 A/D Converter

From: "Michael Plante" <michael.plante@xxxxxxxxx>
To: "libftdi devel" <libftdi@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 18 Apr 2011 21:04:47 -0400
Ok, I see you have posted to the list, so I'm forwarding my reply... sorry about the html, but it's in my original response, so preserved...
 
 
 
-----Original Message-----
From: Michael Plante [mailto:michael.plante@xxxxxxxxx]
Sent: Monday, April 18, 2011 9:04 PM
To: Tumer TOPCU
Subject: RE: FTDI 4232H and TI ADS7871 A/D Converter

Hi Tumer,
 
Please use the mailing list for libftdi-related issues, and contact FTDI itself for the FTDI-proprietary drivers.  I can only help with the former, and, if you choose to go that route, it'd be nice if everyone can benefit from the discussion by use of the list.
 
It looks like you might be using ftd2xx instead of libftdi?  If so, you should use the FTDI SPI library instead of D2XX directly.  My homegrown SPI work was done with libftdi, but if you plan to use the FTDI-proprietary stuff, a lot of that work is already done for you.   I do not use the FTDI-proprietary drivers, as I have dug inside them and found many bugs.  Since it's closed-source, I cannot fix them.  So I use libftdi instead, which I can fix (if needed).
 
I don't know if there are Pascal/Delphi/whatever bindings for it, though.  It's been nearly 20 years since I've written any Pascal, sorry.  It would be much easier for me to read in C or C++, and it would help if you described the symptom better.  But again, if you're not using libftdi, I don't know if anyone outside of FTDI Inc is going to be willing to help.
 
Regards,
Michael
 
 
 
 
 
 
-----Original Message-----
From: Tumer TOPCU [mailto:tumert@xxxxxxxxx]
Sent: Monday, April 18, 2011 8:51 PM
To: michael.plante@xxxxxxxxx
Subject: FTDI 4232H and TI ADS7871 A/D Converter

Hello Michael,

I am sorry to disturb you but I found your message about ftdi chips and SPI library. So I am hopping you can help me out for a hobby project.

I have a FTDI 4232H connected to an A/D converter from texas instrument which is ADS7871 (http://focus.ti.com/lit/ds/symlink/ads7871.pdf). I have tried to use the following code to read from analog channels but it always return the same values for reads and the last 2 byte read simply gets stuck. I am pasting the code I have written. If you can help me out that would be really great.



function TFtdi4232.ReadVoltage(channelNo: Byte): Double;
var
  ret, i: Integer;
  val: UInt16;
mux_cnv: Byte;
  Instruction: Array[0..1] of Byte;
  BytesWritten: DWORD;
  FtStatus: FT_Result;
begin
  ret := 0;
  val := 0;
  i   := 0;

// MUX_M3_bm forces single ended*/
// This is also where the gain of the PGA would be set*/
  Instruction[0] := REG_GAIN_MUX;
  Instruction[1] := (MUX_CNV_bm or MUX_M3_bm or channelNo);
  FtStatus := FT_Write(FTHandle, @Instruction, sizeof(Instruction), @BytesWritten);

ret := ReadReg8(REG_GAIN_MUX);
mux_cnv := ((ret and MUX_CNV_bm) shr MUX_CNV_bv);
// on 400MHz arm9 platform the conversion
  // is already done when we do this test
while ((i < 2) and (mux_cnv <> 0)) do
  begin
i := i + 1;
ret := ReadReg8(REG_GAIN_MUX);
 mux_cnv := ((ret and MUX_CNV_bm) shr MUX_CNV_bv);
Sleep(1);
end;

if (mux_cnv = 0) then
  begin
val := ReadReg16(REG_LS_BYTE);
// result in volts*10000 = (val/8192)*2.5*10000
result := ((val shr 2) * 25000) / 8192;
end
  else
result := -1;
end;

function TFtdi4232.ReadReg8(Reg: Byte): UInt8;
var
  BytesWritten: DWORD;
begin
Reg := Reg or INST_READ_bm;

  FT_Write(FTHandle, @Reg, sizeof(Byte), @BytesWritten);
  FT_Read(FTHandle, @Result, sizeof(Byte), @BytesWritten);
end;

function TFtdi4232.ReadReg16(Reg: Byte): UInt16  ;
var
  BytesWritten: DWORD;
  temp: Array[0..1] of Byte;
begin
Reg := Reg or INST_READ_bm or INST_16BIT_bm;

  FT_Write(FTHandle, @Reg, sizeof(Byte), @BytesWritten);
  FT_Read(FTHandle, @temp, 1, @BytesWritten);
  Result := (temp[1] shl 8) or temp[0];

end;




libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread
  • FW: FTDI 4232H and TI ADS7871 A/D Converter, Michael Plante <=