Sunday, February 21, 2016

Configuring Nusbio GPIO to drive up to 16 mA of current

Overview

All Nusbio's 8 GPIOs are configured to source/sink 4 mA of current.

If you need the 8 gpios to source or sink 16 mA of current if possible to activate this mode using the Nusbio Console application.

We noticed that in 16mA of current mode I2C bus does not work.
  1. Execute the console
  2. Select the C)onfiguration option
  3. Verify that the setting ADDriveCurrent is set to 4 
  4. Hit the enter key
  5. Answer Y)es at the question: Increase GPIO current drive/sink to 16 mA Y)es N)o
  6. Once the operation is done, unplug Nusbio, wait 5 seconds and plug back Nusbio








Monday, February 15, 2016

FT232 versus FT231

Overview


In his Adafruit interview Fred Dart, the CEO of FTDI, talked about the differences between the UART FT232 and FT231.

For the design of the Nusbio, I started with the FT232R and later switched to the FT231X.
I spent a good amount of time studying the 2 chips.



I was surprise to hear that:
"it can only drive out at 3.3V max though it has 5V tolerant inputs"
and also in the interview it was not mentioned that the FT231X has a 1024 bytes (512+512) transfer buffer, versus the FT232 which only has a 384 bytes transfer buffer (128 + 256). The buffer size in synchronous bit banging mode makes a big difference in terms of byte/second transferred.




The FT231X has multiple advantages over the FT232R
  1. Price
    $2.12 over $4.50 for one chip.
  2. Buffer size 1024 over 384. A larger buffer increase the transfer performance when using the synchronous or asynchronous bit banging mode. I do not know if this make a difference in UART mode (I supposed it should) but with Windows the serial port are limited 128 000 bauds.
  3. Package
    SSOP-20 over SSOP-28, easier to solder. For both I would not use a regular solder iron. I recommend to use an "electric skillet"or toaster. Obviously the FT231X take less space on the board.
  4. Voltage
    Based on the FT231X datasheet the 3.3 Volt out should feed VCCIO, therefore all 8 GPIO would output 3.3V. Making it a 3.3V devices.
    For now in Nusbio I feed VCCIO with the USB 5V or 3.3V configurable with a jumper or a soldered connector. By default it is set to 5V, making Nusbio a 5V device.

    I need to check with FTDI if that is ok, though it seems to work and Fred Dart confirmed the input are 5V tolerant. The question is the output and VCCIO are 5V tolerant.

    At the URL http://www.ftdichip.com/Products/ICs/FT231X.html, I found this
          True 3.3V CMOS drive output and TTL input.
          (operates down to 1V8 with external pull ups and is also 5V tolerant)
    From Twitter @FTDICHIP sent me back the following:
    the VCCIO is really meant to be 3.3V Absolute max ratings as quoted are this. It will withstand a 5V input but output at 3.3V.

    I am going to update Nusbio board to send 3.3V to VCCIO, this mean the 8 GPIOs will send 3.3V.  Nusbio VCC will remains 5V with up to 500 mA.

  5. Clock
    With the FT232R, there is an issue with the internal clock in bit banging mode. It can only be viewed with an Oscilloscope. The clock is not stable. If you bit bang 1 0 1 0 1 0, you would expect a stable 50% duty cycle what ever the baud rate. But what I saw on the Oscilloscope was all over the place. I found one person on the FTDI forum that remarked the same problem. Adding an external clock fixed the problem (Adding an external clock does not increase performance).
The FT231X has multiple disadvantages over the FT232R.
  1. The USB data lines require each a 27Ohm resistor and a 47pF capacitor.
    More work to build a device
  2. FT232R is definitely 5 or 3.3 volts chip, where the FT231X is a 3.3V chip (though the gpio input are 5V tolerant. And gpio can be configured to 5V, but not "recommended" by FTDI)

Temperature Sensor For .NET

Overview


Do you want to know the temperature around your laptop in your .NET app?


Nusbio is a USB device that can talk the different protocols to query temperature sensors.
Nusbio is fully programmable in any .NET languages.

Communication Protocols 


There are 3 protocols supported
  • SPI
  • I2C
  • Analog
Temperature using the 1 Wire protocol like sensor family of DHT XXX are not supported.

Temperature sensors tested

  • MCP9808 - I2C
    • Very accurate ±0.25 (typical) from -40°C to +125°C 
    • Datasheet
    • Price for one: $1.22
    • Package MSOP-8
      • A little bit challenging to solder manually, but possible
      • Adafruit has a breakout (breadboard compatible)
    • We have an adapter for Adafruit I2C device (see photo above)
  • TC77 - SPI
    • Accurate 1°C (max.) accuracy from +25°C to +65°C
    • Datasheet
    • Price for one: $1
    • Package SOIC-8
      • Easy to solder manually on a adapter (See picture below)
    • We are working on an extension for it that will be plug and play
  • TMP36 - Analog
    • Not very accurate. ±2°C accuracy over temperature.
    • Datasheet
    • Price for one: $1.36
    • Can be plugged into a breadboard
    • This  temperature sensor requires an ADC (Analog to Digital Converter)
    • We have noticed that the TMP36 does not perform correctly with our Analog Extension

    TMP36 analog temperature sensor (in black)
    plugged into the Nusbio Analog Extension

    Conclusion


    If you need to query for temperature in your .NET app in an easy to assemble solution we recommend the
    • Adafruit MCP9808 breakout + Nusbio adapter for Adafruit I2C device
    • Coming soon our own plug and play extension for the TC77

    Saturday, February 13, 2016

    USB to SPI for .NET - EEPROM


    EEPROM and Nusbio G1

    The Nusbio library supports the following EEPROMs

    • SPI 128k 25AA1024
      • Transfer the 128k in 5.8s 22Kb/SS 
      • Transfer the 128k in 89ms with Nusbio G2 prototype 1438 Kb/s 15Mhz
    • SPI 32k 25AA256
      • Transfer the 32k in 1.5s 21Kb/SS 
    • I2C 32k 24LC256
      • Transfer the 32k in 4.5s 7Kb/SS  






    Friday, February 12, 2016

    USB to SPI for .NET (performance)

    USB to SPI performance

    Getting good performance with a USB to SPI with a USB 2.0 full speed also depend also on what slave chip you are controlling, for example:
    • Let's pick the MAX7219 (10Mhz) an LED driver used to control 7-Segment display or 8x8 LED matrix.
      The communication protocol is :

          SELECT Byte0:Command, Byte1:Data, UNSELECT

      It does not really matter the speed at which the 2 bytes are transferred, after the 2 bytes, the MAX7219 required the UNSELECT. Most USB to SPI chip will therefore end the USB operation. With each USB operation there is a penalty at least of 1 Milli-second.
      If the USB to SPI chip (Software and hardware) allows to package multiple SELECT, Data, UNSELECT in one USB operation, then we will get good performance.
    • An EEPROM are generally more forgiving because we generally transfer pages of bytes. So for the cost of one USB operation we can transfer 64, 128, 256, ... bytes. But then it also depend on how much buffer the chip has.
    • A third case is for example the SPI OLED SH1106 or SSD1306 driver (128x64 monochrome pixel), which requires also extra GPIO named D/C (Data or Command).
      The communication protocol is :

      SELECT, DC=C, Cursor Position 3 bytes, UNSELECT, SELECT, DC=D, 128 data bytes, UNSELECT

      We need 8 times this sequence to send a full refresh of the display.
      If we cannot combine in one USB operation multiple sequences SELECT, DC, Data, UNSELECT. We will not get good performance even with a clock at 12Mhz.
      So it depends on the hardware and software feature of the chip.
      I am going to call this feature: USB to SPI Low Level Optimization.

      For example Nusbio G1 library (FT231X Chip) do support this mode and this allow to support the devices mentioned above with acceptable performance. That said the USB Buffer of the FT231X is 1k, so we can only package the bit banging in batch of 1024 and then we hit the USB operation penalty. That is why Nusbio G1 performance depending on the SPI slave device are between 10 K byte/s and 20 K byte/s.

      The FTDI FT232H is the only chip so I tested that support SPI Low Level Optimization.
      In FTDI world it is called MPSSE (Multi Protocol Synchronous Serial Engine). All FTDI chips supporting this mode can do SPI, I2C in very optimized way. This FT232H is High speed, the FT2232 is Full speed. More on the FT232H later.
    • USB 2.0 Highspeed. In Highspeed mode the cost (latency) of an USB operation is 100 nano second (I think). Therefore we can get better performance without SPI Low Level Optimization. Though it is preferable to have access to it.

    Digital Potentiometer SPI AD5290 and Nusbio

    Overview


    The Digital Potentiometer AD5290 is not a regular one.
    1. It provides 2 supply modes
      1. Single supply, Positive voltage
      2. Dual supply, Positive voltage and negative voltage
        You need to provide the positive and negative voltage (pin 1 and 2)
    2. In mode 1, the current can be between 20 and 30 Volts.
      In mode 2, the current +-10 to +- 15 volts
    3. It is only available in MSOP-10
    Datasheet


     

    SPI


    The AD5290  is an SPI chip which does not use MISO (The chip does not send information back).
    Be care full, the SDO pin is used for daisy-chaining

    The recommended wiring with Nusbio is a follow

    GPIO 0 - CLOCK
    GPIO 1 - MOSI
    GPIO 2 - CS

    VB.net Code

    Wiring

    5 Volts from the USB

    In this wiring, we use the Single supply, positive 5 volts mode from Nusbio and therefore from the USB.


    9 Volts from a battery

    In this wiring, we use the Single supply, positive 9 volts mode from a battery.
    Nusbio GPIO 0,1,2 should never be in contact with the 9 Volts from the battery.



    Thursday, February 11, 2016

    SPI digital potentiometer AD5290Y 10k with some vb.net code

    SPI digital potentiometer AD5290Y 10k with some  code and Nusbio










    Monday, February 8, 2016

    USB to SPI for .NET

    Overview

    I started investigating the hardware architecture for Nusbio 2. With the new device I would like to achieve a transfer of at least 100 K byte /s and target 1 M byte/s.
    (Update: 2017.04.02 with the FTDI FT4222 I achieved 100 Kbyte/S in I2C using a 32k byte EEPROM and 2.4 MebaByte/S using a NOR FLASH at 100Mhz)

    I most likely will use a USB 2.0 to SPI chip and add a micro-controller like the ATiny84 to provide
    • More GPIOs
    • PWM
    • ADC
    • EEPROM storage
    I may select a Full speed or High speed. High speed is faster, but more expensive and most likely does not exist in package SSOP-20, but rather LQFP-48 or QFN-48.

    In this post, I will summarize my findings regarding the chips I tested. Obviously my end goal is to create a .NET compatible device.

    USB to SPI performance

    See blog: USB to SPI for .NET (performance)


    Test Scenarios

    1. Test1 - Transfert 32 K byte of data from EEPROM 25AA256 (support SPI 10MHz) to computer in C#.
    2. Test2 - Transfert 128 K byte of data from EEPROM 25AA1024 (support SPI 10MHz) to computer in C#.


    USB to SPI Chip

    • MicroChip - MCP2210 Datasheet
      • Evaluation board ADM00419 $15
      • USB 2.0 Full speed
      • SPI Bitrate 3 Mbps
      • 128 byte buffer
      • GPIO for select: 8
      • Packages: 20-lead QFN, 20-lead SOIC, 20-lead SSOP
      • Price: $1.98 for one
      • .NET samples: Yes
      • SPI Low Level Optimization: Most likely No
    • Cypress - CY7C65211 Datasheet
      • Evaluation board  CY8CKIT-049-42XX $4
      • USB 2.0 Full speed
      • Bitrate 3 Mhz
      • 256 byte buffer
      • GPIO for select: 5 
      • Packages: 24-lead QFN
      • Price: $2.61 for one
      • .NET samples: No. C code.
      • SPI Low Level Optimization: Most likely No
      • Remark: Can be configured as UART, SPI or I2C
    • FTDI - FT232H Datasheet
      • Evaluation board  UM232H $20
      • USB 2.0 High speed
      • Bitrate 30 Mhz for SPI
      • 64k byte buffer
      • GPIO for select: 5
      • Packages: 48-lead QFN
      • Price: $4.25 for one
      • .NET samples: Partially, Require C DLL.
      • SPI Low Level Optimization: Yes
      • Remark: Can be configured as UART, SPI, I2C, JTAG, FIFO, Bit banging.

    • SILICON LABS - CP2130 Datasheet
      • Evaluation board  CP2130EK $20
      • USB 2.0 High speed
      • 6.6 Mb/s for SPI (844Kbyte/S, Video)
      • xx byte buffer
      • GPIO for select: 11
      • Packages: 24-lead QFN
      • Price: $2.16 for one
      • .NET samples:?
      • SPI Low Level Optimization:?

    Test Result

    • MicroChip - MCP2210
      • At the SPI Bitrate 3 Mhz (which cannot be increased)
      • Downloading the 32k of  data in chunk of 32 pages of 64 bytes (2k)
      • 4.559s 7.02 K byte/S
      • Conclusion: Really bad performance.
    • Cypress - CY7C65211 
      • At the SPI Bitrate 3 Mhz  
      • Downloading the 32k of  data in chunk of 16 pages of 64 bytes (1k)
      • 12 K byte/S
      • I asked on the Cypress forum for help - Page. So far no real help from the Indian support.
    • FTDI - FT232H 
      • At the SPI Bitrate 10 Mhz (Max supported by the EEPROM)
      • Downloading the 32k of  data in chunk of 256 pages of 64 bytes (16k)
      •  0.03s  1066.67 K byte/S
      • Conclusion: Really very nice performance. and the FT232H can goes up to 30 Mhz.
    • SILICON LABS - CP2130

    More About The MCP2210

    •  Kerry Wong, blogged a lot about the MCP2210 at http://www.kerrywong.com.
    • In his post "Finicky MCP2210 Oscillator", John Davis added the following comment, which explain a lot.

      WARNING: According to our trouble ticket interactions with Microchip technical support, the MCP2210 is “throttled” internally with a mininum SPI inter-byte spacing of about 45uS REGARDLESS of SPI clock frequency (we got 12 MHz working on our board.) That limits the byte data rate to about 23KBytes/second max. However, the performance is still limited further by the fact that it is an HID device with a HID-limit 64KByte/second interface. Two USB 128 byte transactions of 3mS each with a wait in between are required for a transfer, so the effective data rate using full 60 byte packets works out to slightly less than 8KBytes/second (Verified with ‘scope.) THIS IS NOT A HIGH THROUGHPUT PART!



    Tuesday, February 2, 2016

    Technical Precisions About The Nusbio Device

    What is Nusbio?

    Nusbio is USB device that bring the following to a Windows machine and the Microsoft .NET Runtime:

    Device

    • Gpios

      • 8GPIO pins
      • 3 or 5 volts 
        • Nusbio version based on the chip FT232RL can be changed between 3.3 and 5 volts (GPIO and VCC). In 2017 only the version based on the FT232RL will be sold.
        • Nusbio version based on the chip FT231X only the VCC can be changed between 3.3 and 5 volts. The GPIO are always 3.3 volts.
      • Modes: OUTPUT or INPUT PULL UP.
      • Maximum current per GPIO pin default 4 mA .
        The Console application allows to switch from 4 to 16 mA.
        In 16 mA of current mode we noticed that the I2C protocol does not work.
     Powering devices connected to Nusbio
      • The VCC output from Nusbio provides 5 or 3.3 volts and up to 500 mA of current as defined by the USB 2.0 standard.
      • The VCC output can be used to power other devices connected to Nusbio.
      • Some Nusbio version based on the FT231X have a fuse that will limit the consumption to 500 mA of current.
      • The voltage can be changed depending on the version as follow:
        • De-soldering the 5 volts connector and soldering the 3 volts connector.
        • Or switch the jumper between 5 volts and 3 volts
    • SPI Protocol

      • Mode

        • Clock MODE_CPOL0_CPHA0 supported and tested
        • The other 3 modes have been implemented but not tested.
      • Tested Devices

        • MCP3008 - 8 DAC
        • MAX7219 - 7-Segment Driver
        • 25AA256 - 32k EEPROM
        • 25AA1024 - 128k EEPROM
        • MCP23S08 - 8 Gpio Expander 
        • OLED drivers
          • SD1306
          • SH1106
        • SPI Compatible Devices
          • 74HC595 - Shift register
          • APA102 RGB LED
      • SPI Slave

        • Number of devices on an SPI bus. Since Nusbio comes with 8 gpios, we can control 5 (8-3 (clock, miso, mosi)) SPI devices on the same bus.
      • Transfert Speed

        • When data in and data out communication is needed (MOSI and MISO) the maximum transfer rate is around 15 k byte/s with no optimization.
        • With specific optimization for EEPROM downloading in batch of 128 pages of 64 bytes, the transfer rate can go up to 28 k byte/s.
        • Generally speaking when only data out communication is needed (no MISO) the transfer rate can go up to 20 k byte/s by using the class GpioSequence rather than the class SPIEngine. The class GpioSequence offers a way to optimize the bit banging.
        • Transfer speed vary depending on the SPI device and the Windows PC.
        • Nusbio and the C# class SPIEngine can transfer in one USB operation multiple SPI buffer (Select + Data + UnSelect + Select + Data + UnSelect).
        • Some SPI device like the OLED driver SH1106 or SSD1306, required on top of the Select pin (CS) another pin named D/C (Data or Command). Nusbio and the C# class SPIEngine can transfer in one USB operation multiple SPI buffer (Select + D/C + Data + UnSelect + Select + D/C + Data + UnSelect. (See our source code on GitHub).
    • I2C Protocol

      • Tested Devices:
        • 24LC256 32k EEPROM
        • MCP2308 - 8 Gpio Expander 
        • MCP9808 - Temperature sensor
        • MCP4725 - 12Bit DAC 
        • HT16K33 - Matrix Driver 
        • Adafruit I2C LED Matrix devices
      • Transfer Speed 
        • The tests were performed by downloading 32k from the I2C EEPROM 24LC256 . 
        • Transfer speed around 7.5K byte/s. 
        • Transfer speed vary depending on the device and the Windows PC.
    • SPI and I2C Protocol Combined

      With Nusbio it is possible to control SPI and I2C devices from the same configuration. For example

      • GPIO 0,1,2 would be reserved for SPI BUS: CLOCK, MOSI and MISO
      • GPIO 3,4,5 would be used as SELECT for 3 SPI Devices
      • GPIO 6,7 would be used as SDA and SCK for the I2C bus, allow to control up to 127 devices

    • UART

      Nusbio can also play the role of an UART (FTDI cable, FTDI Friend) to upload data into an micro-controller like an Adafruit Trinket or Diavolino.
      The .NET library MadeInTheUSB.Lib.dll does not support this mode. The Arduino IDE will support Nusbio to upload code into an micro-controller with no UART.

      Videos

    •  Library/Assembly

      • The MadeInTheUSB.Nusbio.Lib .NET assembly give access to the Nusbio device to any .NET language.
      • The MadeInTheUSB.Nusbio.Components assembly contains classes for specific components including the one used in the Nusbio's extensions.
      • Github Source

    • Internal EEPROM

      Nusbio can store up to 32 bytes of data into the Description field. Though the Description property is a .NET string, the EEPROM only support ASCII string.
    • Unique Serial Number

      Each Nusbio device is initialized with a unique Serial Number. See property SerialNumber.

    Chip

    Nusbio is based on the FTDI FT231X chip (Datasheet) or the FT232RL.
    In 2017 only the FT232RL chip is used.