libftdi Archives

Subject: Re: Bitbang speed/latency

From: Rogier Wolff <R.E.Wolff@xxxxxxxxxxxx>
To: Peter Smith <pete@xxxxxxxxxxxxxx>
Cc: Jim Paris <jim@xxxxxxxx>, libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Mon, 23 Mar 2015 10:27:55 +0100
On Sun, Mar 08, 2015 at 01:21:44AM -0000, Peter Smith wrote:
> > Peter Smith wrote:
> >> Hi,
> >>
> >> I'm using the Device::FTDI Perl wrapper for libftdi to communicate
> >> with an FT230X, which in turn is driving 16 cascaded shift
> >> registers.
> >> The communication speed is decent, but I'm hoping for more if
> >> possible.
> >>
> >> Here's my code:
> >>
> >> use Device::FTDI;
> >>
> >> ##  0x08 CTS - LATCH
> >> ##  0x01 TX - DATA
> >> ##  0x02 RX - CLOCK
> >>
> >> $dev = Device::FTDI->new('vendor' => 0x0403, 'product' => 0x6015) ||
> >> print $!;
> >> $dev->set_bitmode(0xff, 0x01);
> >>
> >>    for (1...128) {
> >>         $dev->write_data(0x01);
> >>         $dev->write_data(0x03);
> >>    }
> >>
> >>    $dev->write_data(0x08);
> >>    $dev->write_data(0x00);
> >
> > Try something like this (untested):
> >
> > $data = '';
> > for (1...128) {
> >     $data .= chr(0x01);
> >     $data .= chr(0x03);
> > }
> > $data .= chr(0x08);
> > $data .= chr(0x00);
> > $dev->write_data($data);
> >
> > Jim
> >
> 
> Hi Jim,
> 
> It's actually one of your MicroFTX breakout boards that I'm using
> (cheers - they arrived yesterday).
> 
> I've tried your code, but no joy - I suspect because it's now going
> too fast. Because the FTX is talking to shift registers I need to set
> my data pin high/low, then pulse the clock, then set the data pin,
> then pulse the clock etc etc. Previously I had some usleep statements
> in my code to sleep for a few ms between writes, but because of the
> latency they're not needed. The clock pulses need to be a minimum of
> 40ns.

The new code should work. Try setting the baud rate. All FTDI chips use
this in "bitbang" mode to pace the outputs. 

That said, as far as I can see your current code is shifting all
"ones" on the data-bit D0. When actually doing data you need to
prepare the data on the right clock edge. So

   if (databit[i]) {
         $data .= chr (0x01);
         $data .= chr (0x03);
   } else {
         $data .= chr (0x00);
         $data .= chr (0x02);
   }

inside the loop may need to become: 

   if (databit[i]) {
         $data .= chr (0x03);
         $data .= chr (0x01);
   } else {
         $data .= chr (0x02);
         $data .= chr (0x00);
   }

with "half" an iteration moved to BEFORE the loop and half
AFTER the loop. 

        Roger. 

-- 
** R.E.Wolff@xxxxxxxxxxxx ** http://www.BitWizard.nl/ ** +31-15-2600998 **
**    Delftechpark 26 2628 XH  Delft, The Netherlands. KVK: 27239233    **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

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

Current Thread