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.
Or for less than the 16f with the extra components you can get a 18f13k50:
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en533925
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.
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.
Well that’s surely a buzz kill for the author of this code.
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?
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.
You could try using the arduino libraries within a regular avr-gcc project. As an IDE I’d suggest eclipse with the avr plugin.
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.
That sounds like a good idea, I do like Visual Studio. I don’t have a recent copy but can (hopefully) get it in a couple weeks.
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). :)
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.
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
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.
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!).
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::
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)?
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.”
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.
Splendid!
wonder if this can also be ported to the 12F to match Atmel.
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.
You’re right Abhi. That’s the hacker spirit!
It’s the simpliest because it looks like it’s the only one you know
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)
Could be worth a few years ago. No you can get an stm32 for around the same price or even cheaper.
Is 16FUSB not supported anymore?
I am not able to access http://www.lendlocus.com/?q=16fusb
Funny… I just found tgis yesterday also, and was also crushed to find that the link is dead..
Um. Let me google that for you:
http://code.google.com/p/16fusb/
This site has the source and DIO example. I tried to email to efs…@gmail.com but was not able to do so. The address seem weird or is it me? Basically, I like to know if 16FUSB can be implemented on 16F876. Also like to know what pins to use in 16F876 if it is applicable. Same PORTB0,1,2 as in 16F628? If I can use PORTB0 as the interrupt and swap out PORTB 1,2 to other pin, I can use 1,2 as hardware USART. I am not good enough to understand the source so I cannot confirm if USART is use for 16FUSB. Will someone please advise on this?
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/