Last chance to enter The Hackaday Prize.

16FUSB — it’s like V-USB for the PIC 16F628

If you have an idea for a fairly simple USB device but don’t want to invest in the more expensive microcontrollers, this library will be of interest to you. It’s a software implementation of the low-speed USB protocol for PIC 16F628. You can pick these up for around $2, and it just takes a few other components to complete the circuit. And hey, you don’t even need a proper PIC programmer to flash the code. This is the same chip for which we just saw an Arduino act as the programmer.

The circuit design looks exactly the same as the V-USB stack, which provides USB functionality to lower-end AVR microcontrollers. In addition to the chip you need a crystal oscillator, a couple of 3.6V zener diodes, and a handful of passive components. There are a couple of LEDs in the design, but we assume these are for feedback and are not crucial to the functionality of the circuit.

There’s no shortage of data included in the project post so you may want to bookmark this one for later reference.

Comments

  1. Austin says:

    Or for less than the 16f with the extra components you can get a 18f13k50:
    http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en533925

    • nes says:

      Microchip’s pricing of latest generation stuff is always rock bottom. It doesn’t detract from teh awesomeness of porting v-usb to midrange 8-bit pic. I see it is overclocked though. :-/

      Mike, the extra diodes are for EOP condition detection. Guess the PIC just isn’t fast enough to be able to do that in software.

  2. WestfW says:

    Very impressive; I wouldn’t have thought that this would be possible on a PIC without much more serious overclocking. However, note that Microchip’s cheapest PIC with hardware USB support (18f13k50) costs less than the 628, has more program memory and a nicer architecture, and is still available in DIP packaging.

    • fightcube says:

      Well that’s surely a buzz kill for the author of this code.

      • WestfW says:

        I dunno. People are still building z80 systems, and those projects have their own value. You do realize that even overclocked a 24MHz, the PIC is running HALF of the instruction rate of the 12MHz AVR needed to run V-USB? That’s REALLY impressive! I wonder if any of the tricks carry over?

  3. majordump says:

    I haven’t been able to find a V-USB library for Arduino, at least not an up to date one. I’d like to do some ATTiny85 USB magic but with out the headache of doing everything out side of the Arduino IDE.
    The googlecode project for the Arduino AVRUSB only works with Arduino 0016 according to the README.

    • max says:

      You could try using the arduino libraries within a regular avr-gcc project. As an IDE I’d suggest eclipse with the avr plugin.

    • Jarel says:

      If you’re already used to Visual Studio as an IDE, Atmel’s AVRStudio might be your best bet.

      It’s free and it’s far less hassle than anything else I’ve ever tried. You can even program your AVR directly from it without needing avrdude (provided you’re not using your Arduino as an ISP).

      If you do need to use the Arduino as your programmer, just copy the hex file from the project folder and run avrdude as usual.

  4. Steve-O-Rama says:

    Pretty neat. I’ve been looking into Microchip’s stuff more, but only recently, and it so happens I do need USB connectivity in almost every device I design. Nice to have more options on the table than the ATmega32U4 I’ve been glued to (or using a costly FTDI chip). :)

    • WestfW says:

      Note that FTDI recently started shipping cheaper chips. The FT230X is less than half the price of the FT232RL in small quantities. FTDI’s host-side driver support is really, really, good.

  5. Amit Bhojraj says:

    How about considering the ARM LPC11U00 family? This family has a low price point (starting at $0.99, 10K quantities of course) and offers memory extensions to 128KB. Plus, the LPC11U2x offers HID, MSC and CDC drivers in on-chip ROM.

    Have you seen the NXP VID program by the way?
    http://www.lpcware.com/content/project/usb-vid-pid-program

    AB

  6. tlalexander says:

    I highly suggest just making the leap to 32 bit to anyone who’s played with microcontrollers a bit, especially if you want USB.

    The Atmel ATSAM3S1 has USB built in, is less than $4 per chip, and is insanely more powerful than any PIC. Its a 48 pin LQFP which is super easy to solder.

    • Kit Scuzz says:

      It’s a fair point, but there are a lot of tradeoffs in using an ARM instead of a PIC:

      1) Power output per pin. As a general rule: the more processing power, the less output capacity per pin. I was shocked to find 4mA as the expected output per pin on an LPC2388 (and dsPIC33F), meaning that I couldn’t (or at least shouldn’t) try and drive LEDs directly from the pins!

      2) Starting code complexity. In a PIC16 you can get the thing up and running with maybe 10-20 lines of assembly code, and the tools are well supported and explained in the documentation and on the website. ARM comes with a lot of baggage to get to that main routine, and if you’re running assembly: good luck if you’re a beginner figuring it all out! Let me tell you that I’m still rather mystified about how exactly I’m meant to do OpenOCD to get code on to the LPC without using GDB.

      3) How long you can expect the chip to be supported: microchip seems to pretty much indefinitely support their chips, and they’re normally pretty well stocked at the distributors. Atmel seems to have a lot of trouble with this…

      All of that said? There is nothing quite like coding up a beautiful C++ routine with templates and crazy awesome data structures and just compiling it and slapping it into a microcontroller. ARM is beautiful for this, and as long as you’re not doing strict realtime? Go for a cortex-m0 or something! Those things are crazy cheap (sub $1) and amaaaaaazzzziiiiing (50MHz!).

      • Kit Scuzz says:

        Side note for the rant:

        Kinda forgot halfway through there that the premise of “if you’ve played with usb and want to make the jump” which kind of invalidates the end (I don’t know of any USB-enabled sub $1 cortex-m0’s) and point #2 (you’re probably not a beginner if you’ve started in on the USB territory)

        ::shuts up::

  7. notmyname says:

    Can you please confirm me that I understood correctly, english not being my primary language.

    Does this mean that there is no need for a programmer to work with this pic (That it is possible to program it directly via usb)?

    Or this is only to interact with a pc via usb (right/read I/O)?

  8. daniel says:

    The writeup explains the use of the ‘extra’ diodes. They’re not LEDs. Their function is very clever, and worth bringing attention to:
    “The external interrupt pin of the PIC (RB0) is connected to pin D+ USB port. This is where we receive the Sync Pattern (which initiates the interrupt routine) as well as all the others bits read by the PIC. D- is connected to pin RB1, being used almost exclusively for sending bits (along with RB0), unlike RB0 that receives and sends data bits. As the USB port works with differential pair, the lines D + and D- will always be in opposite logical levels, except on one occasion: the EOP (end of packet), where the two lines will be at logic zero (SE0). This ensures that the RB2 pin, connected to the differential pair through D3 and D4, will always be at logic one, except when the host informs the end of package. This trick allows us to check the EOP for every bit received just reading RB2 (btfss PORTB, 2). Remember that time is all we don’t have here.”

  9. Ray says:

    It’s impressive the author figured out all the technical details. But I have to say that my main reason to I would pick Microchip over Atmel is exactly because Microchip provides many inexpensive microcontrollers with built-in USB support and DIP package. The choices are abundant. For example, 18f14k50 is a nice one. No zener diodes needed, no overclocking needed, and their application library provides many examples of USB applications, like HID class bootloader, serial simulator. So in practice, I am not sure why I would need to make USB work on chips that do not have built-in support for USB.

  10. spiralbrain says:

    Splendid!

    wonder if this can also be ported to the 12F to match Atmel.

  11. Abhi says:

    WoW !!! Man, I am late on the scene. I was thinkin something similar for loooonggg. You stole my show, I’d have done it in another decade or so.
    To everyone talking about using a different uP, 32 bit etc etc. Remember, PIC is still the easiest to use. No fancy stuff, ximple tool. Also at times you do projects for the kick of it rather than ‘it can’t be done otherwise’. Thats what make you a hacker.

  12. Abhi says:

    Randi, glad to know you agree.
    Ftorama, you can say that to some extent. I am not a pro in MCUs. I know only about AVR, MSP430, 8051 and a bit and to a larger extent Picoblaze (ok, you may want to put it in 8-bit processor cat, I’d like it as MCU)

  13. Necromant says:

    Could be worth a few years ago. No you can get an stm32 for around the same price or even cheaper.

  14. ngo says:

    Is 16FUSB not supported anymore?
    I am not able to access http://www.lendlocus.com/?q=16fusb

  15. Emanuel Paz says:

    The ‘lendlocus’ page is no longer supported. But you can download 16FUSB complete article from http://bit.ly/1q6waDO or in the project page http://code.google.com/p/16fusb/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 91,175 other followers