PDA

View Full Version : Beginning USB How to/Whats needed to use it.



wdmagic
- 2nd April 2013, 19:41
I would like to start interfacing PICs to my PC, I can program VB.NET applications and it has a serial output in that software, so if I can turn my usb on and have it act like a serial port I should be able to interface with the PIC.

First though we need to get a breakdown of whats all needed and identify some of the terms and definitions used. second is what is our limits, what kind of data can we send/receive, third what is needed in code to turn on USB, etc...
4th project ideas.

Number 1
What is HID?
In MicroCode Studio (I have version 4) there is a "Easy HID Maker" Should we use this or is there a better way?
Does enabling USB just place a new COM Port on the PC?
If its not a COM Port then how do we communicate?
As far as schematics and electrical layout, I will be using a 18F4550, D+ & D- are tied to those pins, vUSB is tied to power/capacitor etc. there are numerous layouts online for the electrical side. So this shouldnt be a problem, but if anyone has special notes or ideas, put them in.
If Ive missed anything for number 1 just add it in.

Now for Number 2
How much data can we send in a single stream?
can we send text? like a "Hello World" to a LCD?
Does the USB have to sync with PC on regular basis or just act like a one-shot?
Other ideas?

And Number 3
Ive seen some articles that list a few DEFINEs for USB, Is there a minimum or are all required and what are they?
How do you store the info that is to be sent or received from USB?
Do you just transmit/receive like serial, example USBIN USBOUT?

Number 4, Ideas?
I would like to control several Servos, LEDs, interface with multiple ADC's for readings, be able to read the I/O states, Etc...
What have other people used USB for?\


now I may have left some stuff out, this is just a list of stuff that comes to mind right now. I did several searches for USB and didnt find great info on begining USB. The idea though is to list everything to get USB to run and bits of code for interfacing it.

Demon
- 2nd April 2013, 19:49
http://www.picbasic.co.uk/forum/showthread.php?t=5418

I would start by going through that.

Robert

wdmagic
- 3rd April 2013, 08:04
Ive read through it some, and i unerstand a bit of it, but most of its based on the first code/project and making a few modifications to it, I understood darrels a bit better, but was hopeing to get a from scratch point of view, you know what is the minimum code/hid requirements and then list some items you can add to it. For instance, I have 1 project right now, uses only 2 pins of a 4550 chip, a ADC input and a single I/O output, it takes a reading and outputs based on reading, now I need to randomly make changes to what the output changes to on a flexible scale, think of something like a oven, you might want it on at 300 degres for 10 minutes but the next day you want it at 400 for 1 hour. the computer can take the reading and tell the output pin when to go high. another progect I need to control say 16 servos with the computer... and yet another is a audio controller circuit that controld 4 volumes via spi, also needs to work with bass treble lcd display, and led matrix. but to begin with I thought I would start with just taking a ADC reading , send to computer , computer makes desision on what to do and sends a 1 or 0 to PIC to output to other device.

There is alot of extra stuff I dont need in those other examples some of its outdated anyways, and am unsure of what to cull from code.

wdmagic
- 3rd April 2013, 08:41
just an example of code that I am starting with


'* Notes : Using 18F4550 *
'* : *
'************************************************* ***************
DEFINE ADC_BITS 10 ' A/D number of bits
DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us

TRISA = 1 ' PORTA.0 is Analog Input
TRISB = 0 ' PORTB is Output

Analog VAR WORD ' Stores the 16bit Result from ADC0
UnitON VAR Bit ' Stores the state that output should be
UnitON = 0 ' Initial state

MainLoop:
ADCIN 0, Analog ' Saves 16bit Analog reading to Variable

'Code for sending Analog reading to PC
'Code for receiving the state needed to send to output port.

PORTB.0 = UnitON
pause 100
goto mainloop

END

tasmod
- 4th April 2013, 10:18
Any idea where I can download Easy HID Maker as the site throws up a 404 error ?

peterdeco1
- 4th April 2013, 19:15
Chris I'm not familiar with that chip but don't you mean TRISA = 255 for all inputs?

wdmagic
- 6th April 2013, 02:53
tasmod try this
EASY HID (http://www.develotech.net/Archive/Circuits/Docs/microchip%20refs/EasyHID%20USB%20Code%20Generator.htm)

peter, this chip has to set up the buts with some kind of special binary its weird, you would think trisa = 255 or %11111111, but it doesnt. %00000001 = just porta.0 is adc, but to get more theres a chart, so if your just neededing 1 adc, then porta = 1 works.

tasmod
- 6th April 2013, 09:48
Thanks Chris,

Unfortunatey that's the site where the download link throws up the 404 error.

Rob

wdmagic
- 6th April 2013, 20:02
Sorry Tazmod,
Heres a working link (http://advancedsystems.dyndns-office.com/EasyHID.zip)

Archangel
- 11th April 2013, 21:11
Or you could use an FT232RL at about $4.50 USD with absolutely ZERO headaches or brain damage, which is what those Arduino thingies do.