PIC and USB

General discussion on mikroBasic PRO for PIC.
Author
Message
roys29
Posts: 106
Joined: 13 Oct 2009 15:09

PIC and USB

#1 Post by roys29 » 29 Oct 2009 21:18

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. :wink: 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! :x

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. :lol:

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.

User avatar
nikola.kostic
mikroElektronika team
Posts: 433
Joined: 11 Aug 2009 12:12

#2 Post by nikola.kostic » 30 Oct 2009 14:39

Thank you for writing and sharing what you have learned Roy.

Btw. our website is mikroe.com, not mikro.com :wink:

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#3 Post by p.erasmus » 30 Oct 2009 15:17

Hallo Roy
Thank you very much for searing your work with us
it is clear that you have made an large effort into this
many many thanks to you :D :D
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

#4 Post by roys29 » 30 Oct 2009 20:28

Nikola,
Sorry, my bad. I'll correct the URL to your web site and post a new copy.

P. Erasmus, I've read a number of your responses to other threads and find your answers clear, thoughtful and helpful. Praise from you is very well received. Thanks.

Roy

RichardHirst
Posts: 35
Joined: 08 Feb 2007 11:25

#5 Post by RichardHirst » 31 Oct 2009 01:00

Hi Roy

Excellent information you have given, I have been wanting to create a Joy Stick for some time.

Would you be willing to Post the complete code on Mikro's web sit ein the Projects sections.

Thanks

Richard

Colin
Posts: 738
Joined: 15 Oct 2007 08:53
Location: Australia

#6 Post by Colin » 31 Oct 2009 04:19

Well done Roy,
and perfect timing.
I am going to try out some USB code this weekend. Now I can have your tutorial up on my other monitor.

Thanks a lot.
Colin

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

#7 Post by roys29 » 31 Oct 2009 14:05

Ok, I fixed the URL to ME's web site, sorry for the mistake.

Richard, I'll see about getting my code up in the projects section. Howeer, the link I provided to Amr Bekhit's web site does a pretty good job of describing the code.

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

#8 Post by roys29 » 31 Oct 2009 16:03

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

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

#9 Post by roys29 » 28 Nov 2009 15:16

BTT :D
I made a few additions and corrections to the document. This is a nice resource for those just getting into programming PICs and trying to get them to communicate with USB.

Enjoy,

Roy

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#10 Post by p.erasmus » 28 Nov 2009 15:39

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 :D
I am considering going back to Rs232 coms in the project as my HID is just not stable
Regards
Peter
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

patman
Posts: 2
Joined: 23 Nov 2009 15:36

#11 Post by patman » 28 Nov 2009 18:30

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

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#12 Post by p.erasmus » 28 Nov 2009 19:07

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
:D
Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#13 Post by p.erasmus » 28 Nov 2009 23:45

Could you please post your code and descriptor file
it would be interesting to look at it and possibly we can see the error
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

roys29
Posts: 106
Joined: 13 Oct 2009 15:09

#14 Post by roys29 » 29 Nov 2009 12:55

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.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#15 Post by p.erasmus » 29 Nov 2009 13:36

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 :evil:
Regards
Peter
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Post Reply

Return to “mikroBasic PRO for PIC General”