libftdi Archives

Subject: Re: Baud rate confusion

From: Jim Paris <jim@xxxxxxxx>
To: linux@xxxxxxxxxxxxxxxxx
Cc: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 19 Jan 2016 22:06:21 -0500
linux@xxxxxxxxxxxxxxxxx wrote:
> Hi
> 
> I am trying to get lirc working with my Adafruit FT232H device and
> having some problems with getting the clock speed (baud) correct.
> 
> I'm trying to transmit a carrier frequency of 38KHz which is turned
> on and off based on the IR pattern to transmit.
> 
> I've created a separate program from LIRC to investigate this which
> simply opens the device, sets bit bang mode, sets the baud rate, and
> writes a block of 4k alternating 0xff / 0x00.
> 
> I'm driving an IR LED and I have a receiver which will print out the
> duration it detects the 38KHz carrier for if the frequency is close.
> 
> I'm using libftdi-HEAD-c4c9f0a from a few days ago.
> 
> If I provide a baud rate of 3800 to ftdi_set_baudrate then that for
> some reason gives me the required 72K bits / second transmission
> rate.  This is completely at odds with any docs I can find or the
> LIRC code.

I'm not sure I exactly follow your numbers here.

For a 38KHz carrier, wouldn't you want 76Kbits/second transmission
rate?  I assume 72Kbits was a typo?

You're saying that you need to provide a baudrate of 3800, which means
that it's apparently getting scaled up by (76000 / 3800) = 20
with the libftdi version.

> As an experiment I tried building the same program against the FTDI
> D2XX libraries which the docs say multiplies the rate up by 16.  But
> to get that to give me the correct baud rate, I have to pass 15200
> as the argument to FT_SetBaudRate.

By correct baud rate, you mean it's getting scaled up by (76000 /
15200) = 5 in the D2XX version?  So you're not seeing the baudrate get
multiplied by 16 in either situation?

> USB sniffing shows that ultimately both of these calls result in the
> same value being passed down to the chip.

What is the value?

> Can anyone help me understand why I have such a seemingly bizarre
> bit rate being used by this device?
> I had some eeprom issues initially with the device; is it possible
> that the eeprom contents can affect the baud rate like this?
> Or have I bought a fake FTDI device which doesn't operate as the
> genuine ones do?

Not sure, but it sounds like you have a factor of 4 discrepency
between D2XX (scaling by 5?) and libftdi (scaling by 20?).  I also
saw this mystery factor of 4, with a FT230X in bitbang mode.  For 38
KHz IR, my code uses:

#define CARRIER 38400

  ftdi_set_bitmode(&ftdic, 1, BITMODE_BITBANG);
  ftdi_set_baudrate(&ftdic, (CARRIER * 2 / 16) / 4);

The / 4 was just something I determined experimentally and never dug
into.

Jim

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

Current Thread