MOBILE HOME Technical Tips  

USB HID WITH ANALOUE INPUTS AND DIGITL OUTPUTS

Using PIC18F2550 for connecting analogue and digital signals to USB port . Included Visual Basic 6 code, VS2005 C++ and C# codes are based on Microchip code, PIC ASM code, PIC C code and a circuit diagram. The PIC microcontroller has 10 bit analogue to digital converter. The circuit is powered by the USB. The interface to the PC is HID class.
The inputs and outputs are updated every 10ms.
HID class (human interface device) is a class of devices like the mouse and the keyboard, the data transfer rate is limited to 64KB/S. The PC already has a driver for HID USB.
VB6 code includes guidance to setting up the PC. The PC register the PID and VID (product ID) of the USB device when it's plugged, the VB code uses these ID's to communicate with the device. For commercial VID it is needed to buy it from USB-IF, but in your lab you can use any number.
The source code is derived from freeware from these sources: http://janaxelson.com/usb.htm , http://openprog.altervista.org/USB_firm_eng.html
You are free to use the circuit diagram and the VB software with no limitations.



PC application

Circuit Description
See also Technical Tips

PIC18F2550
Pins 2-5 are the analogue inputs, voltage range 0 to 5V. Max input voltage is 5.5V . 1K resistors are to protect the PIC.
Pins 25-28 are the digital inputs, TTL voltage levels.
Pins 21-24 are the digital outputs, they can sink or source 16mA.
Pin 14 is 3.3V internal supply for the USB transceiver. 0.22uF is required for regulation.
Pins 15,16 are the data lines to the USB connector on the PC.
Pin 20 is the PC 5V powering the PIC. It is limited to 100mA by the PC. 0.47uF is for decoupling.
For USB wiring info: http://www.interfacebus.com/Design_Connector_USB.html





Name:

Comments and questions

Copy the number from the picture It stops net-robots from adding comments.



24.04.2015 - 13:32
Name: Moty
Comment: Hi Stain, it written in the description above what program, you cannot use XC8.

24.04.2015 - 12:18
Name: stain
Comment: Which program used for compile ASM code & C code plz help me . email: an1997zs@gmail.com

24.04.2015 - 12:17
Name: stain
Comment: Which program used for compile ASM code & C code plz help me . email: an1997zs@gmail.com

17.04.2015 - 18:23
Name: Moty
Comment: Sorry Aymen, I don't understand the question. The last answer I sent was for ASM

17.04.2015 - 13:55
Name: aymen
Comment: hi moty how I can change the main program asm code (hand) to properly adjust c code on my work. when I have commented on the application code does not work

14.04.2015 - 01:32
Name: aymen
Comment: i change the build to mpsam c18 but is not work again

14.04.2015 - 01:31
Name: aymen
Comment: but the code is on assembleur nort on C ????

14.04.2015 - 00:25
Name: Moty
Comment: You have to change the 'Build Option' settings from 'Generate absolute code' to 'Generate relocatable code' : Menu > Project > Build Options > Project, In the window select MPASM/C17/C18, select 'Generate relocatable code', Click OK

13.04.2015 - 23:04
Name: aymen
Comment: ---------------------------------------------------------------------- Debug build of project `C:\Users\HP pavilion G6\Desktop\aymen led\usb.mcp' started. Language tool versions: MPASMWIN.exe v5.37, mplink.exe v4.37, mplib.exe v4.37 Preprocessor symbol `__DEBUG' is defined. Mon Apr 13 22:03:43 2015 ---------------------------------------------------------------------- Clean: Deleting intermediary and output files. Clean: Deleted file "C:\Users\HP pavilion G6\Desktop\aymen led\usb.mcs". Clean: Done. C:\USERS\HP PAVILION G6\DOCUMENTS\EGDOWNLOADS\USBIO\ASM\USB IO.ASM 113 : Overwriting previous address contents (000A) Error[118] ------------------------------------- BUILD FAILED

13.04.2015 - 17:12
Name: Moty
Comment: Hi Aymen, for asm use MPLAB 8.xx , you cannot use MPLAB X. Make sure your MPLAB is configured for PIC18F2550 MPLAB has compiler for ASM code. Copy to the comments the errors maybe I'll be able to tell what is the problem.

13.04.2015 - 15:30
Name: aymen
Comment: please help me

13.04.2015 - 13:41
Name: aymen
Comment: is not work ???????

13.04.2015 - 13:26
Name: aymen
Comment: many errors ?????? What you use the compiler in mplab ide ????

13.04.2015 - 13:24
Name: aymen
Comment: i use asm but the compilation not work ???

13.04.2015 - 13:06
Name: Moty
Comment: If you are using ASM put in your project the 3 files in ASM folder, usb io.asm has the main code. If you use C put in your project the 4 files in C-GPL folder, main.c has the main code.

13.04.2015 - 03:25
Name: aymen
Comment: what about the file .asm adn . inc ??? and the file asm is the file of the application of the inpout outpout er the file main.c ???

13.04.2015 - 03:25
Name: aymen
Comment: what about the file .asm adn . inc ??? and the file asm is the file of the application of the inpout outpout er the file main.c ???

13.04.2015 - 03:12
Name: aymen
Comment: what the name of file to add all the file please ???????

10.04.2015 - 00:56
Name: Moty
Comment: Hi Mohamed. Maybe I'll be able to fix it when I see the project that is similar to mine, do you have a link to the project? Are you using my pic software with a different VB6 program?

09.04.2015 - 21:29
Name: Mohamed Sayed
Comment: Moty. In a project similar to yours .the VB6 cannot send bytes to hardware. When I run the software for the 1st time and wait a while then press toggle LED button, Number of written bytes are 0 and no bytes were sent to hardware.. But when I don't wait and press the button just once the Form loads, It sends data .. Do you know how to fix that ???

03.12.2014 - 01:55
Name: Moty
Comment: Use the ASM files with the MPLAB if you don't have C-18 compiler

02.12.2014 - 07:19
Name: tharindu
Comment: moty iam added my project to the 2 C files and the 2 headers files (h). after iam compiled it. it have more error in compile iam used mikroproc for compile to it. moty please give me step for compile it.

02.12.2014 - 05:48
Name: tharindu
Comment: thank you moty thank you your project is very impotent to me i am study one by one day by day very soon it will be a newest invention or production Rio Electronic

02.12.2014 - 00:33
Name: Moty
Comment: Hi Tharindu, you have to add to your project the 2 C files and the 2 headers files (h) to be able to compile it.

01.12.2014 - 17:17
Name: tharindu
Comment: moty cannot compile asm and c file into hex but ur hex file is working carefully

01.12.2014 - 15:37
Name: tharindu
Comment: moty i am downloaded this project but have a two c file. what is the real file to re-assign the PIC pins.

30.10.2014 - 15:22
Name: Moty
Comment: Hi Fabio. I don't but there must be some on the net.

29.10.2014 - 21:47
Name: Fabio
Comment: Hi Moty, Do you have any exemples on how to use a Rotary encoder? Rgds

29.10.2014 - 21:42
Name: Fabio
Comment: Hi Moty, Do you have any exemples on how to use a Rotary encoder? Rgds

25.08.2014 - 10:51
Name: Moty
Comment: Thanks, it was fun too.

24.08.2014 - 08:54
Name: El ismail
Comment: It took a lot of effort & generosity to give out a reliable work like this one. Thanks moty.

14.08.2014 - 20:10
Name: Moty
Comment: Hi Fabio, You can have up to 6 analogue inputs on the PIC18F2550. I don't have an example for that. I don't know why you can't have 2 USB devices working together on your PC, I have 2 devices working on my WIN XP PC.

14.08.2014 - 00:27
Name: Fabio
Comment: Hi, this is a very good Project and it�s working great, but I would like to have 5 or 6 analog input. Is it possible to have such inputs? If so, where do I have to change on the program? Could you send me any example? Another problem I see is when I attach more then one devices, even with diferente PID&VID, the first device is disconnected by the second one.

14.04.2014 - 21:55
Name: Moty
Comment: Hi Rathish, I don't have problems with Win 7 for this project. My firmware is for pic18f2550.

14.04.2014 - 13:29
Name: rathish
Comment: Hi , Few months before I download your usb 4 adc input program ,first time it was worked with my 18f4550 chip. recently I use the same chip for the same program. My os win7 now not recognizing it. My os also shows it is counterfeit problems.

26.10.2013 - 15:34
Name: Moty
Comment: Hi Tharindu It is possible to add 4 outputs. To do that you need to re-assign the PIC pins, rewrite the PIC code and to rewrite the VB code. I don't have the prototype so I can't try it.

26.10.2013 - 03:25
Name: tharindu
Comment: your program for to 4 out put but i want to 8 out how program asm code give me simple example

15.09.2013 - 23:40
Name: matteo
Comment: hello, thank you for answering. I do not care to lower the full scale, I would like to read value in the corresponding voltage. I'm not able to modify the source code visual basic. if possible I would like it to be displayed with 50V input 5V in analog inputs. thanks, see you soon!

15.09.2013 - 23:39
Name: matteo
Comment: hello, thank you for answering. I do not care to lower the full scale, I would like to read value in the corresponding voltage. I'm not able to modify the source code visual basic. if possible I would like it to be displayed with 50V input 5V in analog inputs. thanks, see you soon!

14.09.2013 - 22:36
Name: Moty
Comment: Hi Matteo. The VB program can be changed to have less than 5V full scale. Can you change the VB source code yourself? if not I can do it for you after you let me know what voltages you want to read.

14.09.2013 - 17:31
Name: matteo
Comment: hello, have matteo, from Italy. I tested your project and works very well! I would like to ask a change, you can add each voltage next to scroll bars each voltage in volts (ej.: 2.8V 4.5V etc.)? thank you very much, please contact me on my mail shark97@tiscali.it my english is bad!

02.04.2013 - 01:17
Name: Moty
Comment: Hi Israel, I could find Master-Prog information in Spanish only. It appears like people have problems using it. Check if you can find people's comments on using it on pic18f2550. If I find something I'll let you know. It is difficult for me to tell what can be the problem without looking at your setup.

01.04.2013 - 04:52
Name: Israel
Comment: Monty, and downloaded the usb counter, my PC still does not know the device, and so I switched Proto and nothing happens. I have some questions: If the pic is wrong, the developer should give me an error, is not it? In this case would have to change pic. (For me the pic work properly) If the developer is wrong, you also send me a write error, no? (but I programmed correctly with this device)

01.04.2013 - 04:23
Name: Israel
Comment: I use the MASTER-PROG programmer, and if indeed I have done projects with PIC 16F84A and the correction function. At this point try with usb counter. As I have echo, informs him of the events. Thanks for listening.

01.04.2013 - 02:44
Name: Moty
Comment: Hi Israel. The folder ASM contains files for the project written in asm code. Folder C-GPL contains files for the project in C code. The codes are only similar in the way they operate the project. I recommend to use the C-GPL hex file but if you want to modify the code and you use asm code then you have to use the asm hex. You can try to program the pic to both hex files and see if any of them work. You can also download the code of the USB COUNTER project and try to program the pic with it, don't build the circuit of the USB counter just write the hex and try if the PC recognizes the device. If the PC doesn't recognize any of the 3 hex files then it is likely that the problem is not with the hex. What pic programmer do you use? have you ever programmed successfully another pic? Make sure your programmer inserts the configuration bits. You can't use bootloader with these hex files.

01.04.2013 - 01:11
Name: Israel
Comment: Hi Moty. Now I have such circuit as in the diagram, I did what you told me and all drivers are okay, do not fail me other than a bookstore? My PC does not recognize the device when connected and when I do them only 3 LEDs light up with the .hex of the C-GPL folder. I have no idea what could be the error, hope you can help me. Thank you.

01.04.2013 - 01:11
Name: Israel
Comment: Hi Moty. Now I have such circuit as in the diagram, I did what you told me and all drivers are okay, do not fail me other than a bookstore? My PC does not recognize the device when connected and when I do them only 3 LEDs light up with the .hex of the C-GPL folder. I have no idea what could be the error, hope you can help me. Thank you.

31.03.2013 - 23:52
Name: Israel
Comment: Ok, I'll check that. Another question, does the PIC what .hex file should I write, does the ASM folder of the folder or the C-GPL? thanks

31.03.2013 - 23:47
Name: Israel
Comment: Ok, I'll check that. Another question, does the PIC what .hex file should I write, does the ASM folder of the folder or the C-GPL? thanks

30.03.2013 - 22:27
Name: Moty
Comment: Hi Israel. If your PC works OK for USB mouse or keyboard then you already have HID driver. It is normally installed with XP. You can try updating your drivers with this Microsoft download: http://xpdrivers.com/microsoft/_2_135761.cfm?gclid=CPfXwZeopbYCFW_KtAod6B4AIw You can also search HP for updated drivers for your model. Make sure that the connections to the USB are correct and that the crystal is 4MHz. Don't use a bootloader to program the PIC, most of them require special firmware. Good luck and don't hesitate to ask more questions. 

30.03.2013 - 03:21
Name: Israel
Comment: Hello, since the program began. Hex on my pic but when I connect it to my PC (Win XP Hp), tells me that it does not recognize the device and that I need drivers. Can you tell me what drivers should I watch?, Or what goes wrong? When connecting the circuit LEDs are lit only pin 21, 22, 24 .. Please help me ..: S

10.07.2012 - 21:04
Name: Moty
Comment: Hi Abdoalreza, With This project you can connect using USB only.

10.07.2012 - 09:11
Name: Abdoalreza
Comment: Hi plase for me code port RS232 to PLC send thank

10.07.2012 - 09:10
Name: Abdoalreza
Comment: Hi plase for me code port RS232 to PLC send thank

21.05.2012 - 04:10
Name: Vaibhav Jain
Comment: Dear Sir: I want to develop USB based applications provided by you. I have some questions;- 1. Is VB6 runs on Win7. 2. how can I make a graph which show volt vs time and amp. vs time with recording. thanks your truly vaibhav

18.12.2011 - 18:16
Name: Moty
Comment: Hi Ali, I'm glad to see that it works well.

18.12.2011 - 07:54
Name: ali
Comment: Hi Moty all inputs (digital and analogue) have problem but outputs work well. I connected pin 2,3,4,5 to earth and it showed that when one pin(2) connected, other input signal decrease, when 2 pin (2,3)or and other pin connected to earth all inputs signal(digital and analogue with together) become 0 and no signal appear. thanks best regard

17.12.2011 - 22:33
Name: Moty
Comment: Hi Ali. Try running the PIC with pins 2,3,4,5 connected to pin 8 (earth). If you still read analogue outputs then it can be the software. Are the digital inputs and outputs working well?

17.12.2011 - 08:27
Name: ali
Comment: hi moty sorry with out connecting any analogue input have signal its my problem.i check earth connection (pin 8 & pin 19)not problem.wire connection is 1 m lenght. i replace 10 uf with 0.47 but i have signal.i dont know i confuse. may be from pic firmware.? thank best regard

11.12.2011 - 18:37
Name: Moty
Comment: Hi Ali, I assume you mean that the analogue output readings aren't stable. Try to connect the analogue inputs of the PIC to earth and if the readings are stable then check your signals for noise. Try to use short USB lead. Try to increase the 0.47 capacitor to 10uF, that will remove noise from the 5V supply.

11.12.2011 - 06:57
Name: ali
Comment: hi moty i assembled and test, it worked,but have very noise ,not constant. what problem or things maybe caused. thanks best regard

09.05.2011 - 08:32
Name: Moty
Comment: Hi Ali, The files p18xxx.h etc are in the system of MPLAB and mcc18 programs. You need those 2 programs to be able to compile the hex file. I attached them to the email in case that you wish to use a different compiler.

08.05.2011 - 04:20
Name: ali
Comment: hi in zip file i can not find p18xxx.h,stdio.h and usart.h .please,how can i get these thank

09.07.2010 - 22:13
Name: Eduardo Ramos & Fernando Mendoza
Comment: Hey, congratulations This is a great job,I was thinking the same, but you did it, can you send me the c code? eduardoramogaz@hotmail.com --> Eduardo' mail v771v771@hotmail.com --> Fernando's mail we would like to make like a router so with this we can cotroll the device