PIC and USB
PIC and USB
Everyone,
I notice a lot of posts here regarding getting a PIC microcontroller to communicate with a PC via USB. After a couple of weeks of struggling myself I had some significant breakthroughs, and learned quite a bit in the process. So, I wrote down what I learned, created a PDF file, and posted it on the Internet to share in the hopes it would help someone else and possibly prevent them from going through weeks of steep learning and frustration like I did!
http://www.ktgunsmith.com/other/PIC_and_USB_3-80.pdf
This is not supposed to be the final resource on USB communication, but will hopefully answer a lot of questions and again, help someone like myself get started. Your comments are always welcome, folks.
BTW, I want to especially say thanks to folks on this forum for providing answers, and also thanks to the mikroElektronika team for their excellent EasyPIC6 development board and mikroBASIC Pro compiler, their libraries, and examples that really helped accelerate my learning.
Cheers,
Roy
Edited 07/17/2010: Updated link to new document for use with mikroBASIC PRO version 3.85.
I notice a lot of posts here regarding getting a PIC microcontroller to communicate with a PC via USB. After a couple of weeks of struggling myself I had some significant breakthroughs, and learned quite a bit in the process. So, I wrote down what I learned, created a PDF file, and posted it on the Internet to share in the hopes it would help someone else and possibly prevent them from going through weeks of steep learning and frustration like I did!
http://www.ktgunsmith.com/other/PIC_and_USB_3-80.pdf
This is not supposed to be the final resource on USB communication, but will hopefully answer a lot of questions and again, help someone like myself get started. Your comments are always welcome, folks.
BTW, I want to especially say thanks to folks on this forum for providing answers, and also thanks to the mikroElektronika team for their excellent EasyPIC6 development board and mikroBASIC Pro compiler, their libraries, and examples that really helped accelerate my learning.
Cheers,
Roy
Edited 07/17/2010: Updated link to new document for use with mikroBASIC PRO version 3.85.
Last edited by roys29 on 20 Jul 2010 14:18, edited 3 times in total.
- nikola.kostic
- mikroElektronika team
- Posts: 433
- Joined: 11 Aug 2009 12:12
-
- Posts: 35
- Joined: 08 Feb 2007 11:25
Ok, I sent my 5 axis, 32 button joystick controller project up to ME following their guidelines. A quick synopsis of this program:
PIC18F2455, 8mhz crystal, mikroBASIC Pro v2.50, EasyPIC6 board.
5 analog inputs each connected to a 100k ohm linear potentiometer provide joystick axis control.
Up to 32 push-button or toggle switches are connected through diodes to a 6 x 6 switch matrix. (Although this gives 36 connections, Windows only recognizes a maximum of 32 buttons on a joystick). Because a toggle switch provides a constant "on", the program actually sends a pulse to the PC. The pulse is adjustable through a 6th analog input to the PIC.
Roy
PIC18F2455, 8mhz crystal, mikroBASIC Pro v2.50, EasyPIC6 board.
5 analog inputs each connected to a 100k ohm linear potentiometer provide joystick axis control.
Up to 32 push-button or toggle switches are connected through diodes to a 6 x 6 switch matrix. (Although this gives 36 connections, Windows only recognizes a maximum of 32 buttons on a joystick). Because a toggle switch provides a constant "on", the program actually sends a pulse to the PC. The pulse is adjustable through a 6th analog input to the PIC.
Roy
Hi Roy
What are the amount of bytes you are sending and how fast ,
I have an Application in a proto type vehicle where I send HID bytes
(34 bytes every 30 mSec) to a PC running the MPHID class driver from Microchip ,
and every now and then the PC will hang and the USB communication is lost ,
although I can see that the microcontroller is running as the messages on the CAN Bus is still running ,
I am just not sure if it is the PC side (Windows or the MPHID class)
or the micro HID code causing the problem,anybody have such difficulties
would be nice to hear about it
I am considering going back to Rs232 coms in the project as my HID is just not stable
Regards
Peter
What are the amount of bytes you are sending and how fast ,
I have an Application in a proto type vehicle where I send HID bytes
(34 bytes every 30 mSec) to a PC running the MPHID class driver from Microchip ,
and every now and then the PC will hang and the USB communication is lost ,
although I can see that the microcontroller is running as the messages on the CAN Bus is still running ,
I am just not sure if it is the PC side (Windows or the MPHID class)
or the micro HID code causing the problem,anybody have such difficulties
would be nice to hear about it
I am considering going back to Rs232 coms in the project as my HID is just not stable
Regards
Peter
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
hello,
I'm new on this forum and I'm trying to learn how work USB. English is not my first language but I hope you understand all I say.
In first, Roys29, thanks for your work.
I'm trying to program something but I've got a problem.
I work with a free mikroBasic Pro version 3.2 on Vista and I have a easy pic 5. When I want to Build the project, the compiler has a problem with "Dim dummy as byte Volatile register" ( inconsistant type) and don't generate the usbdsc.mcl. Do you know the problem?
Regards
I'm new on this forum and I'm trying to learn how work USB. English is not my first language but I hope you understand all I say.
In first, Roys29, thanks for your work.
I'm trying to program something but I've got a problem.
I work with a free mikroBasic Pro version 3.2 on Vista and I have a easy pic 5. When I want to Build the project, the compiler has a problem with "Dim dummy as byte Volatile register" ( inconsistant type) and don't generate the usbdsc.mcl. Do you know the problem?
Regards
patman
take a look at this post it decribes how to handle the problem you are having
http://www.mikroe.com/forum/viewtopic.php?t=22144
Regards
take a look at this post it decribes how to handle the problem you are having
http://www.mikroe.com/forum/viewtopic.php?t=22144
Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------
Peter,
If you look at the joystick project I posted to the ME projects page, you will see I am reading 3 analogue inputs with the associated delay built into the ME ADC library. I am also polling a 2x8 switch array with 32.1 milliseconds of delay. I'm not quite sure what the total delay is between USB writes but I am only sending 5 bytes. We worked with that joystick for a couple of hours the other night with no problems.
If you look at the joystick project I posted to the ME projects page, you will see I am reading 3 analogue inputs with the associated delay built into the ME ADC library. I am also polling a 2x8 switch array with 32.1 milliseconds of delay. I'm not quite sure what the total delay is between USB writes but I am only sending 5 bytes. We worked with that joystick for a couple of hours the other night with no problems.
Roy
This is exactly the problem some times it would run for hours with out any hick ups and then just one day when whether has changed windows would hang and do all sorts of funny things with funny error reports
I just dont know any more where to search
Regards
Peter
This is exactly the problem some times it would run for hours with out any hick ups and then just one day when whether has changed windows would hang and do all sorts of funny things with funny error reports
I just dont know any more where to search
Regards
Peter
P.Erasmus
Saratov,Russia
--------------------------------------------------------------
Saratov,Russia
--------------------------------------------------------------