PDA

View Full Version : USBDemo, something to learn USB a little bit



Pages : [1] 2

mister_e
- 31st December 2006, 01:52
Hi all,
Since the USB stuff is coming more and more popular, and as we see more and more questions, i decided to post my little contribution.

OK OK You already asked... but i'm in a good moon today, so let me believe it never been asked before ;)

The whole thing will use a PIC18F4550 and a 4MHz crystal + few Leds, 2 trim pot... you should be able to figure this out easy.

There we go, here's the PC interface,


<img SRC="http://www.mister-e.org/Pics/USBDemo.JPG">

Sounds good eh?

With this you can
play with both CCP (PWM) duty cycle and show it on 2 leds attach to your PIC CCP i/o (PORTC.1, PORTC.2)
modify each PORTB bits status as you wish.


You can also
see the results of AN<1:0> ADC results in the progress bars
monitor the status of those push-buttons attach to PORTA<5:2> inputs (with pull-down resistors)
receive text string
Display your VendorName and ProductName.

So almost everything EASY will be covered in both code.

I tried to stay away of the cryptic-fashioned coding but i couldn't resist to use some macro etc etc. Eh, maybe you'll learn from it? Who knows?

In attachment, you'll find ALL FILES. PBP source code and VB6 source code AND a ready to run USBDemo.exe file. Everything is hardly commented so, read it carefully... it won't hurt!

The original folder was c:\PBP_PROG\USBDemo but it shouldn't cause any problem... well i guess. If so, you know where to send them.

NOTE: If you're going to use LONG variables, you MUST copy the PIC18Xxxxx.BAL file in your source directory as well, unless you'll receive some compilation errors.

The .BAL file is located in \PBP\USB18 directory.

Those who want to use PIC18F2455, 18F2550, have a look at post 99.
http://www.picbasic.co.uk/forum/showpost.php?p=38468&postcount=99


Enjoy!

Jerson
- 31st December 2006, 07:52
Hi Steve

Thanks for sharing your work with us. I for one have never designed around USB till now, but, have something to back me up now.

Anyway, I looked at the VB code and have a question. There is a MCHID.DLL on which the code depends. Where do I get this? On the Microchip site or is it something you built?

I hope you see this the first thing on the 1st morning of the new year. So, I wish you and the community here a HAPPY NEW YEAR in anticipation.

Jerson

skimask
- 31st December 2006, 09:28
No kidding! I've been a bit weary of trying out a bit of playing around with a PIC and a USB. Previously, I've only used the FTDI chips or the CP2102/2103 combo's. This little application could save me a fair amount of PCB space.

Question in regards to the onchip transceiver. Where would one NEED or prefer to use an external transceiver for the USB, or, conversely, where would one want to use the internal transceiver exclusively?

And BTW, thanks a lot, mister_e. Now I've got another project to play...like I don't have enough to play with to keep me up late at night as it is :)
JDG

mister_e
- 31st December 2006, 10:16
Anyway, I looked at the VB code and have a question. There is a MCHID.DLL on which the code depends. Where do I get this? On the Microchip site or is it something you built?

This DLL comes with Mecanique EasyHID... wich i use all the time to generate those code template. I can't believe it's free http://www.mister-e.org/Pics/mad2.gif

So just download and install EasyHID HERE (http://www.mecanique.co.uk/products/usb/easyhid.html) and this will solve the problem.



No kidding! I've been a bit weary of trying out a bit of playing around with a PIC and a USB. Previously, I've only used the FTDI chips or the CP2102/2103 combo's. This little application could save me a fair amount of PCB space.


indeed, it's a little tricky those first time, but once you have rebooted you computer over 1000 time to solve the USB connection failure, you learn really fast :D



Question in regards to the onchip transceiver. Where would one NEED or prefer to use an external transceiver for the USB, or, conversely, where would one want to use the internal transceiver exclusively?

Sorry i can't help on that, i never use an external one. But probably THIS (http://www.fairchildsemi.com/an/AN/AN-5015.pdf) or THIS (http://www.maxim-ic.com/appnotes.cfm/an_pk/3891) could help ?



And BTW, thanks a lot, mister_e. Now I've got another project to play...like I don't have enough to play with to keep me up late at night as it is

Who need to sleep anyways :D

You're welcome AND enjoy!

malc-c
- 2nd January 2007, 01:28
The whole thing will use a PIC18F4550 and a 4MHz crystal + few Leds, 2 trim pot... you should be able to figure this out easy.

Thank goodness you didn't choose the 18F2550 - :) :) :)

Steve, nice project, maybe this should be made a sticky in the main PBP section

mister_e
- 2nd January 2007, 01:37
Hehe, but.. will your PicProgrammer be able to program it ? ;)

First, i wanted to post it in the USB section... But, Code Examples have to be post in the right section...

Hope you may use some part of it one day.

Bear in mind it's only a Demo and a 1-2 hours job.. yeah i count the beer, coffe and cigarette breaks, but remove those phone calls i got when doing it... always like that when you don't want to be disturbed :D

Darrel Taylor
- 9th January 2007, 22:46
Mister_E,

I fart in your general direction ....

This is all your fault. I've been totally cosumed by this USB stuff for several days now. I've been so affraid of USB for so long. But after your example showed how easy it is, I've been locked in a never ending cycle of, "hmm, what else can I do with it".

Consequently, I've accomplished nothing else, "including going to work yesterday" :eek:

I haven't answered your ASM question in the other thread (or anyone elses), I haven't eaten much, and Sleep is a requirement that I would have rather done without (wish I could).

I'd like to say "Thank you for the great example", but it's ruining my life.

So instead I'll say ...
Thanks for the Mean, Vicious, Natsy, Brutal, Sadistic, yet Wonderfull piece's of code. :)
<br>

mister_e
- 10th January 2007, 00:12
Disclaimer

Mister E assume no responsibility for any addictions caused by the use of this actual thread, program, tutorial...
call it as you want.

Mister E don't want to be involve in any of your future or actual health, job and/or girlfriend/wife/boyfriend problem!
So use with care.

You read it, you use it... it's your problem what's happen next.

LMAO!
\_________________________________________________ ________________________________________________/

<table><tr><td>http://www.mister-e.org/Pics/ComplaintDept.gif</td><td>Well Darrel i'm really sorry (yeah right), but at the same time... i'm proud of me. At least you lost this USB fear! And i think, for once, i teached you something... ???

You know, I already said to few user here and there that PIC are addictive... i thought you took the advice... seems not... so

TOO BAD FOR YOU !</td></tr></table>

Now, go to sleep, eat and go back to work http://www.mister-e.org/Pics/whip.gif

skimask
- 10th January 2007, 04:34
Mister_E,

I fart in your general direction ....

This is all your fault. I've been totally cosumed by this USB stuff for several days now. I've been so affraid of USB for so long. But after your example showed how easy it is, I've been locked in a never ending cycle of, "hmm, what else can I do with it".

Consequently, I've accomplished nothing else, "including going to work yesterday" :eek:

I'd like to say "Thank you for the great example", but it's ruining my life.

So instead I'll say ...
Thanks for the Mean, Vicious, Natsy, Brutal, Sadistic, yet Wonderfull piece's of code. :)
<br>

No kidding! I'm looking forward to reducing my sanity, food intake, sleepy time, and probably the wife soon after my 18F4550's arrive. So, if mister_e gets a call in the middle of the night from a screamin' female who he doesn't know, this thread is most definetly the reason why.
I wonder how long it'll take before he's on the 'Jerry Springer' show as the unseen homewrecker.

Thanks a lot...
May the demons of evil get confused on their way to your doorstep! :)

mister_e
- 10th January 2007, 05:34
So, if mister_e gets a call in the middle of the night from a screamin' female who he doesn't know, this thread is most definetly the reason why.

No problem then, my phone number is not hidden anyway... But, LOL, maybe she will have to repeat few times and be patient when i will try to reply to her... yeah my english writing is bad... imagine how bad i talk :D

skimask
- 11th January 2007, 18:49
No kidding! I've been a bit weary of trying out a bit of playing around with a PIC and a USB. Previously, I've only used the FTDI chips or the CP2102/2103 combo's. This little application could save me a fair amount of PCB space.

Question in regards to the onchip transceiver. Where would one NEED or prefer to use an external transceiver for the USB, or, conversely, where would one want to use the internal transceiver exclusively?

And BTW, thanks a lot, mister_e. Now I've got another project to play...like I don't have enough to play with to keep me up late at night as it is :)
JDG



I forgot to order USB connectors. The average project will use a USB Type B Female on the box of the side of the project, right? Example....the 'normal' cable that a person would buy down at the local store has Type A male on one end, and Type B male on the other end, or is that wrong too? I know on the last 2 USB projects I've done (and this was just to get rid of the wrong stuff I bought in the first place), I had to go out and get special cables made up because I bought the wrong gender at both ends with the wrong type (A or B) at each end :) I done good with that one...

mister_e
- 11th January 2007, 18:56
It's up to you guy, you know there's also this tiny model on digital camera ( or PICKIT 2) as well.... i don't remind the name...

But most of the time, use a 'B type' on the PIC end... if you really want a connector.

In meantime you can still hack an old USB mouse or buy a few $ USB cable. i got few 6' here in a local electronic store for 2$.

Please, use an external psu for you tests.... you never know what could happen.

EDIT.... i thought they could choose a more sophisticated term for those mini-tiny-usb connector... NOP mini-A or mini-B :D
http://en.wikipedia.org/wiki/USB

skimask
- 11th January 2007, 20:21
Mini- connectors - Those seem to be a bit more prevalent these days as opposed to the older/larger types. Will probably switch over to those in due time. A-type at the PC end, B-type female (mini or not) at the device end.

External power - yes, most definetly. In the past, I've drawn a small bit of power off the USB bus to charge a small AAA NiMH pack, but the bulk of the power for the circuit comes from the AAA NiMH pack.

keithdoxey
- 11th January 2007, 20:25
Please, use an external psu for you tests.... you never know what could happen.

Oh yes I do :( :(

I have a board that I have been working on and had no problems with it whatsoever until I moved it slightly on the computer desk and my daughter had left a metal hair grip on the desk.

Now have a PC with 4 dead USB ports on the mobo :(

mister_e
- 11th January 2007, 20:33
:eek: and unless you want to waste your time debugin it... maybe it's just some blown pcb tracks...

A in-line fuse could be used as well, but i stick with the external PSU.

To do this one i used Mikroelektronika a EasyPic 4 board.

http://www.mikroe.com/en/tools/easypic4/images/easypic4_500.jpg

Nice board, but the on-board programmer fail sometime with 18Fs device.

Squibcakes
- 12th January 2007, 02:26
Bravo, Bravo, Bravo!!!

Steve that EasyPic 4 board looks fantastic! I see that it has an add on PLCC programming kit but in your experience can it program the PIC18F4550??

Has anyone made a test PCB for this yet and willing to post on site?

Cheers
Squib.

mister_e
- 12th January 2007, 02:34
The on-board programmer work with most PIC. The 18F4550 also work... but sometime it fail to program at the first time, you just need to reprogram it once again... no big deal but sometimes annoying.


http://www.mikroe.com/en/tools/plcc/images/plcc_onboard_200.jpg

I don't have the PLCC board, but it should work... it's just an adapter, so i don't see why it shouldn't work... unless the programming pins are not at their usual places...

skimask
- 12th January 2007, 04:45
The on-board programmer work with most PIC. The 18F4550 also work... but sometime it fail to program at the first time, you just need to reprogram it once again... no big deal but sometimes annoying.


http://www.mikroe.com/en/tools/plcc/images/plcc_onboard_200.jpg

I don't have the PLCC board, but it should work... it's just an adapter, so i don't see why it shouldn't work... unless the programming pins are not at their usual places...

I made an adapter for an '8722 awhile back that puts it in a 40pin 18F socket using a 40 wire ribbon cable on an IDC socket (think '452 with a load more memory), and another 40pin dual row to get to the rest of the pins. Do you think that would work in this? It worked in my mp3 player.

mister_e
- 12th January 2007, 04:49
In theory... all 40 pins device have the programming pins at the same place or the EasyPic 4 would have a second 40 pins dip socket.

charudatt
- 12th January 2007, 14:39
Here's a small contribution from my end to support the good work.

Thank you steve for the help

regards.

skimask
- 12th January 2007, 15:58
Here's a small contribution from my end to support the good work.

Thank you steve for the help

regards.

And I would think that a similar dev board for a '4550 would be practically the same except for the obvious pin differences...
I hope so...'cause that's what I'm building...still waiting on the '4550's though...

mister_e
- 12th January 2007, 21:23
Sure,

There's just a little something i would point so far. Yes the 1.5K is recommended if you don't enable the internal one as i did. Now i think the generic code do it for us... but for safety sake i did it in mine. the two 100nF could be replace with a 470nF. In some occasion it seems to be better when using a higher value. EasyPic 4 use 2X110nF but i changed it. It's just for safety sake so far. If it's working for you... use it ;)

Now, the Darrel's code mod comes really handy. It free 1 timer... really interesting...

Instant Interrupts - Revisited, post 148
http://www.picbasic.co.uk/forum/showpost.php?p=30682&postcount=148

Thanks to everybody posting in here!

vacpress
- 18th January 2007, 21:46
Does anyone know if i can substitute a different value for the 470nf capacitor that pulls the usb+ to vcc? Somehow I haven't got any nf value capacitors - plenty of pf, uf...

I read a post somewhere at some point where a guy said he was using a 2.2uf and it worked ok.

Thanks

Robert

vacpress
- 18th January 2007, 22:27
Hey!

First, Mister E, thanks so much for putting this together, I can tell it will be a huge springboard for me, if i can ever get it to work!

I already mentioned that I am using a 10pf capacitor instead of the 470nf one specified. I haven't got any nf capacitors at all! oi!

Anyways, i loaded the included .hex(still cant compile it from source) and my computer recognizes an 'unknown usb device', not a HID device. :(

Ive got a 4mhz resonator on there.. i tried it with a 20mhz and it didn't seem to do anything.

Any advice please?! I took the day off work to do this stuff today, and it is frustrating!

Thanks!

Robert

vacpress
- 23rd January 2007, 09:55
i got it to work! Now to understand it all! Not to mention get it working alongside a USB bootloader.

Thanks for the example. The code looks excellent. Way beyond anything I can conceive of.

cheers.

Squibcakes
- 24th January 2007, 06:15
Yep got mine working today too!!! Woo Hoo!!

Golly gosh, loaded Mr E's sample prgram, connected the USB cable and Presto - Windows detected it and it started to work first time!!!

On the demo PCB I added a serial connector so that I can program the 18F4550 via serial ICSP, and also added a couple a RS422/232 line driver receiver so that the PC can communicate via USB to serial devices.

I'm sure I'll have more to add once I've played around with this toy some more.

Cheers
Squib.

See photo attached.

Darrel Taylor
- 24th January 2007, 06:25
Now there's a circuit that made for the mister_e USBDEMO.

Uhhh, let me guess.

USB to DMX convertor?
<br>

vacpress
- 24th January 2007, 22:51
hey squibcakes - nice demo board..

question... you have 3 LEDs by you USB port, is one an activity indicator by chance? I want to put a activity LED on my USB, and was wondering if that is what you have there..

what do you plan on doing with that board, just learn? i considered building a special purpose mister e pcb as well.. but didnt.. instead i put most of the circuit on a protoboard from demicro.com, and the rest is on a breadboard with leader from sockets i put on the protoboard IO..

that code mister e posted is.. yeah... have you got any plans to move it into .net? i may start a seperate thread detailing my progress attempting to convert the usbdemo software from vb6 to .net... i dont know if i can do it without help...

thanks!

Robert

Squibcakes
- 25th January 2007, 00:09
Hi Vacpress,

The Two LEDs are for the PWM output and the Other green led is just connected to Vdd to indicate that there is power on the board.

I built the board for two reasons -
1. Get a grip on all this USB stuff
2. Use it as a programmer for these chips.

I added a DB-9 / Max3486 chips so that I can learn a bit about serial to usb as well.

Now can someone please explain how to use Microchip's CDC? http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2124&param=en022625

No plans for Dot net. We use PowerBasic around these parts.

Cheers

vacpress
- 25th January 2007, 05:26
powerbasic. cool... i wish i wasnt addicted to the VB language...

if vb would compile for mac like powerbasic does i would be extremely happy.. in the meantime ive downloaded so much stuff in an attempt to learn cross compatability... and never really got too far, as i havent got a mac so it is no fun..

hehe... you must use power basic cuz its free... i like .net express for the same reason!

how is the usb battle going? any luck comprehending the usbdemo code? it sure looks different from my picbasic code!

currently i am trying to find the best usb bootloader, hopefully one that has code for the PC side as who knows, I may eventually develop something marketable!

carry on
-robert

Squibcakes
- 25th January 2007, 05:43
Yeah your right it is a battle!

Couple of things.,... I am finding that jumping straight into USB with these 18F chips may be a bit ambitious.

These 18F series do seem to be a bit more complex than your average 16F chips.

Just getting my head around the config fuses and using mpasm as opposed to using PBP Compilier is mind boggling but I think I got it.

At this stage I'm just trying to get the 18F to flash the LEDs and stuff LOL!

On another note, I tried to compile Mr E's usbdemo.pbp file and I get all soughts of errors. Any idea why? I mean the hex file works, but cant I compile his pbp file. I want to make sure that I can get the basics working first.

I tried tiny bootloader which apparantly supports 18F4550 chips but couldnt get it to work yet.


Squib

mister_e
- 28th January 2007, 23:10
On another note, I tried to compile Mr E's usbdemo.pbp file and I get all soughts of errors. Any idea why? I mean the hex file works, but cant I compile his pbp file. I want to make sure that I can get the basics working first.

mmm, i suspect those usuals
1. upgrade your MPASM version
2. comment all default PBP config fuses in the 18F4550.inc file, AND if you don't have PBP 2.47, modify the LIST line to.....

LIST p = 18F4450, r = dec, w = -311, w = -230, f = inhx32

once done, if everything is in the same directory, it MUST work!3

for the Tiny loader, i know there's some DEFINEs to add... wich? i don't know, i don't and won't use it.

mister_e
- 28th January 2007, 23:12
how is the usb battle going? any luck comprehending the usbdemo code? it sure looks different from my picbasic code!


What's not clear enough?

Squibcakes
- 30th January 2007, 03:11
HI Mr E,

Yep tried that but still get those errors BTW I have Mpasm 5.03, PBP 2.46.

Anyways after searching the posts the only thing that works is this (I think maybe one of your ideas)....

Don't use any preset fuses in the main code, and edit them manually in the .inc file. This for sure is working!!!

I have all the fuses setting in this file, and just REM out the ones I dont use.

OK after all that, I now have some simple programs working on the demo PCB at last including my serial coms!!!

Squib

mister_e
- 30th January 2007, 04:50
interesting. So i can't confirm if it's a MPASM problem (5.06 now) or a PBP V2.46 problem.

I know they fixed the config fuse problem in 2.47, but can't say if they have only edit the .INC file (LIST line) or they also change something else.

Anyways, if it's working :)

Squibcakes
- 30th January 2007, 06:46
Mr_E
Yeah ok well thanks for your input anyway - always welcome I'm happy to edit the the .inc file and leave it at that.

Great news! I finally got the CDC virtual comport working!!!!!!

Now I can send data via USB (virtual comport) and out of the Pic 18F4550 USART! and vice versa!

I'm stoked that this actually works!

Squib

xxdymhbh
- 30th January 2007, 09:01
Thanks for your sharing!

:)

Noise.be
- 22nd February 2007, 02:17
Thanx for share

I have a problem when I program the PIC with the version of the zip and that I makes all the connection necessary,
I connect it on the USB and Windows says to me every 3 minutes Unrecognized device

20MHz
10nF on pin 18
resistor 1k5 on pin 23 ?

what did I wrong?

mister_e
- 22nd February 2007, 02:22
This example use a 4MHz crystal (as stated in the code and in post #1), and i suggest something higher than 220nF and you don't need the 1.5K resistor as i set the internal one.

Now if you want to stick with the 20MHZ crystal, you'll need to modify the first __CONFIG line to

__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L

all should be fine after that.

Darrel Taylor
- 22nd February 2007, 02:31
For 20mhz, you also need ...
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEM_OFF_1H & _IESO_OFF_1H

mister_e
- 22nd February 2007, 02:35
<table><tr><td>http://www.mister-e.org/Pics/DOH.jpg</td><td>Newbie mistake from me... At least heaven's voice saved the day :D</td></tr></table>

ozion
- 22nd February 2007, 02:41
Bravo, Bravo, Bravo!!!

Steve that EasyPic 4 board looks fantastic! I see that it has an add on PLCC programming kit but in your experience can it program the PIC18F4550??

Has anyone made a test PCB for this yet and willing to post on site?

Cheers
Squib.

Hi Squibcakes,
I have an older model 'EasyPic3' and i have no problem to program PIC18F4550. It is a great board and I ma glad owning one.
Cheers
Ozion

Darrel Taylor
- 22nd February 2007, 05:01
<img src="http://www.pbpgroup.com/files/zombie2.gif" align=middle> &nbsp; &nbsp;Heaven you think?http://www.pbpgroup.com/files/skeleton-9.gif
Goood..., then you won't notice when I come to collect your PBP soul.

<div style="background-color:#000000"; layer-background-color:#000000;>http://www.pbpgroup.com/files/monsters36.gif</div>

Noise.be
- 22nd February 2007, 13:48
Many thanks!!! Got it working, now I'll proceed to port it for my purposes.

I've change the 2 lines and one thing more

__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC3_PLL4_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEM_OFF_1H & _IESO_OFF_1H

Darrel Taylor
- 22nd February 2007, 14:20
Curious,

That means the CPU is running at 24mhz.
Why not run at 48mhz, since it's available.
_CPUDIV_OSC1_PLL2_1L
<br>

Noise.be
- 22nd February 2007, 14:53
because windows don"t detect the hardware at 48MHz

Darrel Taylor
- 22nd February 2007, 15:08
Sure it will!

Did you have...

DEFINE OSC 48

I use 48mhz CPU with USB without any problems.
<br>

Noise.be
- 22nd February 2007, 23:56
Here is my version of the code (http://noisettes.dyndns.org/USBDemo.pbp)

Darrel Taylor
- 23rd February 2007, 03:46
I can't make it NOT recognize the device when the OSC is 48 with 20mhz crystal.

Did you increase the size of the VUSB cap like mister_e suggested?

The way you have it now, the CPU is running at 24mhz. But, PBP thinks it 48mhz because of the DEFINE OSC 48. Any Time related statements will take twice as long.

If you are going to leave it at 24mhz? You should change to
DEFINE OSC 24

But I'd suggest trying 48 again.
<br>

Noise.be
- 23rd February 2007, 14:07
Yup I've changed the cap to 220nF
I've tried many configurations

20MHz Crystal
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L ;with OSC 48 ; NON-WORKING
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC3_PLL4_1L & _USBDIV_2_1L ;with OSC 24 ; WORKING

4MHz Crystal
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L ; with OSC 48 ; NON-WORKING ;Original post
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC3_PLL4_1L & _USBDIV_2_1L ; with OSC 24 ; WORKING

Noise.be
- 23rd February 2007, 21:47
I've seeking all the day to find the solution, I thus don't find it now I would continue to use it under 24MHz
But now I am occupied to migrate the code from VB6 towards VB.NET 2005 but I have a problem. I suppose that the post here is not welcome ?

mister_e
- 24th February 2007, 16:24
unless you have a faulty PIC, a faulty OSC , or your Vusb cap it too low (or bad), it have to work AS IS.

Windows XP or Vista?

Connected on a USB HUB or not?

For the code conversion i can't help, i still use VB6. Start a new thread, maybe some could give you some tips.

Squibcakes
- 28th February 2007, 01:05
Hi mr_e,

I'm learning how to use Easy HID, and have a question about the PBP output files.

If I copy the files into the same folder as as your demo files (using same names etc) and then run, the push buttons don't have an effect and the 2 var POTS don't work, LEDS and PWM are ok.

After doing a compare with your original files and the easy HID output the difference is in the DESCUSBDemo.asm file.

There are two lines that perhaps you have manually modified?? They are in the **** INPUT OUTPUT REPORT ***** sections, specifically:


; report count (number of fields)
retlw 0x95
retlw 0x08


Why have you have changed the value from EasyHIDs default of 40 to 8?

Once changing the value from 40 to 8 my EasyHID files work with your VB program.



Cheers
Squib

b1arrk5
- 1st March 2007, 03:21
Great job Steve! I have your program running great on a MELABS LABXUSB board, I just took out your asm section for the config fuses (I'm running a 20 MHz crystal,) since my .inc file was already set up for 20 MHz, and changed portb to portd. The LABXUSB board has some leds on portd already. Works great! Thanks for getting us started with USB.

Jerry.

mister_e
- 1st March 2007, 19:13
Hi mr_e,

I'm learning how to use Easy HID, and have a question about the PBP output files.

If I copy the files into the same folder as as your demo files (using same names etc) and then run, the push buttons don't have an effect and the 2 var POTS don't work, LEDS and PWM are ok.

After doing a compare with your original files and the easy HID output the difference is in the DESCUSBDemo.asm file.

There are two lines that perhaps you have manually modified?? They are in the **** INPUT OUTPUT REPORT ***** sections, specifically:


; report count (number of fields)
retlw 0x95
retlw 0x08


Why have you have changed the value from EasyHIDs default of 40 to 8?

Once changing the value from 40 to 8 my EasyHID files work with your VB program.



Cheers
Squib
sorry... but as far as i remind, i'd never ever do any change to it :( Weird, other have tested it, and proved to be working... :eek: can't say what is wrong.

EDIT.. are you using a 4550?

mister_e
- 1st March 2007, 19:14
Great job Steve! I have your program running great on a MELABS LABXUSB board, I just took out your asm section for the config fuses (I'm running a 20 MHz crystal,) since my .inc file was already set up for 20 MHz, and changed portb to portd. The LABXUSB board has some leds on portd already. Works great! Thanks for getting us started with USB.

Jerry.
You're welcome!

Enjoy!

Squibcakes
- 2nd March 2007, 21:33
HI Mr_e

Yep using the 18F4550.

Thats a strange one, because without changing those two lines, It just doesnt work.... which kind of makes me think that easyHID isn't really that "easy" (If you have to make modifications)

I'll have to play with it some more, but to be honest I'm not into VB programming so HID isn't on of my top list of projects....would be nice to know a bit about it to help others one day.

Squib

Darrel Taylor
- 3rd March 2007, 02:16
There are two lines that perhaps you have manually modified?? They are in the **** INPUT OUTPUT REPORT ***** sections, specifically:


; report count (number of fields)
retlw 0x95
retlw 0x08


That number is changed by easyHID according to the number in the Buffer (Input) field on the "Configuration Details" screen.

If you enter 64 for the input (or output), you get
retlw 0x95
retlw 0x40

But, Steve's program is only set up for 8.
<br>

SterlingY
- 14th March 2007, 02:09
This message will now be rendered useless. I wanted to delete it, but since I can't, I've put this stupid line here.

Squibcakes
- 14th March 2007, 03:50
Hi,

Having a problem with the MCHID.DLL.

My HID device works well on my development PC - but when I plug it into another PC (both running XP), windows automatically assigns it's own HID.DLL, and thus the device doesnt work. (It appears in devicemanager correctly)

How do I force XP to use the MCHID.DLL when there are no .inf files to use?

Cheers
Squib.

Noise.be
- 14th March 2007, 22:41
I've always MCHID.DLL in the same dir as the executable :-) that helps

Squibcakes
- 15th March 2007, 00:28
Yeah but... let me clarify,

I've made a USB HID device (rudder pedals for my flight sim to replace my old gameport rudder pedals) and used Easy HID to make the necessary files.

When I plug it into the my Development PC with PBP etc installed, windows detects and it installs them perfectly! The pedals shows up in the game controllers list automatically and I can use them properly, ie calibrate them.

But when I plug the pedals into my Gaming PC, windows detects them and intalls a driver for it (show up in the system device list), but it doesn't show up in the game controllers list, thus I can't use the peddals.

I've tried other pc and the same happens.

I'm not creating any application to go with these pedals, I just want to plug them into any pc and have it work.

I'm not sure if it is a driver issue, or just a blonde moment. LOL.

Cheers

SterlingY
- 15th March 2007, 04:06
mister e,

Great stuff. A lot of good things to learn in your example.

So I've decided to make my own version, but I have run into a hurdle with EasyHID. Has anyone had trouble installing it? I need to mcHID.dll, but I can't install the software on my XP64 machine. The setup.exe program just seems to hang, without ever bringing up the install screen. And on my win2K machine, I get an error that it can't create the mcHID in the winnt/system32 folder.

Any thoughts?

-Sterling

SterlingY
- 15th March 2007, 04:23
I was able to just put the mcHID.dll in the Visual Basic project folder where my project files are located. That solved working with VB, but I still don't have the easyHID program at my disposal. Maybe I will just have to slug it out by hand.

-Sterling

Squibcakes
- 15th March 2007, 04:59
OK, got it sussed!

The problem was in my report descriptor section..... originally, I had setup up a "joystick" descriptor, which worked, but then later I changed the descriptor to a "simulator control".

The confusing thing was that windows was happy to use this new descriptor, and I figure the HID PID/VID sections in the registery never got updated (ie windows still recognised the pedals as a joystick).

When I plugged them into another PC for the first time, windows installed the pedals as a simulator control and that is why they didn't show up into the game devices list.

After changing the report descriptor scetion back to a joystick - all is working!

I guess the moral of the story here is that if you use the same VID/PID for different USB applications your USB device may not install properly.

I found that just removing the usb device from the device manager isn't enough, as you may need to delete all keys in the registry that ref. the paticular PID/VID device.

Clear as #*$#@!! mud?

As for installing EasyHID - I haven't had any problems installing (XP Pro 32). I don't suppose you can set compatabillity to XP(32) for the setup file?

Cheers Squib

SterlingY
- 16th March 2007, 00:54
Of course I took your excellent example and tore it all apart to modify it into something completely useless to me.

I'm not getting data from USBbufferin on the device. I am kind of curious about a line in the VB side:

"hidWriteEx VendorID, ProductID, BufferOut(0) ' send it"

Doesn't that just send the first element of the array? On the device I am trying to read USBbufferin[2] but get nothing. I should point out that my version has this as a normal BYTE, not the LSB of another number or whatever you had.


-Sterling

SterlingY
- 16th March 2007, 02:45
More info:

In the VB code, if I put the following line "BufferOut(2) = 145" in the WriteSomeData() function, I get "0" when reading on the device, however, If I put that same line in the Form_Load() function, it sends the data, so I think the Form is constantly reloading. How can this be?

-Sterling

SterlingY
- 16th March 2007, 05:05
I seem to be talking to myself here, but that's okay.

I just wanted to say that I got it working. I don't know how. But, I ran the original USBDEMO.exe, and then everything started working with my modified version.

Crazy, I know!

-Sterling

SterlingY
- 16th March 2007, 05:24
Here I go again:

The problem was that VB buffer(1) comes into the device as buffer[2]

ronjodu
- 19th March 2007, 00:25
Thanks for the inspiration Steve. My upgrade is complete, PBP2.47,EasyPic 4, PicFlash 7.03, a new laptop to stuff it all in and some 18f4550 samples.
Thanks to Uncle Sam for a quick tax return also.


Had some trouble with the USB stuff at first but this post solved my problems.
http://www.picbasic.co.uk/forum/showpost.php?p=31764&postcount=32

Not sure what to do with the $20 I got left. Dinner at Denny's with my wife maybe?
Then again I could use another USB cable...

Thanks again Steve.

Momboz
- 5th April 2007, 12:17
Dear all

I am a newbie who's tying to do his first steps with UBS programming under PIC. My environment is PBP 2.47, Microcode Studio 3.0.0.0 and MPASM 5.03.

I am using microsontroller PIC 18F2450.

The issue is: when trying to compile and assemble the source file USBDemo.PBP from Steeve I get the following error messages:

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

I did make any change to the original files as posted on this forum.

Could any one be of help to me?

My file locations are as follows:
MPASM D:\Program Files\PBP\MPASM
PBP D:\Program Files\PBP

When loading the USBDemo.HEX file in my microcontroller (18F4450 and 18F2450) it works fine with the PC application from Steeve.

In advance many thanks for your help.

skimask
- 5th April 2007, 14:51
I am using microsontroller PIC 18F2450.

The issue is: when trying to compile and assemble the source file USBDemo.PBP from Steeve I get the following error messages:

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

I did make any change to the original files as posted on this forum.

Could any one be of help to me?

My file locations are as follows:
MPASM D:\Program Files\PBP\MPASM
PBP D:\Program Files\PBP

When loading the USBDemo.HEX file in my microcontroller (18F4450 and 18F2450) it works fine with the PC application from Steeve.

In advance many thanks for your help.

As far as I know, PBP doesn't support USB on the 2450/4450. Yes, those chips are USB chips. Yes, PBP does support those chips, just not using the USB, at the website doesn't specifically say it supports them that way. The only chips I see that PBP directly supports with USB are the PIC18F2455, 2550, 4455, and 4550, and the 16C745, 765.

Josuetas
- 5th April 2007, 14:57
Hi, This really is a nice post, I am going to work with it, i will have to use 18f2550 since it is the available part around here.

1. Any problem with it being the 2550? someone said "Thank god you didnīt choose the 2550" before.

2. I guess i`ve read the answer to this but...: Usb Communications require somehow a "master"(host) and a "slave"? if this is so, i would never be able to communicate two pics through USB would I?, where i am going is that i intend to control USB devices but this could never be done if this is true, has anyone figured something without buyign those ugly USB HOST controllers? they really are a pain in the a.. you canīt find them at all(not here).

I have a uC develpment to control by serial (rS232) port some GSM phones, but the newer models dont support serial but USB, what should be done to transfer data between a uc and them?

It seems to me like an step backwards the fact that usb had lost the simplicity of RS232 communications in this matter.

thanks for the hobby time again

mister_e
- 5th April 2007, 15:31
1. There's no real problem with the 2550. It was just an inside between me and Malc about a previous thread on some behaviour to program this specific PIC with his PIC programmer. not much. Don't worry.

2. You can't use a PIC to PIC USB comm unless you really want to waste your time to develop a host controller... not something i would do. Hence why there's a few available on the market.

USB is not as simple as RS232 of course, it's another and really different animal.

Good luck!

Noise.be
- 5th April 2007, 15:46
I lately bought the book of Jan Axelson and this realy helped me. Here the link of Amazon
USB Complete: Everything You Need to Develop Custom USB Peripherals (http://www.amazon.com/USB-Complete-Everything-Develop-Peripherals/dp/1931448027/ref=sr_1_3/102-5295903-5512930?ie=UTF8&s=books&qid=1175780503&sr=8-3)

Good Luck ;-)

Momboz
- 5th April 2007, 16:39
As far as I know, PBP doesn't support USB on the 2450/4450. Yes, those chips are USB chips. Yes, PBP does support those chips, just not using the USB, at the website doesn't specifically say it supports them that way. The only chips I see that PBP directly supports with USB are the PIC18F2455, 2550, 4455, and 4550, and the 16C745, 765.
Hi skimask.

First, many thanks for your help.

Second, I know from Melabs, that they support 2450/4450 in the USB modes.

My issue again is: I was not trying to use any other PIC, but 4550. I am not that far in the process. What I was trying to do is just to compile the USBDemo.PBP for the 4550 in my environment.

And this doesn't compile because of some missing macros.

Any suggestion?

Thx

mister_e
- 5th April 2007, 17:15
shouldn't be a problem IF ALL files i've provided are located in the same folder unless i miss something obvious.

Josuetas
- 5th April 2007, 17:52
Ok, so there are plenty USB host controllers, any to recommend? it would be great if it is NOT surface mountable,

Thanks

Momboz
- 5th April 2007, 18:22
shouldn't be a problem IF ALL files i've provided are located in the same folder unless i miss something obvious.
Many thanks Steeve

I have copied all the files in the folder where I have PBP 2.47 installed and I tried to compile again. The errors are the same.

I have been surprised by the way you did programm your application (the PIC configuration is written in assembler and is in your source code. Why not) and it's the only example that does recognize the USB interface when plugged in. The other examples from Melabs (UBMouse, UBSJadem and USBCDC) do not recognize when plugged in but they compile without errors.

I am not asking what is the best :-)

I will still investigate the issue and try to find out what's wrong with my configuration. I am very very patient and I have plenty of time to spend on the subject. This is just as a hobby. No boss is expecting any results from me in this case.

Thanks again for your help.

Momboz
- 6th April 2007, 09:01
shouldn't be a problem IF ALL files i've provided are located in the same folder unless i miss something obvious.

Dear Steve

I would like to give you feedback on 3 points:

1st, there is a typing error in your example USBDemo.pbp source file. Line 39 in your file should say "_FCMEM_OFF_1H" and not "_FCMEN_OFF_1H", i.e. the letter N should read M.

2nd, your example compile perfectly if it located in the USB18 folder (or if you copy the UBS18 folder files in yours).

3nd, you are redefining the PIC CONFIG register and this is also done in the so called INC file from Melabs for that PIC. This generates errors and the user has to choose where to configure these registers to avoid duplication of definition.

I take this opportunity to thank you very much for the example first and then for your kind help.

Bye

malc-c
- 6th April 2007, 10:26
1. Any problem with it being the 2550? someone said "Thank god you didnīt choose the 2550" before.



Don't be put off by my comments. As Steve mentioned it was a "toung in cheek" jibe as poor old Steve and I spent days trying to get an 18F2550 programmed with some bit of code using my cheap JDM programmer and some freeware loaders !

mister_e
- 6th April 2007, 16:08
1st, there is a typing error in your example USBDemo.pbp source file. Line 39 in your file should say "_FCMEM_OFF_1H" and not "_FCMEN_OFF_1H", i.e. the letter N should read M.
Yes and no, it have been discussed before, it's down to your MPASM version. The latest version use FCMEN, while older use FCMEM
http://www.picbasic.co.uk/forum/showthread.php?t=3251&page=30 Post 149 and +


3nd, you are redefining the PIC CONFIG register and this is also done in the so called INC file from Melabs for that PIC. This generates errors and the user has to choose where to configure these registers to avoid duplication of definition.
Yes, you are right, but it's usual to comment the default one. At least, i always do it. see bellow..
http://www.picbasic.co.uk/forum/showthread.php?t=543 Post 5 and +++

mpardinho
- 10th April 2007, 19:13
Mister E,
the code work,
but AN0 and AN1 not stable
leds not stable off....same time is on or off....+- 5 seconds...push-buttons is off
than push-button = on, led stable ......on...off

i use 18F4550
470 nf in Vusb / Vss
.1 uf ceramic in Vcc/Vss
4k7 in MCLR / Vcc
resonator 4mhz


* pardom for my english

skimask
- 10th April 2007, 19:35
Mister E,
the code work,
but AN0 and AN1 not stable
leds not stable off....same time is on or off....+- 5 seconds...push-buttons is off
than push-button = on, led stable ......on...off

i use 18F4550
470 nf in Vusb / Vss
.1 uf ceramic in Vcc/Vss
4k7 in MCLR / Vcc
resonator 4mhz


* pardom for my english

You unstable just like the other post in the Communications->USB section?

mpardinho
- 10th April 2007, 19:45
yes, but i make the mr.e code and circuit to test
....and ...not stable too...i think my 5v from pc is not good

pardon for the same question.

skimask
- 4th May 2007, 18:02
Yep got mine working today too!!! Woo Hoo!!
See photo attached.

I just ordered and received the wrong USB connector...AGAIN!!! (insert Mr_E's headbanging against desk picture here)...

Could ya take a look at www.digikey.com and match up a part number if you get a chance?

Noise.be
- 5th May 2007, 09:40
i use 18F4550
470 nf in Vusb / Vss
.1 uf ceramic in Vcc/Vss
4k7 in MCLR / Vcc
resonator 4mhz
I've used
220nF Vusb / Vss
.1 uF ceramic too
10k MCLR/Vcc
USB B type Connector http://www.allproducts.com/communication/kinsun/14usb-b.jpg
and it works fine now ;-)

mister_e
- 11th May 2007, 04:14
Out of curiosity... Anyone tried USBDemo with Windows Vista? Working?

Squibcakes
- 11th May 2007, 08:19
No, but I'll give it a go this weekend ;) I can feel a backup coming on....

BTW,

I need a decent way to debounce a number of switch's connected to my pic.
I'm using a dirty PAUSE 50 to do just that, but finding unless I put USBSERVICE everywhere (ie after checking the status of each switch), the switch's arent being sent to the pc (via usb).

I borrowed the ASM timer interrupts from the usbdemo code, but that doesnt help either. I'm thinking that TMR interrupts aren't independent of PAUSE statements. Is this true?

I don't want to use the BUTTON command.

cheers
Squib

mister_e
- 11th May 2007, 16:27
If you're using ON INTERRUPT... yes PAUSE will screw up things. Using Darrel's interrupt + it's USBDemo code modification ( AKA POST 148), should solve it.
http://www.picbasic.co.uk/forum/showpost.php?p=30682&postcount=148

Depending how you implemented the interrupt debounce/read plah plah, it may work as well with ON INTERRUPT..

Squibcakes
- 12th May 2007, 05:13
Ok Great I'll have to try it. Good to know there could be a work around.

BTW I tried running usbdemo on Vista, but I need the mchid.dll, which I have on floppy disk but can't get it on to the laptop running vista. :(

Don't supose you can upload it on to the website so I can download it straight onto my laptop eh?

Cheers
squib

mister_e
- 12th May 2007, 10:58
That DLL came with Mecanique EasyHID. I'm not sure if David allow to link the DLL even if the software is 100% free.

Squibcakes
- 14th May 2007, 02:50
If you're using ON INTERRUPT... yes PAUSE will screw up things. Using Darrel's interrupt + it's USBDemo code modification ( AKA POST 148), should solve it.
http://www.picbasic.co.uk/forum/showpost.php?p=30682&postcount=148

Depending how you implemented the interrupt debounce/read plah plah, it may work as well with ON INTERRUPT..

Hi Steve,

Thanks for the tip, it works a treat!

I rekkon melabs should incorporate DTs instant interrupts into their next version of pbp and do away with ON INTERRUPT altogether......

Cheers buddy.

Squib

skimask
- 14th May 2007, 05:29
I rekkon melabs should incorporate DTs instant interrupts into their next version of pbp and do away with ON INTERRUPT altogether......

Of course that would assume they do anything at all.......
Come On MELABS...you're falling behind!!!

Firegod
- 14th May 2007, 11:02
What would the __CONFIG lines look like using the ECIO mode with a 48MHz half size oscillator on pin 9?

mister_e
- 14th May 2007, 13:47
i would guess...


asm
__CONFIG _CONFIG1L, _PLLDIV_12_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; Divide by 12 (48 MHz oscillator input)


__CONFIG _CONFIG1H, _FOSC_ECPLLIO_EC_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; External clock, PLL enabled, port function on RA6, EC used by USB

;
; other __Config
;
endasm


Look table 2-3 in the data sheet. there's few other setting available. Not sure the divide by 12 is the best option when you can feed it directly.

Firegod
- 15th May 2007, 06:23
Thanks for the quick reply

Firegod
- 16th May 2007, 09:15
Dear all

I am a newbie who's tying to do his first steps with UBS programming under PIC. My environment is PBP 2.47, Microcode Studio 3.0.0.0 and MPASM 5.03.

I am using microsontroller PIC 18F2450.

The issue is: when trying to compile and assemble the source file USBDemo.PBP from Steeve I get the following error messages:

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

I did make any change to the original files as posted on this forum.

Could any one be of help to me?

My file locations are as follows:
MPASM D:\Program Files\PBP\MPASM
PBP D:\Program Files\PBP

When loading the USBDemo.HEX file in my microcontroller (18F4450 and 18F2450) it works fine with the PC application from Steeve.

In advance many thanks for your help.


I have the same problem as above but I am using a 18F2550. What am I missing or where did I go wrong?

I am configured for a 18F2550 but the USBDEMO.MAC file is overwritten without the needed macros each time I try to compile.

mister_e
- 16th May 2007, 12:23
O.K. the original code was for a 4550. You need to rebuild the project in EasyHid for a 2550. There's a load of needed files.

I've uploaded the 2455 and 2550 stuff here. let me know what happen now. The 2550 have been tested... but i don't have any handy 2455.

I've also uploaded the schematic, if some need it.

NOTE: If your going to use LONG variables, you MUST copy the PIC18Xxxxx.BAL file in your source directory as well, unless you'll receive some compilation errors.

The .BAL file is located in \PBP\USB18 directory.

mister_e
- 17th May 2007, 02:02
OK i received those 2455 today, the files i sent work as suppose to.

f_lez
- 27th June 2007, 14:35
I downloaded the 2550 zip, then the 4550 zip.

compiled the 2550 example, blew it, plugged it in, nothing, then remembered the crystal speed (I'm on a 16) so went into programmer software and changed div from none to 4, nothing.

changed all fuse setting in programmer software to what I usually have, worked first time!

Ran the VB demo, picked it up and worked a treat!

I was going to update one of my toys with the fake comport CDC but this, well, so much better!

Thanks a million for showing me it can be done without expensive development kit, this thread should be tagged as a sticky at the top of the forum!

(yes I had it working in about 20 minutes, this from me that usually has all kinds of problems!) (And I dont even have a proper dev board, just a homebrew with leds etc)

mister_e
- 28th June 2007, 01:16
http://www.mister-e.org/Pics/woohoo

Welcome in the USB world :)

Glad to hear you like it.

Enjoy!

f_lez
- 28th June 2007, 13:03
Like it I love it!


just about to start a little project with it now, or at least block one out, so I have a quick question.....

If I was to use hserin to receive a string of long slow bytes, say 160chars at 1200, would it cause a problem with the USB not being serviced while hserin recieved the bytes, especially if say the incoming data was short, say only 10 chars sent, hserin would have a timeout but if it sat there for 2 seconds, would it drop the USB?

mister_e
- 29th June 2007, 01:24
yes or not, i would recommend to use the POST 148 version with Darrel Taylor instant interrupt instead of ON INTERRUPT.

See that link...
http://www.picbasic.co.uk/forum/showpost.php?p=30682&postcount=148

precision
- 13th July 2007, 11:34
Can i use this demo with DasyLab Or Labview ? I using both software from long time for DAQ.
Thanks

.

Johan
- 13th July 2007, 14:14
I am looking for this trough hole plcc socket, could anyone help which type , or digikey/mouser part number

Thanks



http://www.mikroe.com/en/tools/plcc/images/plcc_onboard_200.jpg

Darrel Taylor
- 13th July 2007, 14:36
http://www.mikroe.com/en/tools/plcc/

Johan
- 13th July 2007, 14:41
Thanks Darrel, but I need the PLCC socket only, not the whole adapter, what make/ type is it ?

It is smaller than normal PLCC44 socket

Johan

mister_e
- 14th July 2007, 00:39
Can i use this demo with DasyLab Or Labview ? I using both software from long time for DAQ.
Thanks

.
Sorry, i don't use them :(

Johan, it's really a trough hole PLCC44 socket
Digikey:
A-CCS44-Z-R
http://rocky.digikey.com/WebLib/Assmann/Web%20Photos/A-CCS44-Z-R.jpg

OR
940-44-044-24-000000

OR
8444-11B1-RK-TP
http://rocky.digikey.com/WebLib/3M/Web%20Photos/8444-11B1-RK-TP.jpg

Johan
- 14th July 2007, 15:50
Steve

Yes, it is indeed just a plain PLCC socket,

I was mistaking it as something else , I thought it was a " mini" plcc44,that fits inside DIP 40 socket, but after I look more closer, it is bigger than the DIP

I never use PLCC44 socket before, will it fit to QFN 8x8 type PIC 18F4431 ?

mister_e
- 14th July 2007, 16:07
Nope, it's really 2 different animal. Even if possible, good luck with home made soldering for QFN packages :D

the easiest home made soldering would be DIP or TQFP packages.

But yes you can buy some QFN adapter.. make sure you're wallet is ready for that ;) talking about those no solder type... kind of ZIFF for QFN... see those

http://www.ironwoodelectronics.com/catalog/Content/Drawings/PA-MLF044A-P-Z-01Dwg.pdf
http://qfp-adapter.com/Site/QFN-MLF-ZIF-socket-TOPs.htm#

naga
- 22nd August 2007, 09:49
hi,

getting these errors: PBP 2.47, Microcode Studio 3.0.0.0 and MPASM 7.31

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file


Thank you,

Regards..

naga
- 22nd August 2007, 13:05
Dear all

I am a newbie who's tying to do his first steps with UBS programming under PIC. My environment is PBP 2.47, Microcode Studio 3.0.0.0 and MPASM 5.03.

I am using microsontroller PIC 18F2450.

The issue is: when trying to compile and assemble the source file USBDemo.PBP from Steeve I get the following error messages:

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

I did make any change to the original files as posted on this forum.

Could any one be of help to me?

My file locations are as follows:
MPASM D:\Program Files\PBP\MPASM
PBP D:\Program Files\PBP

When loading the USBDemo.HEX file in my microcontroller (18F4450 and 18F2450) it works fine with the PC application from Steeve.

In advance many thanks for your help.


Hi.
Momboz..

Iam getting exactly same errors dear,

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

How did you solve this problem?

Plz Help me...

Regards...

Darrel Taylor
- 22nd August 2007, 17:36
Which PIC are you using?

You probably need a modified .bas file for that chip.

If you are using a 2455, 2550 or 4550 then Steve has already provided the files. (see post 99)

You may also need to modify the PBPUSB18.LIB file if your PBP installation is not in the default c:\PBP folder. As was the case with Momboz.
<br>

naga
- 23rd August 2007, 09:06
Which PIC are you using?

You probably need a modified .bas file for that chip.

If you are using a 2455, 2550 or 4550 then Steve has already provided the files. (see post 99)

You may also need to modify the PBPUSB18.LIB file if your PBP installation is not in the default c:\PBP folder. As was the case with Momboz.
<br>
Hi,

Thanks for your reply.
Errors for both 2550 and 4550;(using steve's files)
there are 2 folders in c:\PBP, one is MCSP-3.0 2ND one is PBP247,
Now different errors when iam trying to compile Steve's file from C:\PBP.
No errors from the sample folder files(pbp247)i tried with its own compiller and mpasm..

Regards,

plaese find attached image..

Darrel Taylor
- 23rd August 2007, 19:55
There may be several things going on here. Let's see if we can fix a couple of them.

First, since PBP wasn't installed in the default folder, you have to change the path to one of the files.
In your c:\mcsp\pbp247\ folder, there is a PBPUSB18.LIB file.
Open it with notepad, and change the first include line to...

&nbsp; include "c:\mcsp\pbp247\PBPPIC18.LIB"
----------

Next, edit the c:\mcsp\pbp247\18F2550.INC file with notepad.
Comment out ALL of the __CONFIG lines with a semicolan ;
----------

Then in the USBdemo program, change _FCMEN_OFF_1H to _FCMEM_OFF_1H

That will need to be changed again after the next time you upgrade MPASM.
----------

Those should fix several of the errors.
Compile it like that and let me know whats left.
<br>

Darrel Taylor
- 23rd August 2007, 20:09
Oh, and 1 more.

In Microcode studio, goto

View | Compile and Program options | Compiler tab

And select the INHX8M radio button.
<br>

naga
- 24th August 2007, 17:07
Oh, and 1 more.

In Microcode studio, goto

View | Compile and Program options | Compiler tab

And select the INHX8M radio button.
<br>
Dear Darrel Taylor,

Thank you very much..compilled succesfully but few warnings..
commented like this :
ALL ; __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
ALL ; __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
ALL ; __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
ALL ; __CONFIG _CONFIG3H, _PBADEN_OFF_3H
ALL ; __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L

i selected only INHX8M radio button in View | Compile and Program options | Compiler tab
and disabled rest..

I'll let you know its behavior after programming the IC tonight ..

Thanks again..

Warm Regards...

Darrel Taylor
- 24th August 2007, 22:19
Ha Ha Ha :D
That's funny.

Very close,
but no cigar.

should be...


&nbsp; ; __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
&nbsp; ; __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
&nbsp; ; __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
&nbsp; ; __CONFIG _CONFIG3H, _PBADEN_OFF_3H
&nbsp; ; __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L

naga
- 25th August 2007, 09:02
Ha Ha Ha :D
That's funny.

Very close,
but no cigar.

should be...


&nbsp; ; __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
&nbsp; ; __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
&nbsp; ; __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
&nbsp; ; __CONFIG _CONFIG3H, _PBADEN_OFF_3H
&nbsp; ; __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L


Opearation Success...:D :D

Thank you again, and i look forward to your continued support.

Darrel Taylor
- 25th August 2007, 09:45
http://www.mister-e.org/Pics/woohoo

Hey, It's mister_e's thread.
I gotta use the dancing WooHoo. :D

EDIT: And if it weren't for the 40 posts per page, you'd know why we were dancing ... :o
Pevious post (http://www.picbasic.co.uk/forum/showthread.php?p=42952)
<br>

naga
- 25th August 2007, 21:01
Hi,

Im in trouble again..not detecting my usb device..18F4550(compiled successfully).

Iam using 20 mhz 22pf so i modified steve's code like this:
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L

__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H (updated my mplab to 7.60)

tried :
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC3_PLL4_1L & _USBDIV_2_1L
post # 44(no luck).
and your "http://www.darreltaylor.com/files/USBDemo2_DT.txt" also but
INCLUDE "DT_INTS-18.bas" not found error..

waiting for your reply..

Thank you...

Darrel Taylor
- 25th August 2007, 21:25
For a 20Mhz crystal ...

__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H


>> and your "http://www.darreltaylor.com/files/USBDemo2_DT.txt" also but
>> INCLUDE "DT_INTS-18.bas" not found error..

You can download the files from here ...
http://darreltaylor.com/DT_INTS-18/home.html
<br>

naga
- 25th August 2007, 22:11
[QUOTE=Darrel Taylor;42974]For a 20Mhz crystal ...

__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H


Dear Darrel,
just tried above code and demo2_dt.txt but no luck..showing "USB DEVICE NOT RECOGNISED"

i'll send you the schematic 2morrow..plz go through it..
using PICKIT2 V2.10 PROGRAMMER (NEED TO CHANGE ANY SETTINGS?)

REGARDS..

naga
- 27th August 2007, 06:44
Dear Darrel,

Iam happy that succeed in 18f2550 4mhz- 22pf..
Iam still struggling for 18f4550 tried 4mhz-22pf with steves original hex (no luck)... can i have Steve's 4550 code's Schematic.i think its different from my development board..

Thanks & Regards,

Darrel Taylor
- 27th August 2007, 23:01
I think Steve's original circuit was the same as the schematic at the bottom of the EasyHID page.

http://www.mecanique.co.uk/products/usb/easyhid.html

At least I don't remember him posting a different one.
<br>

naga
- 29th August 2007, 08:01
Hi,
schematic helped...now its working ..

Thanks to Mister_E for making such a fantastic code..and
Thanks to Darrel Taylor for great support..

Best Regards..
Naga

naga
- 3rd September 2007, 12:19
@Darrel,
Hi,
circuit becomes very slow when i enable all PORTA<5:2> inputs; i mean it responds after some delay, only when i switch on all push buttons..
slowing down including AN<1:0> ADC results in the progress bars..otherwise perfect :-)

Thanks&Regards.

leisryan
- 14th October 2007, 01:48
Sir:

I'm also new to USB i was thinking if USB can't handle peer to peer does it mean we can't use newer PICS to interface to one another using USB? I 've learned that USB PICS are only capable of PERIPEHRAL mode but not HOST without any external aid like FTDI? is it possible to daisy-chain 2 or more PICS using onboard USB? I'm starting a project base on easyHID but i need some sort of external controler like hand held control with LCD's, Keypads,-etc. Are other onboard peripherals in the PIC like USART the only way to do it?,with USB already dedicated to PC interface?
Hoping for anyone's enlightenment!!!

Yours Trully,
Ryan

RodSTAR
- 14th October 2007, 05:18
mister_ed, you are my idol

Squibcakes
- 17th October 2007, 08:17
Hi Steve,

I'm revisting USB again and using parts of the demo as a bit of a refresher ;)

Im writing a program where I want to send half a dozen NMEA strings (of varrying string length) which are stored in their own array, to the pc running hyperterminal.

I can send them successfully via USB using 6 separate DoUSBOut subroutines (without the SendUSB macro array code) but I want to trim my code down and use one (1) DoUSBOut routine to do the lot.

->>> I kinda have it working but the received data into hyperterminal appear as though some strings aren't received or are being over written or something.

I've modified the SendUSB macro array so that the USBBufferOut should just keep filling up according to my USBBufferCount (array size) and suspect this is the problem but I'm rusty on ASM. Perhaps the USBBufferOut needs to be "erased" after each visit to DoUSBOut? How would I do that?

I'm going blind looking at this code and wonder if you could see any traps I may have fallen into...




USBBufferCount Var Byte '
USBBufferOut Var Byte[50] ' store outgoing USB data ...... this value originally [8]

GPZDA VAR BYTE[28]
GPGLL VAR BYTE[41]
GPGGA VAR BYTE[49]
GPVTG VAR BYTE[27]

'...... arrays get filled up here.........
'...... other code........

asm
SendUSB macro array
; Use to Copy an specific array to USBBufferOut AND send it
; to USB bus
variable i=0

;while i<8 ' ...............original line here........

while i<_USBBufferCount
MOVE?BB (array+i),(_USBBufferOut+i)
i+=1
endw

L?CALL _DoUSBOut
endm
endasm


USBBufferCount = 28
@ SendUSB _GPZDA

USBBufferCount = 41
@ SendUSB _GPGLL

USBBufferCount = 49
@ SendUSB _GPGGA

USBBufferCount = 27
@ SendUSB _GPVTG


DoUSBOut:
'
' Send data to the USB bus & Wait for USB interface to attach
' ================================================== =========
T1CON.0 = 0 ' TURN OFF TIMER

WaitPC: '
USBService ' keep connection alive
USBOut 3, USBBufferOut, USBBufferCount, Waitpc ' if bus available, transmit data

T1CON.0 = 1 ' Re-Enable TMR0 interrupt
return

Josuetas
- 24th October 2007, 16:37
Hi.. i canīt find EasyHid at mecanique webpage, is it gone? how do you get it now? did it became part of some package?

Thanks

RodSTAR
- 25th October 2007, 01:06
Hi.. i canīt find EasyHid at mecanique webpage, is it gone? how do you get it now? did it became part of some package?

Thanks

Open MicrocodeStudio 3.0.0.5, in View menu, choose EasyHID USB Wizard

Josuetas
- 25th October 2007, 15:08
Is it possible to use microchipīs bootloader since the driver is different than the one from easyHID?

Havenīt tried but, is it possible to use MCS bootloader (Serial)? i have a version of 4 MHZ for 18f4550 that comes with MCS but i am not sure if this pic program made by Mister_e is runing 4Mhz or more with some PLL (i am newbie with this concept).

Thanks AGAIN.

Josuetas
- 28th October 2007, 17:37
Hello, i have done great things with this demo from Mister_E Thanks always. Its a great playground ;)

Now i made some changes and created my own device, its working already BUT how do i manage two of the same devices with my software? Where are we choosing one from another? if they both have the same ID, etc?

Thanks for your replies,

DJC

bj49
- 5th November 2007, 23:52
Thanks to Mister_E's USB demo and DT's ints18 and this forum I have my USB board PICF4550@ 48 Mhz running a single DS1820 displaying on VB6 and it took less than 1/2 a day and its stable and fast!

This is my first post and I would like to congratulate this forum for the information that is available and the generosity of people like mister_e and darren taylor and others for sharing their experience;it is invaluable for me
This demo should be pinned!

selimkara
- 7th November 2007, 16:21
First of all, I would like to thank everybody here.,especially, Mister_E, Darrel Taylor and Squibcakes. I have downloaded the usbdemo and it works great.
I have programmed the pic while including the line INCLUDE "CDCDESC.ASM" in USBDESC.asm.
But I could not use this with VB6 with MSCOMM1. Namely, I want to use as CDC the given VB6 code. Please could you help me?
Thanks,
Selim

mister_e
- 7th November 2007, 17:12
@selimkara
is there any specific reason why you really want to use CDC ?

@Josuetas
There's probably few way to do what you want, using something like a header. Such HSERIN WAIT(YourHeader) so when you receive/send data, you may want to check/set few or only one Byte. Then the Slave/Master do what he has to do if the header match.

selimkara
- 7th November 2007, 18:24
Thanks for your rapid response and interest. We are working in Physics dept. at Trakya University. Our aim is to control some experimental structures (for example temperature, light intensity...). To do so, we need a less complex and short VB6 procedure. I think using virtual comm port is very useful to do this. Am I wrong? We had succeeded similar connection, using CDC via MSCOMM in VB6 with a short code. But in pic side, we could not set interrupts. Your code(pic) is very useful and simple. So we want to use your pic code and change your VB code to adapt MSCOMM (virtual comport). You may ask why we don't use serial comm.because there's no comm port on new laptops, so we must learn to use USB.
If I'm not misunderstand, in the following conversation (#36) between you and Squibcakes, Squib reported that he succeeded this. I would like to know how? I think some changes must be made at pic code. If you or squib have tips about this or have complete codes, I'd be grateful. Thanks for your previous suggestions. We'll also utilize them.

sincerely
Selim

#36---------------------------------------------------
Mr_E
Yeah ok well thanks for your input anyway - always welcome I'm happy to edit the the .inc file and leave it at that.

Great news! I finally got the CDC virtual comport working!!!!!!

Now I can send data via USB (virtual comport) and out of the Pic 18F4550 USART! and vice versa!
-------------------------------------------------------
I'm stoked that this actually works!

Squib

Squibcakes
- 7th November 2007, 23:11
T
If I'm not misunderstand, in the following conversation (#36) between you and Squibcakes, Squib reported that he succeeded this. I would like to know how? I think some changes must be made at pic code. If you or squib have tips about this or have complete codes, I'd be grateful. Thanks for your previous suggestions. We'll also utilize them.



The post was regarding setting the config fuses by way of changing the 18f4550.inc file.
I never actually used CDC with the USB demo, totally separate and apart :)

As Steve said, you don't need to use CDC to send you data back to the PC. This code uses HID interface and the VB program displays the data coming from the PIC.

As far as VB is concerned I have no clue - One day I should learn it!

Squib

Darrel Taylor
- 7th November 2007, 23:50
Selim,

Maybe I missed something in the conversation,
But this might be what you're looking for ...

USB CDC Communications for Dummies! (Squibcakes)
http://www.picbasic.co.uk/forum/showthread.php?t=5806
<br>

selimkara
- 10th November 2007, 12:07
Ok. Thanks everybody. I think that was a stupid idea. I'll use and develop UsbDemo. Thanks Steve, Darrell and Squib.

Bye

Josuetas
- 20th November 2007, 15:54
Hi.

To Mister_E or anyone that really understand this (i clearly donīt). I made this post already but none seemed to understand it, so i am posting again in other words.

I made this software that controls an USB device, it all began with Mister_E`s demo, it is working really fine now, no problems with it. NOW i want to use two devices, same software!. Lets say this is a temperature sensor, now i want to measure two diferent points so i wanīt to connect two diferent sensors. HOW can i differentiate both devices? when i connect the second one the first connected gets useless (I am sure the handler is replaced).

Iīve been reading the whole code for Visual Basic and PBP, i donīt intend to change my device ID and Product ID.. this would be useless. Does the Driver easyHID only works with one device?

Please give me a little advice on this matter.. How can i use two different handlers?

Thanks

DJC

mister_e
- 20th November 2007, 15:57
2 different ways
1) assign, then read the device serial number -> this has to work
2) use a specific data byte in DataToSend as identifier -> not 100% sure of it

Josuetas
- 21st November 2007, 04:49
Hi.. thanks for your reply Mister_E.

I have this problem with both solutions!... i dont have two working devices when i connect them... i just have one! When i connect the second one the first connected doesnīt work!
My guess is that this happens because the handler of the first connected device is lost and replaced for the second one.. hence my sent data (from pc to device) is just received in one of the ports (this is for sure!) so it wouldnīt work to use the serial number because i canīt even get it :s.

The same reason for the second choice.

I also think that both devices could have exactly the same software, my guess is that this is a matter of software (in VB), there should be a way to create two different connections (what i call handlers) but i donīt get where this is done in the code Sub ConnectHID().

Again maybe i am thinking this wrong but this is what you would do with two diferent serial devices in different serial ports, you would have two different interrupt routines in the VB software to control each one.

I really hope someone could guide me here, has none connected two devices?

Thanks again for your time and concern,

DJC

mister_e
- 21st November 2007, 04:58
i already done that... i just need to find out where... i had to do some unwanted Hard-Disk clean-up recently... i hope i still have it somewhere, unless i may try to redo it once again.

Josuetas
- 30th November 2007, 16:53
Hi!

I was hoping somenone could give any ideas on my subject, its been more than a week and no post here, You donīt have to know the solutions... lets just talk about your oppinions or ideas :D

Thanks for any help

mister_e
- 30th November 2007, 23:49
i already gave mine, maybe yu could check on wich hub/port a specific device is connected... i just don't have any spare time... but i could deal with few K-CAN$ :D

Darrel Taylor
- 1st December 2007, 00:34
I can't speak for Visual Basic, but in Delphi, you request a list of HID devices, and each one has it's own "Handle".

If two devices have the same Vendor/Product ID's then you look for the serial number to tell the difference. But access to the device is by specifying the Handle.

Here's a small program that can identify the serial number and handle. Note: the handle changes on every connection or power-up/re-boot.

www.pbpgroup.com/files/HIDmonitor.exe
Put it anywhere, there is no installation to do.
<br>

mister_e
- 1st December 2007, 00:46
same rules apply with any language, look at the mcHID API reference. But seems NOBODY want to use the serial number... no matter why they suffer :D

Nice utility Darrel!

Darrel Taylor
- 1st December 2007, 01:30
... But seems NOBODY want to use the serial number...

Well, if there was an easy way to do it, it might look more attractive.
Running EasyHID or manually editing the descriptor file each time doesn't seem like an option.

Maybe there's a way to have the descriptor file read the Hardware Serial number, then have the programmer auto-increment the serial number, ... but it doesn't currently have that feature.

Other than that, since you can find the handle of each device with the same Vendor/Product ID, within your software you can create a Challenge/Response type arrangement that will let the computer assign a unique number to any new devices on the BUS.


Nice utility Darrel!
Thanks Steve,

It's come in handy a few times troubleshooting USB connections.
Thought I'd spruce it up and pass it on.
<br>

mister_e
- 1st December 2007, 01:49
On another forum someone already Suggest USBDeview. I use it a lot, it's a real nice utility ...
http://www.nirsoft.net/utils/usb_devices_view.html

They also have bunch of other nice freebies over there...

Darrel Taylor
- 1st December 2007, 01:53
All good info.

But thanks for trumping my puny efforts. :o
<br>

mister_e
- 1st December 2007, 01:57
http://www.mister-e.org/Pics/ROFL well... when you did that utility... wasn't it to learn something ?

And i'm sorry... i thought i posted that link before.. oops!

It's still a nice utility you've made so far!

Darrel Taylor
- 1st December 2007, 02:08
Excellent point! That's exactly what it was.

That program started from my attempt at modifying the USBDemo program from VB to Delphi.

It's based on the Delphi routines supplied by David Barker in the EasyHID results.

It's only right that I posted it here,... along with the reason I even know about USB. (USBDemo)

:D
<br>

mister_e
- 1st December 2007, 02:16
if i find time, i may elaborate USBDemo a little bit more, but you know how busy i am right now with some current project + that ASM one :eek:

For some spare time... my new toys... Delphi, EasyDsPIC 4, PoScope and PIC32s

Josuetas
- 1st December 2007, 13:18
Other than that, since you can find the handle of each device with the same Vendor/Product ID, within your software you can create a Challenge/Response type arrangement that will let the computer assign a unique number to any new devices on the BUS.


Ok i will use Darrelīs exe program.

I know it will not be exactly the same for VB but if there is any chance that you could post the source code i would finally see how itīs done!

I am sure i can do with just the handler, i could also identify wich device was connected first and have a record of devices....

This would be a great place to begin

Thanks for your replies

DJC

Darrel Taylor
- 1st December 2007, 22:29
Ok i will use Darrelīs exe program.
Thank You!<hr>
Looking at the VB side of USBDemo

Public Sub OnPlugged(ByVal pHandle As Long)
'
' A HID device has been plugged in,
' check if it's the right one, and enable the form LED (top left)
'
Dim DeviceHandle As Long
Dim VendorName As String * 15
Dim ProductName As String * 15

If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' Good one?
'
' get the device handle
' =====================
DeviceHandle = hidGetHandle(VendorID, ProductID)
'
' Get the vendor and product name from the handle
' ===============================================
hidGetVendorName DeviceHandle, VendorName, 255
hidGetProductName DeviceHandle, ProductName, 255
'
' Enable the LED and display device information
' VendorName and ProductName
' =============================================
imgON.Visible = True
lVendorName.Caption = VendorName
lProductName.Caption = ProductName
End If
End Sub
Using the line shown in red, anytime a device is plugged in with the same Vendor/Product ID, it will forget about the last device and start using the new one.

To get around that, you need to check further to make sure it's the device you want to talk to. And, for that, you need to search through the HID Device list.

Again, I don't do VB, so the syntax is most probably wrong. But ...<hr>
The function hidGetItemCount returns the number of HID devices in the List.
Then hidGetItem(Index) returns the handle of the item in the list that's specified by Index (0 to count-1).

You can get the info about that device by requesting each field.
Vendor = hidGetVendorID(handle)
Product = hidGetProductID(handle)
Serial = hidGetSerialNumber(handle)

Now if everything matches, you know you have the right one. If not, keep searching through the list.

If you're not using the Serial Number, you'll need to send/receive something to the device to figure out if it's the correct one.

Is that any help?
I'll keep trying if not.
<br>

atwoz
- 18th December 2007, 03:28
Steve, do I need the 18f4550 or any other USB pic for your USB project? or can I do it with a standard pic, like the 18f452?

mister_e
- 18th December 2007, 04:19
Atwoz, only USB PIC will work!

atwoz
- 18th December 2007, 04:22
Ok Thanks Steve! Looks like I will have to buy some 18f4550 :).

mister_e
- 18th December 2007, 04:30
Well, one in the list... 18F4550, 2550,2455, 4455 they all works.

As you'll see, it's fun to have it's first working USB project....even if you're aware of post #7 and #8 :eek:

kiwipiper
- 21st January 2008, 02:16
Hopefully this Topic is still alive as I am really keen to do some experimenting with USB.

I have looked at all the posts and haven't found any refering to my problem.

I am using the 18F4550 pic, Picbasic Pro 2.50 and MicroCode Studio Plus 3.0.0.5

When I compile it stops on Line 81

Line 81: UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't :o(
Line 82: ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

With the following Error Message:

ERROR Line 81: Redefinition of VAR. (USBDemo.pbp)

I notice that when I paste the code from mister-e's zip file into MicroCode Studio it changes the case of line 82:

Line 81: UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't :o(
Line 82: UCFG = %00010100 ' enable internal USB pull-up, Full speed USB

the ucfg is now in Capitals, I don't know if this has anything to do with it?

Darrel Taylor
- 21st January 2008, 02:51
Previous versions of PBP didn't have the UCFG register defined in the include files. And usbdemo was written at that time.

PBP 2.50 does have the UCFG register, so defining it in the main program causes a "re-definition" error.

Just comment out the UCFG var byte EXT line and the error should go away.

hth,

kiwipiper
- 24th January 2008, 23:06
I am using the 18F4550 pic, Picbasic Pro 2.50 and MicroCode Studio Plus 3.0.0.5

When I compile it gives the following errors.

Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 87 : Overwriting previous address contents (0000)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 87 : Overwriting previous address contents (0001)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 93 : Overwriting previous address contents (0000)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 93 : Overwriting previous address contents (0001)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 98 : Overwriting previous address contents (0002)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 98 : Overwriting previous address contents (0003)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 99 : Overwriting previous address contents (0004)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 99 : Overwriting previous address contents (0005)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 100 : Overwriting previous address contents (0006)
Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 100 : Overwriting previous address contents (0007)

Are these errors anything to be concerned with?

Also out of interest, I am using a 4Mhz Resonator but in the code it is: DEFINE OSC 48

What is that about?

However, I seem to be making progress because when I plug it into the USB of the computer. I get the message found new hardware "USB Demo" but then it gives a message There were problems ........ etc etc.

The VB Application is not picking it up yet.

Darrel Taylor
- 24th January 2008, 23:48
When I compile it gives the following errors.

Error[118] c:\progr~1\mecani~1\mcs\usbdemo.asm 87 : Overwriting previous address contents (0000)
...

What to do if i get "overwriting previous address content" error message?
http://www.picbasic.co.uk/forum/showthread.php?p=6775


Also out of interest, I am using a 4Mhz Resonator but in the code it is: DEFINE OSC 48

What is that about?
The 18F/USB PIC's have an amazing oscillator/PLL structure.

With the proper CONFIG settings, You can use any crystal that's a multiple of 4mhz (4,8,12,16,20) and still have a system clock of 48mhz.

If the timing doesn't work well with your program, you can also have 48mhz going to the USB module, and 4/8/12/16/20/24/32 mhz going to the system clock.

It all depends on the CONFIG's.
<br>

kiwipiper
- 25th January 2008, 02:04
I commented out the four offending lines in the 18F4550.INC file and now don't get any errors. However, still get a error message from windows when I attach the PIC

Messages are: Found New Hardware. USB Device
USB Human Interface Device
A problem occurred during hardware installation. Your new hardware might not work properly.

I have tried USBDemo.exe and HIDmonitor.exe neither of these seems to see the PIC.

Any suggestions as to what I should try to do now to find the fault. At this stage I have not connected the push buttons or the trim pot to the breadboard but this shouldn't affect the pic being recognised as a USB device.

P.S. I have the USB connected to 18F4550 in the following way. D- to pin 23, D+ to pin 24 and the -ve usb connection and the USB case connected to vss. I have not connected the +ve usb connection to anything.

kiwipiper
- 25th January 2008, 02:37
Forget my last I have figured it out ....... a very happy man here.

I had left out the .47uF cap on Vusb. Connected this and all is working.

Will now have a serious play with it, which I sure will create a bunch more questions.

Thanks for all your help Darrel.

kiwipiper
- 28th January 2008, 21:57
This One for Darrel Taylor. My question is how did you get on modifying the USBDemo program from VB to Delphi. I am much more comfortable working in Delphi than VB and would be really interested in any examples of Delphi Code for this project. I found a good component at http://www.soft-gems.net/index.php?option=com_content&task=view&id=14&Itemid=33 and have had some success in using it to connect to my PIC but my limited programming ability slows me down a fair bit, although I am learning a lot. If I had a working example in Delphi I am sure it would help me understand what is going on much better.

A second question is how do you put a serial number into the program. I have been playing around with the DESCUSBDemo.asm
file and tried to put a serial number into the code. Here is what I did:

; serial number
String3
retlw (String4-String3)/2
retlw DSC_STR

retlw '4'
retlw 0x00
retlw '3'
retlw 0x00
retlw '2'
retlw 0x00
retlw '0'
retlw 0x00
retlw '8'
retlw 0x00
retlw '8'
retlw 0x00
retlw '8'
retlw 0x00

Not working. Any suggestions.

Darrel Taylor
- 28th January 2008, 22:53
Both questions can be answered with EasyHID.

The serial number is entered on one of the setup screens.

And EasyHID will make a "Starting" program for either VB or Delphi.
<br>

kiwipiper
- 29th January 2008, 09:59
Thanks for that Darrel .... I did not understand the significance of EasyHID when it was being discussed in this thread earlier on. Making some real progress now and think I should be able to recreate the VB USBDemo.exe in Delphi. Very exciting stuff this USB.

thye
- 30th January 2008, 17:14
Hi....i'm new in 18f4550..

Can picbasic pro program this PIC?

How to open the USB port on this PIC?

Thanks a lot....

skimask
- 30th January 2008, 18:28
Hi....i'm new in 18f4550..

Can picbasic pro program this PIC?

How to open the USB port on this PIC?

Thanks a lot....

Read the thread...the WHOLE thread.
It's all there. A complete project from start to finish.
Many others have done it, I've done it, you can do it.
However, I wouldn't expect others to do it for you.

Momboz
- 30th January 2008, 20:54
Thanks for that Darrel .... I did not understand the significance of EasyHID when it was being discussed in this thread earlier on. Making some real progress now and think I should be able to recreate the VB USBDemo.exe in Delphi. Very exciting stuff this USB.

Hi
Here is an adaptation of Mister_E USBDemo but in Delphi. It's not completely finalised but it works. This example bases on the PICPROTO-USB board from MELabs (you can get all the information on this board from their web site).

It's PIC18F4550 @ 20 MHz based. I hope the rest is self explanatory. PWM signal is on PORTC.2.

If you need more info, just let me know. Please, take into account I am not very often on this forum, i.e. please, allow longer reaction times in case you need feedback.

Have fun

kiwipiper
- 31st January 2008, 11:51
Thanks Momboz but I managed to completely recreate Mister_E's USBDemo.exe in Delphi. It was pretty easy once I understood what EasyHID was all about. Had a little bit of trouble with the PWM but in the end once I understood what MSB and LSB was all about that fell into place as well. The only thing I can get working is showing a serial number.

Anyway, thank you to everyone who has contributed to this thread it was all very helpful getting me on the right track. For those just starting with this I concur with skimask's comments two posts back that all the information you need is in this wonderful thread. It is the journey of discovery that is the important part and a bit of a struggle makes it all the more rewarding when you get there in the end.

Here is a link to my KPUSBDemo.zip for another take on the computer interface. It is slightly over the 200K limit, most likely due to my coding skills and overuse of graphics to pretty it up some. If anyone is keen on the code I could clean it up a bit, zip it up and put it up somewhere.

http://www.breambay.com/downloads/KPUSBDemo.zip

thye
- 31st January 2008, 13:57
Hi....what is EasyHID? Is it same as picbasic pro software?

Where can I download the EasyHID?

Thanks a lot....

skimask
- 31st January 2008, 16:18
Hi....what is EasyHID? Is it same as picbasic pro software?
Where can I download the EasyHID?
Thanks a lot....

Refer to Post #173...
Read thru the thread...you have not...
Use the search function...you have not...
Therefore...EasyHID...you have not...
Heed advice given above...and EasyHID...you shall have...

semiuniversal
- 5th February 2008, 07:20
Hi mister_e & all who have contributed. I am quite new to PBP and this is my first post to this list. I just found this demo a week ago, read the thread, ordered the parts, assembled a proto board on Saturday and - (insert Windows USB Device da-dink! sound) it worked FLAWLESSLY, the first time. I am either lucky standing on the shoulders of giants - but oh, my, what a good feeling.

I have been tinkering incessantly since then.
Thank you for giving me super powers.

skimask
- 5th February 2008, 15:14
Hi mister_e & all who have contributed. I am quite new to PBP and this is my first post to this list. I just found this demo a week ago, read the thread, ordered the parts, assembled a proto board on Saturday and - (insert Windows USB Device da-dink! sound) it worked FLAWLESSLY, the first time. I am either lucky standing on the shoulders of giants - but oh, my, what a good feeling.

I have been tinkering incessantly since then.
Thank you for giving me super powers.

Take my advice...Give out while you still can...
I have lost countless hours of sleep playing with USB and that demo, spent untold amounts of money, not to mention ticked off the wife numerous times...

Seriously though...Good game...
I wish other Noobs would take that as an example...especially the part about 'reading the thread'....

mister_e
- 4th April 2008, 20:14
NOTE: If your going to use LONG variables, you MUST copy the PIC18Xxxxx.BAL file in your source directory as well, unless you'll receive some compilation errors.

The .BAL file is located in \PBP\USB18 directory.

If you're using PIC18F4550, you MUST copy the 18F4550.BAL file in your source code directory.

@Darrel.. is this possible to paste it in the first post as well as the other source code (or link) for the other PICs (post 99 http://www.picbasic.co.uk/forum/showpost.php?p=38468&postcount=99) ?

Darrel Taylor
- 4th April 2008, 21:15
Done! :) &nbsp;

skimask
- 5th April 2008, 07:33
Done! :) &nbsp;
$20 says a dozen people miss the 18Fxxxx.BAL note...

UnaKRon
- 7th June 2008, 03:46
Ok so first of THANK YOU to everyone.

I'm much further than I was a year ago already...which is a device windows enumerates....
Now for the problem

So i have a 2550. I commented out the old .inc file lines updated the ASM line to reflect the proper PBP version i have, implemented the corrected Fuse settings for the 20mhz crystal. and When I plug up the device to Windows I get "USBDemo" then it changes to two different things Hid compliant device and USB Human Interface Device. Then The HID compliant one disappears...then the USB Human Interface Device Gets an ! over it...

If i run the USB demo VB program the Device Manager Updates and sometimes It will remove teh USB device all together...or sometimes just change to a USB Unknown Device.

WTF?!

Earlier I plugged it in and the DEMO vb Recognized it and displayed the RX data for like...20 loops....then then everything stopped. it didnt recognize the usb device anymore as the Mister_E USBdemo that the program previously displayed...

Other than the ASM changes, "DEFINE OSC 20" and fuse changes ....i haven't changed anything software side. Hardware I have a .33uf because well...the store had a .47uf in 300volts size..and that was to large for the board..and kinda ridiculous. PBP version is 2.46
Is there a setting in MELABS programmer for the internal pull ups? I saw there was on in the code..but maybe it was being overwritten?


I've been toying for 3 days now...re reading the thread and looking at others... :(

Also...I dont have a .BAL file...*.bal search turned up nothing.. GR....

Anyone?

skimask
- 7th June 2008, 05:07
Other than the ASM changes, "DEFINE OSC 20" and fuse changes
Which are rather large changes considering you have to have the right freq for the USB to run right in the first place.


PBP version is 2.46
Don't know if it'll fix your problem or not, but there is a 2.46 patch, and a few updates for $25 that gets you up to PBP 2.50A. A few fixes for USB and PIC18F types. Might help, might not.


Is there a setting in MELABS programmer for the internal pull ups?
Internal pullups on Port B are described in the datasheet for the particular PIC.


Also...I dont have a .BAL file...*.bal search turned up nothing.. GR....
And you won't unless you're using PBP 2.50A.

sirvo
- 19th July 2008, 21:12
Hello..

I'm using 18F2550 and USB is working very well... I've been trying to increase the buffer size from 8 to 16 but it do not work.

On Pic's code, I've only changed this:


BufferSize con 16
' BufferSize con 8


On VB's code, this:


Private Const BufferInSize = 16
' Private Const BufferInSize = 8


Any idea of what is the problem?

Thanks!!

Darrel Taylor
- 19th July 2008, 21:26
The IN/OUT "Report" length is usually set in one of the easyHID dialogs.
Or it can be changed manually in the Descriptor file.

If you re-run easyHID for the same project, it will wipe out any changes you've made. So create a new project, set everything the way you want it in easyHID, then just copy the descriptor file to your existing project.

hth,

sirvo
- 19th July 2008, 23:33
Done! Perfect Darrel!

Thanks a lot!

Philtkp
- 8th August 2008, 18:48
Hello,

First, Mister e This is an outstanding demo. Was able to get running right out of the box on a PIC18f4550.

I've been trying to add an additonal 8 LEDs to the demo but keep getting overrun errors. Which I'm sure it's caused on the VB side. I'm almost sure the PIC side is ok as i can turn on the original 8 LED or the ones added to PORTD. Can even turn on 4 on PORTB and 4 on PORTD. I'm just unable to get all 16 working at the same time.

I think my problem is in this part of the VB side code. I was hoping someone could point me back in the proper direction


Private Sub Check1_Click(index As Integer)
'
' Convert PORTB check box to decimal value before sending it
' to USB bus. Result is store in BufferOut(1)
'
Dim LoopCheck, PORTB As Byte
PORTB = 0
For LoopCheck = 0 to 15 ' 0 To 7
PORTB = PORTB + (Check1(LoopCheck).Value * (2 ^ LoopCheck))
Next
BufferOut(1) = PORTB
WriteSomeData
End Sub

Any assistance would be greatly appricated

skimask
- 8th August 2008, 18:52
Private Sub Check1_Click(index As Integer)
'
' Convert PORTB check box to decimal value before sending it
' to USB bus. Result is store in BufferOut(1)
'
Dim LoopCheck, PORTB As Byte
PORTB = 0
For LoopCheck = 0 to 15 ' 0 To 7
PORTB = PORTB + (Check1(LoopCheck).Value * (2 ^ LoopCheck))
Next
BufferOut(1) = PORTB
WriteSomeData
End Sub


PortB is a byte value. A byte runs 0-255...
2 ^ 15 = 32,768 which is greater than 255!

Philtkp
- 8th August 2008, 19:59
PortB is a byte value. A byte runs 0-255...
2 ^ 15 = 32,768 which is greater than 255!

I tried changing the variable, PortB to an Integer and Long with no positive results

skimask
- 8th August 2008, 20:32
I tried changing the variable, PortB to an Integer and Long with no positive results

Well of course it won't work.
PortB is a Visual Basic Byte variable (or whatever you want) which gets stored in a Byte Array and sent over the USB to the PIC as a Byte variable stored in a Byte array, which is then stored in the PIC as a Byte variable.


Private Sub Check1_Click(index As Integer)
'
' Convert PORTB check box to decimal value before sending it
' to USB bus. Result is store in BufferOut(1)
'
Dim LoopCheck, PORTB As Byte
PORTB = 0
For LoopCheck = 0 to 15 ' 0 To 7
PORTB = PORTB + (Check1(LoopCheck).Value * (2 ^ LoopCheck))
Next
BufferOut(1) = PORTB
WriteSomeData
End Sub

Philtkp
- 8th August 2008, 21:58
Can this be done using an array of bytes?

skimask
- 8th August 2008, 22:03
Can this be done using an array of bytes?

You ARE sending out an array of bytes...8 of them, unless you've messed with the HID-Maker.
You have to send out more bytes or figure out a way to 'encode' those bytes you've already got to do more...

ozion
- 29th October 2008, 01:42
www.pbpgroup.com/files/HIDmonitor.exe
Put it anywhere, there is no installation to do.
<br>

Very handy little utility. Thank you very much Darrel.
Regards,
ozion

dr_w
- 6th November 2008, 14:05
i want to use usbdemo to count rpm of motor and display the rpm in computer. how to do that?

mister_e
- 6th November 2008, 17:30
Begin small, begin by finding a way to count the RPM, show it on a lcd or via a serial communication... once you have it done, port your to code to USBDemo.

dr_w
- 6th November 2008, 22:00
i use 8 slot encoder.
after googling few minutes. i add this code into usbdemo


COUNT PORTA.2,100,speed
speed = speed * 10 * 60 / 8
rpm[0] = speed / 1000 // 10
rpm[1] = speed / 100 // 10
rpm[2] = speed / 10 // 10
rpm[3] = speed // 10
rpm[4] = 0
rpm[5] = 0
rpm[6] = 1
rpm[7] = 1

@ SendUSB _rpm

Darrel Taylor
- 21st August 2009, 09:36
With the release of PBP version 2.60, mister-e's USBdemo (or any other program derived from EasyHID) will no longer compile (without some changes).

The new way of doing USB with PBP is really nice.
So here's a modification to Steve's program that will allow it to be compiled with PBP 2.60, and hopefully show how much easier it is to do USB.<hr>
√. If you haven't already ... download and extract the USBDemo from the beginning of this thread.

√. Then create a new folder (USBDemo260) and copy the USBDemo.pbp file from Steve's archive into the new folder.
That is the only file that is valid with 2.60, so don't copy any of the others.

√. Download the USBDEMOdesc.bas.txt (http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3597&d=1250839944) (descriptor) file attached to this post and place it in the same folder. Remove the .txt extension.

√. In the USB18 folder, inside your PBP folder ...
Copy the following files to the project ...

usb_dev.asm
usb_dev.inc
usb_hid.asm
usb_hid.inc
usb_mem.asm

√. Add this line to the USBDemo.PBP program ... and compile.
INCLUDE "USBDEMOdesc.bas"

And away you go, with a little Ding-Dong ... Or maybe a Dong-Ding. :)<hr>
Make sure you change the configs if you're not using a 4Mhz crystal.
And comment out the UCFG EXT variable since it's not needed anymore.

The Visual Basic part of mister-e's demo is the same.
You can use the pre-compiled program, or modify it as desired.

jellis00
- 26th October 2009, 07:49
Hi all,
Since the USB stuff is coming more and more popular, and as we see more and more questions, i decided to post my little contribution.

OK OK You already asked... but i'm in a good moon today, so let me believe it never been asked before ;)

The whole thing will use a PIC18F4550 and a 4MHz crystal + few Leds, 2 trim pot... you should be able to figure this out easy.

There we go, here's the PC interface,


<img SRC="http://www.mister-e.org/Pics/USBDemo.JPG">

Steve, the link to the PC interface schematic as posted in your original is broken. Can you please give me a valid link or email me the schematic at [email protected]? I want to check your USBDemo out!

Darrel Taylor
- 26th October 2009, 21:00
Haven't seen him around for awhile.
His website is gone too.

Here's the schematic he had previously posted.

http://www.pbpgroup.com/files/USB_schematic-mrE.gif

Acetronics2
- 27th October 2009, 10:18
Hi,

Last news for me are stamped August, the 14 th ....

Steve was telling he still need some " quiet " time.

But do not hope to read from him before " a certain time " ...


Much Higher priorities thans solving "problems" ( seen quotes ??? ) when solutions just are "in the Manuals".
May be he "simply" has to take care of himself, ... for once.

No Forum for that ...

Alain

jellis00
- 4th November 2009, 01:44
√. If you haven't already ... download and extract the USBDemo from the beginning of this thread.

√. Then create a new folder (USBDemo260) and copy the USBDemo.pbp file from Steve's archive into the new folder.
That is the only file that is valid with 2.60, so don't copy any of the others.

√. Download the USBDEMOdesc.bas.txt (http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3597&d=1250839944) (descriptor) file attached to this post and place it in the same folder. Remove the .txt extension.

√. In the USB18 folder, inside your PBP folder ...
Copy the following files to the project ...

usb_dev.asm
usb_dev.inc
usb_hid.asm
usb_hid.inc
usb_mem.asm

√. Add this line to the USBDemo.PBP program ... and compile.
INCLUDE "USBDEMOdesc.bas"


Darrel, I followed steps you listed explicitly and then tried to compile with PBP 2.6. Got the following error:
" ERROR line 81: Redefinition of VAR. USBDemo.pbp]"
which I don't understand since the UCFG variable is not declared anywhere else in the code...just this line where the code occurs.
The error applies to the statement
"UCFG VAR BYTE EXT ' include UCFG register... Yeah Melabs didn't :o("

I went to manual on 2.6 compiler to check syntax of this statement. I guess I don't understand the use of EXT at the end of the statement....manual doesn't explain that.

Can you tell me what might be wrong and why this won't compile?? I would really like to get this USBDemo going for my 18F4550.

Also don't understand why Steve's schematic that you posted varies from the hardware description in the USBDemo260 code:
Here is the Hardware description from the code:
Hardware:
' ---------
' 4 Push Buttons on PORTA<5:2> with pull-down resistors
' 2 Trim pot on PORTA<1:0>
' 8 LEDs attach between PORTB and GND
' 2 LEDs attach to CCP<2:1> pins
' 4 MHZ crystal & all the usual USB stuff
Yet the schematic shows no pushbuttons on PORTA <5:2>, no trim pota on PORTA <1:0>, no LEDS on PORTB or CCP, and a 20 MHz crystal rather than 4 MHz. Can you advise me of the correct hardware hookups for the USBDemo260 code...the schematic or the code description??

Darrel Taylor
- 4th November 2009, 02:01
Darrel, I followed steps you listed explicitly...The error applies to the statement "UCFG VAR BYTE EXT


... And comment out the UCFG EXT variable since it's not needed anymore. ...
Steve wrote that program when 2.46 was the latest and greatest.
At that time UCFG VAR EXT was missing from the PIC18EXT.bas file.
But with 2.60, the oversight has been corrected, so you don't need that line anymore.
Well actually, you didn't need it then either, it's handled by the USB routines.
So not sure why he put it there to begin with.

The schematic is the one you requested.
It was originally from Mecanique, and I'm sure he was showing how to hook up the USB stuff.
And probably assumed the user would know how to connect LED's and switches on their own.
<br>

jellis00
- 4th November 2009, 06:22
At that time UCFG VAR EXT was missing from the PIC18EXT.bas file.
But with 2.60, the oversight has been corrected, so you don't need that line anymore.<br>
Thanks, Darrel. That fixed it and it now compiles. Sorry I didn't read your comment more closely about commenting out this statement.
My next step, now that it will compile, is to configure my hardware on an EasyPic6 and then program the 18F4550 and run the program.

One question: Do I need to run the VB6 program on my PC with the USB cable connected before I turn on power to the 18F4550 and run its code??

Darrel Taylor
- 4th November 2009, 06:43
Thanks, Darrel. That fixed it and it now compiles.
Sweet!


One question: Do I need to run the VB6 program on my PC with the USB cable connected before I turn on power to the 18F4550 and run its code??
Doesn't matter, the VB program will pick up when it connects, and sometimes when it disconnects. :eek:
<br>

jellis00
- 4th November 2009, 21:40
Sweet!
Doesn't matter, the VB program will pick up when it connects, and sometimes when it disconnects. :eek:
<br>

Darrell, thanks to your help I now have the USBDemo running on my EasyPic6 and everything appears to work except an annomaly with the RA4 pushbutton. When I initially power up, the VB6 window shows all four pushbutton lights on (GREEN). When I push each of the RA2-RA5 pushbuttons on the EasyPic6, the lights go temporarily out while the pushbutton is depressed, which is expected. However, when RA4 is released it stays unlit, unlike the other pushbuttons. Then if I power down and power backup or if I reset, it is lit again along with the others, and the sequence described above happens again if I depress the buttons.
I don't understand why the RA4 pushbutton doesn't operate like the others as a momentary switch. I checked the code and it appears it should. Is there some reason for this? I thought it might even be a problem with my EasyPic6, but the RA4pushbutton is operating normally in other codes I have that use it on the EASYPIC6. I didn't do anything about changing the capacitors on the EasyPic6 that

I also notice that the RX window continuously shows 10 line entries of "USBDemo" and when you click the Clear RX button, it immediately repopulates the RX window with the same 10 entries. I am trying to understand this and presume that these entries are due to the TMR0 interrupt executing every 100 usec to run the goto at DoUSBService, which reloads the TMR0. I presume each time this reload takes place and the TMR0 overflows, a USBDemo line appears in the RX window. Am I understanding what is happening???

I am TOTALLY impressed with this code and the functionality Steve created in this demo! He is to be highly commended for sharing this since it helps people (like me) to finally understand at a basic level how to incorporate a USB interface into our applications.
Now I have to figure out how to modify it for a specific application that operates this way...am explaining in hopes you or someone else on this thread will have some ideas:
1) the Main code wakes up from SLEEP mode every night at midnight and executes 6-12 ultrasonic range finder measurements which are averaged and the average result is logged into EEPROM, and then it goes back to SLEEP till next midnight.
2) This data logging occurs every night at midnight. If at any time a USB cable is plugged into the USB connector (which will only happen once every 30 days to download the 30 averaged range measurements from EEPROM), it must recognize this as an interrupt to the normal data logging application and permit the User on the other end of the USB interface (a laptop) to recover the 30 averaged range measurements from EEPROM to the laptop and export them into a spreadsheet.
Now that I have the USB interface working, I am struggling with how best to support this scenario with an interrupt that recognizes when the USB cable is connected. I thought I might use an RBIE: RB Port Change Interrupt in the MCU code that would be created by the laptop User when one of the RBx boxes in the VB6 User Interface is clicked. Do you have any better suggestions as to how to do this??

Would also appreciate any pointers you might have to the best approach for a midnight to midnight interrupt without having to add a RTC to my application. I thought a TMR1 approach with 24 hr delays might work for this, but have doubts that it would keep time accuracy well enough to always happen exactly at midnight. Any ideas are appreciated??

OzGrant
- 5th November 2009, 00:40
G'day
Have 2.60 PBP and did the latest setup etc as per the last few posts.
I now get the following errors when compiling.

ERROR: Unable to execute mpasmwin.Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0000)

Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0001)
etc.

Any ideas,
Tks

jellis00
- 5th November 2009, 02:27
I don't understand why the RA4 pushbutton doesn't operate like the others as a momentary switch. I checked the code and it appears it should. Is there some reason for this?
I also notice that the RX window continuously shows 10 line entries of "USBDemo" and when you click the Clear RX button, it immediately repopulates the RX window with the same 10 entries. I am trying to understand this...
The problem resolved itself and I don't know exactly why. The only changes I made were to make sure the pull-down resistors were enabled properly and to connect the RA0 pin to the potentiometer for the Analog A/D input. Either as a result of these changes or some other unknown reason, the annomaly of the RA4 pushbutton and the "USBDemo" messages in the RX window went away. I see now that the "USBDemo messages are not a result of the TMR0 reloads but only appear when the pushbuttons are pressed and the RX window clears normally now and stays clear until the next pushbutton.
Even though these problems are solved, I would still appreciate any inputs/ideas regarding my other questions. It begins to look like I can achieve my intentions for detecting USB connection by implementing the "self-power only" circuit as shown in Figure 17-11 of the 18F4550 data sheet. Will try it and report in later post.

Darrel Taylor
- 5th November 2009, 03:13
I now get the following errors when compiling.
ERROR: Unable to execute mpasmwin.
Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0000)
Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0001)
etc.

OzGrant,
See this thread about how to fix the configs ...
http://www.picbasic.co.uk/forum/showthread.php?p=6775#post6775

jellis00,
Uno momento ...
<br>

jellis00
- 5th November 2009, 04:11
Error[118] C:\PBP\USBDEMO260\USBDEMO.ASM 413 : Overwriting previous address contents (0001)

Make sure you commented out the _config statements in the 18F4550.inc file and resaved it. If you don't the _config statements in the USBDemo code will give this type of error. I don't have any ideas as to the other error...sorry!

What is your development environment?....editor (MicroCode Studio, MPALAB or what?)...assembler (MPASM or PM?).....programmer (PicKit2, EasyPic or what?)

OzGrant
- 5th November 2009, 04:21
Darrel,
Tks it of course fixed the error. I should spend more time searching the forum, that trying to solve the problem, and then by default put up a newbee sort of question. Will now wait for my Picstart Plus upgrade kit so I can burn the 18F4550 and have even more fun. Will now search the forum before I ask my next question "does the mcHID.dll work with VB5"
Tks again.
Grant

jellis00
- 5th November 2009, 04:28
[QUOTE=Darrel Taylor;80423]OzGrant,
See this thread about how to fix the configs ...
http://www.picbasic.co.uk/forum/showthread.php?p=6775#post6775

Attached .txt document is a list of the _CONFIG settings for the 18F4550 from its corresponding P18F4550.INC file in MPLAB folder. It is always a good idea to have this list handy when setting up code for a new program.

jellis00
- 5th November 2009, 04:30
[QUOTE=jellis00;80428
Attached .txt document is a list of the _CONFIG settings for the 18F4550 from its corresponding P18F4550.INC file in MPLAB folder.QUOTE]
Forgot to attach with previous post.

Darrel Taylor
- 5th November 2009, 05:29
USBDemo was a good starting point for me, Thanks Steve.
But there are several problems that don't coincide with what you want.

1) When you disconnect the cable, it will still try to send data, causing the PIC to enter a Locked Loop, waiting to send to an inactive bus.

2) You really have no indication that anything was received.
If there's no incoming data, it just goes ahead and sets the dutycycles again, using the old data left over in the buffer.

3) There's no indication of when it's connected, when something was received or when it's ok to send.

4) With the 1mS servicing from Timer0, it's a bit sluggish when enumerating, overall data rates suffer and it uses TMR0 when it doesn't need to.

5) EasyHID no longer works with 2.60, so it's difficult to make changes to the descriptors.

6) I don't use Visual Basic, so I can't update the PC program.
My main language is Delphi, and I stopped using mchid.dll a long time ago.

I would have worked with Steve to build a better demo, but alas, he's not here.
<hr>
I'm thinking it's time to unveil DT_HID.
It's the PIC side of USB, made ... yes, I'll say it ... EASY!

The PC side is still up to you, but it even works with Steve's original VB prog, so that, or any other VB/Delphi program from EasyHID can be used as a "template".

I'm not even going to tell you how it works. :eek:
I defy you to not understand what it does.
Up until you ask a question.

Warning, the example is setup for 13K50/14K50.
Comment the configs, and uncomment the other configs (if needed).
Change ANSELs to ADCON1 (if needed).

Also note: This is for PBP 2.60 only.
BasicUSB.pbp is the test program.

Don't shoot me, I can't even play a piano ...

jellis00
- 5th November 2009, 08:17
USBDemo Warning, the example is setup for 13K50/14K50.
Comment the configs, and uncomment the other configs (if needed).
Change ANSELs to ADCON1 (if needed).

I made these changes to the BasicUSB.pbp code for use with 18F4550 as you can see in my listed code below. It compiles OK into a .hex file which I then programmed into the 18F4550 using the PicFlash programmer in my EasyPic6. By all appearances everything was OK until I turned on power to the MCU with Steve's VB6 program running....at that point the USB connection was not recognized and nothing else happened. Can you look at this code and tell me what is wrong. I made shure both the include files were in the PBP folder and since it compiled I interpreted that to mean the INCLUDES were OK. Since I was able to get Steve's code to run in my EasyPic6 I believe that eliminates the VB6 code as the problem, so need to figure out how to debug yours and when it doesn't connect or do anything visible, I don't know how to debug it.


I'm not even going to tell you how it works. :eek:
I defy you to not understand what it does.
Up until you ask a question.

I studied the code in both the test program and in DT__HID.bas and unfortunately I guess I don't understand what it does since I can't get it to work. I need your HELP.

'**********************************
'* Name : BasicUSB.pbp *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2009 *
'* Date : 7/23/2009 *
'* Version : 1.0 *
'* Notes : *
'* : *
'**********************************
;--- if you un-comment these, you must comment the ones in the .inc file ---
ASM ; 18F2550/4550, 8mhz crystal as used in EasyPic6
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

ASM ; 18F13K50/14K50 Only 12mhz crystal can be used for USB
; __CONFIG _CONFIG1L, _CPUDIV_NOCLKDIV_1L & _USBDIV_OFF_1L
; __CONFIG _CONFIG1H, _FOSC_HS_1H & _PLLEN_ON_1H & _PCLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
ENDASM

DEFINE OSC 48
clear

;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
endm
INT_CREATE ; Creates the interrupt processor
endasm

;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"

DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Darrel Taylor"
DEFINE USB_PRODUCTNAME "DT_HID"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 32 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 16 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

; --- Each USB LED is optional, comment them if not used ----
DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
DEFINE USB_PLUGGEDLED PORTB,0 ; LED indicates if USB is connected
DEFINE USB_TXLED PORTC,2 ; " " data being sent to PC
DEFINE USB_RXLED PORTC,1 ; " " data being received from PC

OutCount VAR WORD : OutCount = 0
Value VAR WORD
X VAR WORD

;--- Setup ADC -------------------------------------------------------------
DEFINE ADC_BITS 10 ; Number of bits in ADCIN result
ADCON2.7 = 1 ; right justify (Change this if ADFM in diff register)
ADCON1 = %00010000 ; AN4/RC0 Analog
'ANSELH = 0

;--- The Main Loop ---------------------------------------------------------
Main:
FOR X = 0 to 1000 ; Check for incomming USB data while pausing
@ ON_USBRX_GOSUB _HandleRX
PAUSE 1
NEXT X

ADCIN 4, Value
OutCount = OutCount + 1
ARRAYWRITE USBTXBuffer,["AN0=",DEC Value," -",DEC OutCount," "]
IF Plugged THEN GOSUB DoUSBOut ; only send when USB is connected
GOTO Main

;---- This just sends the received packet back to the PC -------------------
HandleRX:
ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
return

Darrel Taylor
- 5th November 2009, 18:26
Apparently, I missed the CONFIG2L.
I always miss that one, weird ...

__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L

And try the HIDmonitor program from the .zip

When I said it works with Steve's original program, well it will, but it's not set up to send/receive the same analog values and switches/LED's. With HIDmonitor you should see when it connects and what data it's sending.

hth,

jellis00
- 5th November 2009, 19:20
Apparently, I missed the CONFIG2L.
I always miss that one, weird ...

__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L

I made this _CONFIG change in the code. Compiles/assembles OK and appears to program the 18F4550 OK.

[QUOTE]And try the HIDmonitor program from the .zip

When I said it works with Steve's original program, well it will, but it's not set up to send/receive the same analog values and switches/LED's. With HIDmonitor you should see when it connects and what data it's sending.


Tried both your HIDmonitor and Steve's VB6 routine after programming and power/resetting the 18F4550 . Although I hear a low "click" and see the USB icon appear in my WINDOWS tray when the USB cable is connected from the PC, I don't see any indication of the connection on the HIDmonitor or on Steve's VB6. And the USB icon disappears out of the tray about 10 secs after the next keyboard key or mouse button is pressed with no audible "click". Nor do I hear another "click" or see any visual indication of disconnect when USB cable is disconnected. Nor is there any indication of any communications on either the HIDmonitor or the VB6 window.

Do you have any suggestions how I might monitor what is happening in the code while running so I can debug? I don't have a usable ICD.

Darrel Taylor
- 5th November 2009, 19:37
Before I posted last time, I copied your program to MCS, added the config2L and changed my crystal to 8mhz.

It fired right up, and is still connected now.
It shows up as DT_HID (001) in HIDmonitor.

Do you have anything on RB0, RC1 or RC2.
I've got some Status outputs to LED's on those pins, that shows when it's connected and when it sends/receives data.

You did have the hardware working before right?
<br>

jellis00
- 10th November 2009, 02:15
Do you have anything on RB0, RC1 or RC2.
I've got some Status outputs to LED's on those pins, that shows when it's connected and when it sends/receives data.<br>

Thanks, Darrel...this led me to the problem. The EasyPic6 has dip-slide switches that let you connect LEDs to the A/E, B, C, and D ports for troubleshooting. I had the switch selected for Ports B and C. When I finally realized I needed to shut them off everything started working properly.

However, one question. I notice while running MisterE's VB6 monitor side-by-side with your DT_HID monitor I see the Rx data showing some variances. I have attached a screen-snapshot of this so you can see.

Notice in the screen snapshot that when when AN=123, AN0= 1023; when AN=51, AN0=510, and when AN=-4, AN0=0. Since both are receiving the same data as transmitted by the PIC, shouldn't the displayed values be equal in both monitors??? Don't understand this. Can you explain for me??

My next step is to figure out how to capture what appears in the DT_HID Rx data window into a text file or better yet into a spreadsheet. Any suggestions as to how to do this in the DT_HID code?,

Darrel Taylor
- 10th November 2009, 03:24
Great, I thought I lost you. :)

The program is sending different data than mister-e's PC program is expecting.
I guess my example was off thread, and I should make an example that does work with his GUI.


My next step is to figure out how to capture what appears in the DT_HID Rx data window into a text file or better yet into a spreadsheet. Any suggestions as to how to do this in the DT_HID code?,
In Delphi sure ... can't help with Visual Basic though.

It may even be easier with CDC and Hyperterminal.
Outputting the data in CSV format from the PIC, and capturing it with the terminal, makes it real easy to import into excel. But it does require user intervention.
If it's has to be automatic, HID's the way, whether it's DDE exchanges, or saving the file and importing to excel.

Anyhow, I'll go make a more appropriate demo for Steve's GUI.

BBL,

Darrel Taylor
- 10th November 2009, 09:21
OK, this program should work with Steve's original USBDemo GUI.

18F2550/4550, 8Mhz, DT_INTS-18, DT_HID260.

Cheers,

jellis00
- 10th November 2009, 20:13
OK, this program should work with Steve's original USBDemo GUI.


Darrel,
Everything compiles/assembles/programs in my EasyPic6 configuration with 18F4550 (8 MHz crystal), and it does run with Steve's VB6 GUI, but only for data from the PIC....data to PIC side of the GUI doesn't work. I double checked that I didn't have anytheng on the EasyPic6 connected to the pins you are using. See attached screen snapshot of the VB6 GUI that shows what is working and what isn't.

I also notice that when I remove the comments on the DEFINE statements for the status LEDs that they do not light during the PLUGGED, TX or RX actions are supposedly taking place that they are suppose to indicate.

I looked at your code and I couldn't see where the problem is. Any ideas??

Darrel Taylor
- 10th November 2009, 20:31
The ones on the left require 8-LEDs on PORTB, and 2 other LEDs on the CCP outputs, RC1/RC2.

Previously you said you disconnected the LED's to get things working with the EasyPIC.

The USB D-/D+ are on RC4/RC5, so I don't think you can just enable the whole bank of LED's on PORTC. You'll need to attach LEDs to only the 2 CCP Pins to get the faders working. But you should be ok with LEDs on PORTB.

HTH,

jellis00
- 11th November 2009, 01:17
The ones on the left require 8-LEDs on PORTB, and 2 other LEDs on the CCP outputs, RC1/RC2.


The USB D-/D+ are on RC4/RC5, so I don't think you can just enable the whole bank of LED's on PORTC. You'll need to attach LEDs to only the 2 CCP Pins to get the faders working.
Turns out you can enable all the whole bank of LED's on PORTC and it keeps working. You can then see the LEDs on RC1 and RC2 vary in brightness as you change the sliders.


But you should be ok with LEDs on PORTB.

Except for the LEDs on RB0, RB5, Rb6 & RB7 (which are used in your code) you can now click the check boxes on B1 thru B4 on the VB6 Gui and they work to light the corresponding LEDs.

I now have Steve's VB6 GUI and the DT_HID monitor running side by side and everything works as advertised except for the exceptions I listed above for the B0 thru B7 check boxes. Your support to me in getting to this has been outstanding, Darrel. Thanks so much!

Now I only have to figure out how to capture the data coming across the USB interface from the PIC into a spreadsheet. Your suggestion to use CDC and HYPERTERM would be an easier option except that my application requires a USB interface that is also used to connect to a cell phone, and I don't have physical room for both an RS232 and a USB interface within the physical board size contstraint or panel connector space. Looks like I have to figure out how to do the capture in Steve's USB VB6 GUI. I will modify the PIC side to send comman delimited data per your suggestion, but don't know how to approach capturing the comma delimited data from the VB6 USB Gui that is showing into a spreadsheet. Can you refer me to any forum ideas or reference tutorials in this area??

Thanks again, Darrell. Your contributions & presence on this forum is what makes it worthwhile.

Darrel Taylor
- 11th November 2009, 01:47
PORTB.0 is not used anywhere in the program (other than output from the Demo).
PORTB.5-7 are only used if the USB Status LED lines are uncommented (I left them commented). And they can be assigned to any pin, they don't have to be PORTB.5-7

CDC is USB, there's no RS232 connector.

In excel, use the Data | Import External Data | Import Data menu item to just plop your CSV file right into your spreadsheet. Then when the data changes, use Data | Refresh Data to update everything automatically.
<br>

jellis00
- 7th December 2009, 19:38
Sorry to be such a pest, Darrell, but am now trying to adapt your USBdemo_DTID so that it will go into USB connection mode as an interrupt when the USB cable is connected, permitting me in the Interrupt Service Routine to execute some code that is only intended to be executed when the USB cable is connected.
I thought I could make the simple changes to your code as shown in my attachment below, where I just used a USB_INT with the DT_INTS-18 include file to perform the interrupt to my label "USBhandler".
This compiles and assembles OK and starts on power up, but when the USB cable is connected I get a WINDOWS error saying "USB Device Not Recognized". Am I missing something here on how to make this work as a USB connection interrupt??


'************************************************* *************************
'* Name : USBdemo_DTHID2.pbp *
'* Author : Modification of Steve Monfette/Darrel Taylor *
'* Date : 11/9/2009 *
'* Version : 2.0 *
'* Notes : This is a re-creation of mister-e's USBdemo for DT_HID *
'* : Meant to work with mister-e's GUI but with a USB interrupt *
'* : service routine where some specific code will be executed *
'* : only during USB connection. *
'************************************************* *************************
;-- if you un-comment these, you must comment the ones in the .inc file --
ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

DEFINE OSC 48
CLEAR

;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_INT, _USBhandler, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm
@ INT_ENABLE USB_INT ; enable external (INT) interrupts

;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"

DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Mister E/DT"
DEFINE USB_PRODUCTNAME "USBDemo"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 8 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

; --- Each USB status LED is optional, comment them if not used ------------
; --- They can be assigned to any pin, and no further action is required ---
DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
;DEFINE USB_PLUGGEDLED PORTB,7 ; LED indicates if USB is connected
;DEFINE USB_TXLED PORTB,6 ; " " data being sent to PC
;DEFINE USB_RXLED PORTB,5 ; " " data being received from PC


;--- Variables -------------------------------------------------------------
Value0 VAR WORD
Value1 VAR WORD
X VAR WORD
DUTY1 VAR WORD
DUTY2 VAR WORD
Old_PORTA VAR BYTE
New_PORTA VAR BYTE

;--- Setup ADC -------------------------------------------------------------
DEFINE ADC_BITS 8 ; Number of bits in ADCIN result

;--- Initialize ------------------------------------------------------------
CCPR1L = 0
CCPR2L = 0
CCP1CON = %00001100 ' CCP1, PWM mode
CCP2CON = %00001100 ' CCP2, PWM mode
PR2 = 249 ' 0-1000 duty range
T2CON = %00000101 ' TMR2 on, prescaler 1:4

TRISB = 0
OUTPUT PORTC.1
OUTPUT PORTC.2

ADCON2.7 = 0 ; left justify (Change this if ADFM in diff register)
ADCON1 = %1101 ; AN0/AN1 Analog

;--- The Main Loop ---------------------------------------------------------
Main:
'Normally in sleep mode waiting for interrupts
Toggle PORTE.2 ' Test LED flashing during Main loop
GOTO Main

'----------------Interrupt Service Routines Start Here--------------------
USBhandler:
FOR X = 0 to 1000 ; Check for incomming USB data while waiting
@ ON_USBRX_GOSUB _HandleRX
PAUSE 1

New_PORTA = PORTA ; Check PORTA pins
IF New_PORTA != Old_PORTA THEN
Old_PORTA = New_PORTA
ARRAYWRITE USBTXBuffer, ["USB Demo"]
GOSUB WaitToSend
ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2, _
PORTA.3, PORTA.4, PORTA.5,0,0]
GOSUB WaitToSend
ENDIF
NEXT X

ADCIN 0, Value0 ; Send A/D about once/sec
ADCIN 1, Value1
ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTA.2, _
PORTA.3, PORTA.4, PORTA.5,0,0]
GOSUB SendIfReady
'Code to be processed only during USB connection.
TOGGLE PortE.3 ' Test LED that USB interrupt occured
@ INT_RETURN

;--- Send Data if Plugged and ready, otherwise discard --------------------
SendIfReady:
IF Plugged AND TX_READY THEN DoUSBOut
RETURN

;--- Wait till Ready to send of until unplugged ---------------------------
WaitToSend:
WHILE Plugged and !TX_READY : WEND
IF TX_READY THEN GOSUB DoUSBOut
RETURN

;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
HandleRX:
ARRAYREAD USBRXBuffer,[PORTB, DUTY1.LowByte, DUTY1.HighByte, _
DUTY2.LowByte, DUTY2.HighByte]
CCP1CON.5=DUTY1.1 ' load CCP1 duty value
CCP1CON.4=DUTY1.0 ' with Duty1
CCPR1L=DUTY1>>2 '

CCP2CON.5=DUTY2.1 ' load CCP2 duty value
CCP2CON.4=DUTY2.0 ' with Duty2
CCPR2L=DUTY2>>2 '
return

Darrel Taylor
- 7th December 2009, 20:39
DT_HID already uses the USB interrupt.
If you override it, then USB can't happen anymore.

Besides, your routine is not suitable for interrupts anyway.
There's 1000 loops with pauses and gosubs ... wouldn't work.

There is already a way to determine if the cable is plugged in or not, and that is handled by DT_HID.

When the cable is plugged in, and the USB is connected to the PC and has fully enumerated. The Plugged bit will be 1. When not plugged, it's 0.

So just put your routine in the Main loop, and only run it IF Plugged = 1.

Don't forget to restore the INT_Handler ...
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
endm
INT_CREATE ; Creates the interrupt processor
endasm


Also, DO NOT enter sleep mode when using USB.
<br>

jellis00
- 7th December 2009, 21:41
Also, DO NOT enter sleep mode when using USB.
<br>
So what your saying is I can't have the MCU in SLEEP mode and wake it up with an intterrupt when the USB cable is connected? Unfortunately, that is exactly what we wanted to do to save battery power on our application. It is only going to have someone plug a USB cable into it once per month and we wanted to have the MCU sleep except for about 1 minute at midnight each night and also when it then sees a USB cable plug-in once per month. Keeping it awake all the time to accomadate a possible USB connection will not meet our battery life requirements.
Is there any way to save power consumption by the embedded processing application when a USB cable is not plugged in???

Ioannis
- 7th December 2009, 21:57
Get +5Vfrom USB itself maybe?

Ioannis

Darrel Taylor
- 7th December 2009, 22:03
You can.
But before you put it to sleep, you'll need to put the USB module in suspend mode UCON.1, which can only be done reliably when unplugged.

This disables the USB voltage regulator and stops the clock to the SIE, which will give the lowest current consumption.

The USB routines are not setup to handle a resume.
So your best bet it probably to connect the +5V from the USB cable to one of the INT pins with a pull-down resistor.

When the cable gets plugged in, it will generate an interrupt, at which point you would execute an @ RESET to reset the processor and initialize the USB again.

HTH

jellis00
- 8th December 2009, 00:27
:(

The USB routines are not setup to handle a resume.
So your best bet it probably to connect the +5V from the USB cable to one of the INT pins with a pull-down resistor.
When the cable gets plugged in, it will generate an interrupt, at which point you would execute an @ RESET to reset the processor and initialize the USB again.
HTH
OK, so I made changes to my code per your suggestions (see partial code below) including an IF Plugged =1 test in the Main loop to pole for USB connection and go to my USB servicing procedure when connected. I didn't do anything to get SLEEP mode yet because I want to make sure the interrupts are working first in this code.
This code compiles, but creates a single error during assembly that says
"Error[101]c:\PathToAsmfile.asm 1132:ERROR:(INT_ENABLE priority state not found)". So I can't get it to run yet with this error.
I'm not sure what this error is telling me...the required statement for @ INT_ENABLE INT2_INT is in the code. Does it also require an INT_ENABLE USB_HANDLER statement for the USB interrupt??


Include "Modedefs.Bas"
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.

DEFINE OSC 48

;--- if you un-comment these, you must comment the ones in the .inc file--
ASM ; 18F2550/4550, 8mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

' Initialize Hardware
' ===================
Spare_1 VAR PORTB.7 ' PGD for ICSP & Spare I/O for normal ops
Spare_2 VAR PORTB.6 ' PGC for ICSP & Spare I/O for normal ops
'Set registers
TRISA = 0 ' PORTA all outputs for LCD use
TRISB =%00011000 ' RB4 & RB3 set as RTC Alarm1 & Alarm2 inputs
TRISC = 0
TRISD = 0
TRISE = 0

'------------SETUP FOR USING DS1337 Real Time Clock (RTC)---------------
'************************************************* **********************
' Setup Hardware for uart
' =======================
DEFINE HSER_BAUD 115200
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1

' Aliased Variables for CLock
' ===========================
Alarm1 VAR PORTB.4 ' Alarm1 input from DS1337 INTA
Alarm2 VAR PORTB.3 ' Alarm2 input from DS1337 INTB
SCL VAR PORTB.1 ' I2C clock pin
SDA VAR PORTB.0 ' I2C data pin
RTC CON %11010000 ' RTC device write address(byte addressing)
' This is a list of allowable clock contrl settings, one which must be
' setup in the SetTimeAndDate subroutine as intended.
'contrl CON %00000011 ' Starts the oscillator, sets the SQW/OUT
' to 1 Hz, enables INTA interrupt from A1F
' or from A2F. WORKS as intended!!
'contrl CON %00000111 ' Starts oscillator, enables INTA interrupt
' from A1F or INTB from A2F. WORKS OK!
' Both interrupts staggered 30 secs apart.

' RTC Address definitions
' ========================
SecReg CON $00 ' seconds address (00 - 59)
' MSB of SecReg must be set to a 0 to enable RTC
MinReg CON $01 ' minutes address (00 - 59)
HourReg CON $02 ' hours address (01 - 12) or (00 - 23)
DayReg CON $03 ' day address (1 - 7)
DateReg CON $04 ' date address (01 - 28/29, 30, 31)
MonthReg CON $05 ' month address (01 - 12)
YearReg CON $06 ' year address (00 - 99)

' Alarm 1 Address definitions
' ===========================
Alm1sec CON $07 ' Alarm 1 seconds address (00 - 59)
Alm1min CON $08 ' Alarm 1 minutes address (00 - 59)
Alm1hr CON $09 ' Alarm 1 hours address (01 - 12) or (00 - 23)
Alm1Day CON $0A ' Alarm 1 day address (1 - 7)

' Alarm 2 Address definitions
' ===========================
Alm2min CON $0B ' Alarm 2 minutes address (00 - 59)
Alm2hr CON $0C ' Alarm 2 hours address (01 - 12) or (00 - 23)
Alm2Day CON $0D ' Alarm 2 day address (1 - 7)

' Alias of Clock register addresses
' =================================
ContReg CON $0E ' CONTROL register address
StatusReg CON $0F ' STATUS register address

' Clock Variables
' ================
sec VAR BYTE ' seconds
MINs VAR BYTE ' minutes
hr VAR BYTE ' hours
day VAR BYTE ' day
date VAR BYTE ' date
mon VAR BYTE ' month
yr VAR BYTE ' year

' ALARM1 VARIABLES
' ================
A1sec VAR BYTE ' seconds
A1MINs VAR BYTE ' minutes
A1hr VAR BYTE ' hours
A1day VAR BYTE ' day

' ALARM2 VARIABLES
' ================
A2MINs VAR BYTE ' minutes
A2hr VAR BYTE ' hours
A2day VAR BYTE ' day

GoSub SetTimeAndDate ' Setup current time & alarm settings

'*----------------SETUP FOR USING USB INTERFACE-------------------------
'************************************************* **********************
INCLUDE "DT_HID260.pbp"

DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Mister E/DT"
DEFINE USB_PRODUCTNAME "USBDemo"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 8 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

; --- Each USB status LED is optional, comment them if not used ---------
; ---They can be assigned to any pin, and no further action is required --
;DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
;DEFINE USB_PLUGGEDLED PORTB,7 ; LED indicates if USB is connected
;DEFINE USB_TXLED PORTB,6 ; " " data being sent to PC
;DEFINE USB_RXLED PORTB,5 ; " " data being received from PC

;--- Variables ----------------------------------------------------------
Value0 VAR WORD
Value1 VAR WORD
X VAR WORD
DUTY1 VAR WORD
DUTY2 VAR WORD
Old_PORTA VAR BYTE
New_PORTA VAR BYTE

;--- Setup ADC ----------------------------------------------------------
DEFINE ADC_BITS 8 ; Number of bits in ADCIN result

;--- Initialize ---------------------------------------------------------
CCPR1L = 0
CCPR2L = 0
CCP1CON = %00001100 ' CCP1, PWM mode
CCP2CON = %00001100 ' CCP2, PWM mode
PR2 = 249 ' 0-1000 duty range
T2CON = %00000101 ' TMR2 on, prescaler 1:4

TRISB = 0
OUTPUT PORTC.1
OUTPUT PORTC.2

ADCON2.7 = 0 ; left justify (Change this if ADFM in diff register)
ADCON1 = %1101 ; AN0/AN1 Analog

'------------------------SETTINGS FOR INTERRUPTS------------------------
'************************************************* **********************
'Set interrupt related registers
RCON.7 = 1 ' Set Interrupt Priority Enable bit (Bit7=IPEN)
' to enable priority levels on interrupts
INTCON.7 = 1 ' Set Global Interrupt Enable bit
INTCON.6 = 1 ' Set PEIE to enable low priority periph interrupts
INTCON2 = %10001000 ' Enable PORTB Pull-ups (Bit7-high), set INTEG2
' for falling edge (Bit4-low) on RTC's interrupt.
INTCON3 = %10001000 ' Set INT2IP high priority (Bit7-high),
' enable INT2IE for interrupt(Bit4-high)
RTC_INT_FLG VAR INTCON3.1 'Alias for RB4 INTA interrupt from RTC
'Setup external interrupt macros
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
INT_Handler INT2_INT, _Alarm, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT2_INT ; enable external (INT) interrupts

' -----------------------BEGIN MAIN PROGRAM LOOP-----------------------
'************************************************* **********************
Main:
Pause 1000
IF Plugged = 1 THEN
HIGH PORTC.6
GOTO USB ' USB cable is plugged-in
ENDIF
' Else, do other things if not connected
' If Alarm interrupt, read current time & ALARM settings from DS1337
' Perform range measurements if Midnight
LOW PORTC.6
USB:
'Process data from EEPROM to PC via USB interface

GoTo Main ' Endless Loop
End ' Safety measure to insure program stops if reaches here

'--------------------( Begin Interrupt Handler )------------------------
'************************************************* **********************
Alarm:
HIGH PORTC.7 ' Test LED if Interupt
' Put code here to service the Alarm interrupt
LOW PORTC.7
' Resume Main Program
@ INT_RETURN
End ' Safety measure to insure program stops if reaches here
'------------------{ End of Interrupt Handler }---------------------------

' START LIST OF SUBROUTINES
'**************************

Darrel Taylor
- 8th December 2009, 02:30
Put the Interrupt definitions before the HID stuff.

That's the way it was originally. But it got reversed in your program.

Also, don't mess with all the INTCON and RCON registers.
DT_INTS handles all those for you.
If you change them, it can interfere with the interrupt system.
<br>

jellis00
- 11th January 2010, 19:21
Darrel, first of all let me commend you on they way you created the USBdemo. It has been a god send to me to save time in getting my application to work with a USB interface. However, I have a couple of more questions:
1) I notice that this declaration implies you must use BufferIn(X) where X is either 8.16, 32, or 64.
"DEFINE USB_INSIZE 8 ; IN report is PIC to PC (8,16,32,64)"
Is that true also with the BufferOut(X) per this statement?
DEFINE USB_OUTSIZE 8 ; OUT report is PC to PIC
I ask this question because I need 10 data elements per BufferOut transmission for my application and didn't know whether I could size the BufferOut as 10 or would have to use 16.

2) In my application I need the PIC to read individual Bytes out of EEPROM and then send them as data to the PC via the USB interface. The data is stored in EEPROM during normal ops as 75 data sets, each data set consisting of 3 bytes. The PIC code reads each data set into a three element array, arrData(i,j,k), where i, j,k range from 0 to 74. My question is how to code the PIC to best fit this data into the BufferOut array to send each arrData(i,j,k) over the USB interface, at the rate of one per second. The data is in the PIC code in the form of:
arrData(0,0,0)
arrData(1,1,1
arrData(2,2,2)
|
|
arrData(74,74,74)
I want each data set to show up at the PC as the three bytes contained in the array element. I guess my question is in essence how to convert each array element into the three BufferOut(X) bytes for transmission.

3) I also notice that the PC's RX Window of my application is showing continuous receipt of a e garbagvalue shown as "p|?|6||", even when none of the PORTA pushbuttons are pressed. But when PORTA.4 button is pressed, the string value "USBDemo" is correctly received. However, when any of the other PORTA buttons are pressed it has no impact on the data stream and just shows another "p|?|6||". All other functions of the USBDemo interface work OK. It almost seems like there is a continuous button bounce going on in PORTA, but causing transmit of garbage values rather than the "USBDemo" string. I don't have a debug ability to see what is causing this. Any ideas?? If seeing my code would help you to assess this, let me know and I will somehow get it to you.

Darrel Taylor
- 11th January 2010, 20:41
Both USB_INSIZE and USB_OUTSIZE can only be 8,16,32 or 64.
If you want to send 10-bytes per report, it needs to be 16.

Question 2, I don't understand.
If you have them in arrays, just copy them to the USBTXBuffer.

And what looks like "garbage data" is the analog reading from the pots being sent periodically.
<br>

jellis00
- 11th January 2010, 21:44
Question 2, I don't understand.
If you have them in arrays, just copy them to the USBTXBuffer.
<br>
That is my problem...I don't know how to structure the code to write each array element of arrData(i,j,k) to the USBTXbuffer. Each of the elements of the USBTXbuffer is a single byte, whereas each element of the array is 3 bytes.
Are you saying I will still need to parse each array element into 3 bytes and then load each byte into one of the output buffer bytes??

Ioannis
- 11th January 2010, 21:54
Arrays in PBP can be byte or word. Not 3 bytes wide. So, what Darrel suggested is still valid.

I suppose that you don't know how to read 3 bytes everytime into a 8-byte buffer?

If so, just fill the rest with zero.

Ioannis

jellis00
- 11th January 2010, 22:13
Arrays in PBP can be byte or word. Not 3 bytes wide. So, what Darrel suggested is still valid.

I am ashamed to admit I missed that in terms of how PBP handles arrays. Probably because I hadn't worked with arrays in PBP until version 2.6 finally supported them.
I now understand what I have to do...it will be simpler to read the data from the EEPROM a byte at a time and insert it into its respective BufferOut(x).

Thanks to both Ioannis and DT for setting me straight on this!

jellis00
- 14th January 2010, 08:03
Also, don't mess with all the INTCON and RCON registers.
DT_INTS handles all those for you.
If you change them, it can interfere with the interrupt system.
<br>
Darrel, I have discovered that when I am using INT2_INT interrupt source from DS1337 to the 18F4550 that I have to have the INTCON2 statement per below code...otherwise the interrupt doesn't work. When you said that I shouldn't mess with the INTCON register settings because DT_INTS takes care of them, did you mean only the GIE setting?? In fact, can you explain which of the INTCON register settings ARE NOT handled by DT_INTS, if more than just this one for INT2 falling edge??



'----------------------[ SETUP FOR INTERRUPTS ]-------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
;INT_Handler USB_Handler
INT_Handler INT2_INT, _Alarm, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT2_INT ; enable external (INT) interrupts
' Per DT, DT_INTS already takes care of setting INTCON and RCON registers
' but this doesn't work unles INTCON2 set per below:
'INTCON.7 = 1 ' Set Global Interrupt Enable bit
INTCON2 = %00000000 ' Set INT2 for falling edge (Bit4-low)
' on RTC's interrupt.
'INTCON3 = %10010000 ' Set INT2 high priority (Bit7-high), enable INT2
' (Bit4-high)

Darrel Taylor
- 14th January 2010, 08:30
Enable bits (IE), Interrupt Flags (IF) or Priority bits (IP).
Don't "mess" with them. That includes GIE and PEIE or GIEL.

Many interrupt sources have registers that affect the specific peripheral.
For instance ...


If you don't set TXSTA and RCSTA then you will never get proper interrupts from the USART.

If you don't set T1CON, you will never get interrupts from TMR1_INT.

And ...
If you don't set the INTEDG bits, you may never get the correct interrupt from INT2_INT.



You have to tell the hardware how to handle the signals.
DT_INTS will handle the interrupts.
<br>

Mark J
- 17th September 2010, 16:26
Hi Guys,

Ive got a bit of a problem with the USB thats got me stumped and hope you can help.

Im using DT's interupts and have setup INT_INT to read a DS18S20+ temp sensor which works fine and I can display it on the LCD lovely.

My problem is that trying to use the USB it works with the interupt for the temp probe ok, but as SOON as I use LCDOUT I get the USB device not recognised :confused:

Even splattering USBSERVICE after all the lines in the main loop it still wont recognise it.

I have tried both ON INTERUPT and DT's TMR0_INT for the USBSERVICE but nothing I do will get it working unless the LCDOUT is removed.

I can post the code if required but thought I would just write the problem first in case its something obvious im missing.

Many thanks,

Mark

Mark J
- 17th September 2010, 18:03
Doh, I suppose I should have looked a bit more deeply on the forum! lol.
I did see this ages ago and it slipped my memory, but found DT's USB_ASM_Service file and tried that and BINGO! sorted it PHEW!

Must say thanks to DT as it seems that whenever I see someone (even myself!) get stuck with something, a quick delve into the forums usually finds a post by Darrel that sorts it!

Mark

sjm2000
- 3rd December 2010, 12:51
Hi,
I am new and this is my first posting, please don't shoot me in case of mistakes.

Today I started to use PicPasic Pro 2.6 with MPLAB IDE 8.60 and tried out the usb_demo.bas sample immediately.

MPLAB file list:
CDC_DEMO.BAS
CDC_DESC.BAS
USB_CDC.ASM
USB_CDC.INC
USB_MEM.ASM
USB_DEV.ASM
USB_DEV.INC


CDC_DEMO.BAS Code:


' USB sample program for PIC18F4550 CDC serial port emulation
' Requires PBP 2.60 or later

' Compilation of this program requires that specific support files be
' available in the source directory. For detailed information, see
' the file PBP\USB18\USB.TXT.

Include "cdc_desc.bas" ' Include the HID descriptors

Define OSC 48

buffer Var Byte[16]
cnt Var Byte


OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10

USBInit ' Get USB going

' Wait for USB input
idleloop:
USBService ' Must service USB regularly
cnt = 16 ' Specify input buffer size
USBIn 3, buffer, cnt, idleloop

' Message received
buffer[0] = "H"
buffer[1] = "e"
buffer[2] = "l"
buffer[3] = "l"
buffer[4] = "o"
buffer[5] = " "
buffer[6] = "W"
buffer[7] = "o"
buffer[8] = "r"
buffer[9] = "l"
buffer[10] = "d"
buffer[11] = 13
buffer[12] = 10
buffer[13] = 0

outloop:
USBService ' Must service USB regularly
USBOut 3, buffer, 14, outloop

Goto idleloop ' Wait for next buffer


The test program in the PC is a simple VB6 routine:


;---------------- Write to PIC --------------------------
Private Sub Out3Byte(bus As Byte, adr As Byte, data As Byte)
Dim Com(2) As Byte
Com(0) = bus: Com(1) = adr: Com(2) = data
'3 byte send
MSComm1.Output = Com
End Sub
;----------------- Receive from PIC ----------------------
Private Sub MSComm1_OnComm()
Dim data As String, ende As Boolean
ende = False: Text1.Text = ""
Static IsActive As Boolean
MSComm1.RThreshold = 0
If IsActive Then
Label4.Caption = "OnComm Ueberschneidung"
Exit Sub
End If
Do Until ende
If MSComm1.InBufferCount > 1 Then 'min 1byte recvd
data = MSComm1.Input
Text1.Text = Text1.Text + Hex$(AscB(data)) + " "
Else
ende = True
End If
DoEvents
Loop
IsActive = False
MSComm1.RThreshold = 1
End Sub


In general it works fine but, for one little but crucial problem I cant find the reason, so I suspect the problem to be with the PBP compilation.

The 3 bytes from the PC are always received properly, but the "Hello World" message arrives in the PC correctly only the first time immediately after Com Port Open statement. When continuously sending and receiving, at the beginning of the messages there is always one garbage byte ahead of "Hello World". The value is always the same, but depends one actual memory location in PIC RAM of "buffer Var Byte[16]"

Can anyone help?

CDC_DEMO_transmission_log:


35 VB6.EXE IOCTL_SERIAL_SET_BAUD_RATE USBSER000 SUCCESS Rate: 115200
36 VB6.EXE IOCTL_SERIAL_CLR_RTS USBSER000 SUCCESS
37 VB6.EXE IOCTL_SERIAL_SET_DTR USBSER000 SUCCESS
38 VB6.EXE IOCTL_SERIAL_SET_LINE_CONTROL USBSER000 SUCCESS StopBits: 1 Parity: NONE WordLength: 8
39 VB6.EXE IOCTL_SERIAL_SET_CHAR USBSER000 SUCCESS EOF:1a ERR:0 BRK:0 EVT:0 XON:11 XOFF:13
40 VB6.EXE IOCTL_SERIAL_SET_HANDFLOW USBSER000 SUCCESS Shake:1 Replace:0 XonLimit:8000 XoffLimit:8000
41 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
42 VB6.EXE IRP_MJ_WRITE USBSER000 SUCCESS Length 3: A1 A9 AF <3 bytes send
43 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
44 VB6.EXE IOCTL_SERIAL_SET_WAIT_MASK USBSER000 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
45 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
46 VB6.EXE IOCTL_SERIAL_WAIT_ON_MASK USBSER000 SUCCESS
47 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
48 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 48 <----- Starts with "H"
49 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
50 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
51 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 65
52 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
53 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
54 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6C
55 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
56 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
57 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6C
58 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
59 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
60 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6F
61 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
62 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
63 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 20
64 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
65 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
66 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 57
67 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
68 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
69 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6F
70 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
71 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
72 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 72
73 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
74 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
75 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6C
76 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
77 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
78 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 64
79 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
80 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
81 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 0D
82 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
83 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
84 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 0A
85 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
86 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
87 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
88 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
89 VB6.EXE IOCTL_SERIAL_GET_PROPERTIES USBSER000 SUCCESS
90 VB6.EXE IRP_MJ_WRITE USBSER000 SUCCESS Length 3: A1 A9 AF <3bytes send
91 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
92 VB6.EXE IOCTL_SERIAL_SET_WAIT_MASK USBSER000 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
93 B6.EXE IOCTL_SERIAL_WAIT_ON_MASK USBSER000 SUCCESS
94 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
95 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
96 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 00 <----- starts with "0x00"
97 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
98 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
99 B6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 48 <----- "H" is 2nd byte
100 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
101 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
102 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 65
103 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
104 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
105 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6C
106 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
107 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
108 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6C
109 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
110 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
111 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6F
112 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
113 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
114 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 20
115 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
116 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
117 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 57
118 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
119 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
120 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6F
121 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
122 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
123 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 72
124 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
125 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
126 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 6C
127 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
128 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
129 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 64
130 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
131 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
132 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 0D
133 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
134 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
135 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 0A
136 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
137 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
138 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
139 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
140 VB6.EXE IOCTL_SERIAL_GET_PROPERTIES USBSER000 SUCCESS
141 VB6.EXE IRP_MJ_WRITE USBSER000 SUCCESS Length 3: A1 A9 AF <3 bytes send
142 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
143 VB6.EXE IOCTL_SERIAL_SET_WAIT_MASK USBSER000 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD BRK ERR RING
144 VB6.EXE IOCTL_SERIAL_WAIT_ON_MASK USBSER000 SUCCESS
145 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
146 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
147 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 00 <garbage again
148 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
149 VB6.EXE IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
150 VB6.EXE IRP_MJ_READ USBSER000 SUCCESS Length 1: 48

sjm2000
- 4th December 2010, 04:18
Hi,

I am still stuck with my proplem, therefore, I modified the cdc_demo.bas to be able to change the outbuffer contents:


' USB sample program for PIC18F4550 CDC serial port emulation
' Requires PBP 2.60 or later

' Compilation of this program requires that specific support files be
' available in the source directory. For detailed information, see
' the file PBP\USB18\USB.TXT.

Include "cdc_desc.bas" ' Include the HID descriptors

Define OSC 48

inbuffer Var Byte[15]
outbuffer Var Byte[15]
icnt Var Byte
ocnt Var Byte

OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10

USBInit ' Get USB going

' Wait for USB input
idleloop:

icnt = 6 ' Specify input buffer size
USBService ' Must service USB regularly
USBIn 3, inbuffer, icnt, idleloop

' Message received
outbuffer[0] = inbuffer[0]
outbuffer[1] = inbuffer[1]
outbuffer[2] = inbuffer[2]
outbuffer[3] = inbuffer[3]
outbuffer[4] = 0
outbuffer[5] = icnt
outbuffer[6] = 0
outbuffer[7] = $AA
outbuffer[8] = $BB
outbuffer[9] = $CC
outbuffer[10] = $DD
outbuffer[11] = 0
outbuffer[12] = inbuffer[0]
outbuffer[13] = inbuffer[1]
outbuffer[14] = inbuffer[2]

outloop:
USBService ' Must service USB regularly
ocnt = 14
USBOut 3, outbuffer, ocnt, outloop

Goto idleloop ' Wait for next buffer


I continued testing and found out:

With ocnt = 14

The first USBOut after com port open in PC test program is actually

outbuffer[0]....outbuffer[12] -> in total 13 bytes

from the second output it is always the same

outbuffer[13], outbuffer[0], outbuffer[1]...., outbuffer[12] ->in total 14 bytes


I suspect in the appended .inc and .asm files might be a definition mistake, but since I do not understand the code written there, I really need the help of an USB specialist in this Forum to overcome this problem.

To all the USB experts in this Forum, please Help.

ScaleRobotics
- 13th January 2011, 11:40
This is a update to Mister E's VB6 demo program, and firmware that uses Darrel's DT_HID260.pbp include file. It brings back some of the functions that went away with the HID update, and it adds a few more. It now transfers 10 bit A/D conversions to the PC, and it has a really low bandwidth mschart function. It also transfers the port info up to the computer in a single byte, and it's read by VB in bits. (It is hard to read bits with VB!) Ports are changed to match the Olimex PIC-USB-STK ( http://www.olimex.com/dev/pic-usb-stk.html ) . On the chart, it's a little over a second from left to right. By the way, if anyone knows how to keep the mschart from flickering as it is being redrawn, please let me know.

5077
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=5077&d=1294914054

VB6 doesn't make it very easy to be sure you have include all the necessary files, so if you have issues, let me know. The code was made for a PIC18F4550 with a 20 mhz crystal. You will also need Darrel's DT_HID260 file from here: http://www.picbasic.co.uk/forum/showthread.php?t=5418&p=80434#post80434

(Thanks Steve and Darrel for giving me the USB bug!)



'************************************************* ***************************
'* Name : USB_Demo_4_HID.pbp *
'* Author : Walter Dunckel ScaleRobotics using Darrels example as template*
'* Notice : Copyright (c) 2011 *
'* Date : 1/13/2011 *
'* Version : 1.1 *
'* Notes : Added Darrel's text example *
'* : *
'************************************************* ***************************
;--- if you un-comment these, you must comment the ones in the .inc file ---
ASM ; 18F2550/4550, 20mhz crystal
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM
'add if using Microchip's HID Bootloader
'DEFINE LOADER_USED 1
'DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader

;ASM ; 18F13K50/14K50 Only 12mhz crystal can be used for USB
; __CONFIG _CONFIG1L, _CPUDIV_NOCLKDIV_1L & _USBDIV_OFF_1L
; __CONFIG _CONFIG1H, _FOSC_HS_1H & _PLLEN_ON_1H & _PCLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
;
; ;added
; __CONFIG _CONFIG2H, _WDTEN_ON_2H & _WDTPS_512_2H
; __CONFIG _CONFIG3H, _MCLRE_ON_3H
; __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_OFF_4L & _XINST_OFF_4L
;ENDASM

DEFINE OSC 48
clear

PortA = %00000000
TrisA = %00000001
PortB = %00000000
TrisB = %11110100 'make pushbuttons inputs for PIC-USB-STK
'TrisB = %00010000 'for 18k50
PortC = %00000000
TrisC = %00000000
TrisD = %00000000
CMCON = 7
'CM1CON0 = 7 'for 18f14k50
'CM2CON0 = 7

' CCP/PWM
' -------
CCP1CON = %00001100 ' CCP1, PWM mode
CCP2CON = %00001100 ' CCP2, PWM mode
PR2 = 249 ' 12khz PWM Freq
T2CON = %00000101 ' TMR2 on, prescaler 1:4
;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
endm
INT_CREATE ; Creates the interrupt processor
endasm

;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"

DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "ScaleRobotics"
DEFINE USB_PRODUCTNAME "Cheap-Scope"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 8 ;was 32 IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 16 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

; --- Each USB LED is optional, comment them if not used ----
DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
'DEFINE USB_PLUGGEDLED PORTD,0 ; LED indicates if USB is connected
'DEFINE USB_TXLED PORTD,2 ; " " data being sent to PC
'DEFINE USB_RXLED PORTD,1 ; " " data being received from PC

OutCount VAR WORD : OutCount = 0
Value VAR word 'analog result from AN0
Value2 var word 'analog result from AN11
X VAR WORD
counter var byte
Duty1 var word EXT ' make them available
Duty2 var byte EXT
smallvalue var byte

;--- Setup ADC -------------------------------------------------------------
DEFINE ADC_BITS 10 ; Number of bits in ADCIN result
ADCON2.7 = 1 ; right justify (Change this if ADFM in diff register)
'ANSEL = %00000000 'for 18f14k50
'ANSELH = %00000100 'for 18f14k50
ADCON0 = %00000001 ' turn on a/d AN0

;--- The Main Loop ---------------------------------------------------------
pause 2000 'wait for connection
ARRAYWRITE USBTXBuffer, ["USB Demo"] 'show text example
GOSUB WaitToSend

Main:
FOR X = 0 to 2 ; Check for incomming USB data while pausing
@ ON_USBRX_GOSUB _HandleRX
PAUSE 1
NEXT X
ADCin 8, value2
@Duty1=_USBRXBuffer+1
@Duty2=_USBRXBuffer+3
counter = counter +1
ADCIN 0, Value
ARRAYWRITE USBTXBuffer,[portb,counter,value.highbyte,value.lowbyte,Value2. highbyte,Value2.lowbyte,0,0]
CCP1CON.5=DUTY1.1 ' load CCP1 duty value
CCP1CON.4=DUTY1.0 ' with Duty1
CCPR1L=DUTY1>>2
CCP2CON.5=DUTY2.1 ' load CCP2 duty value
CCP2CON.4=DUTY2.0 ' with Duty1
CCPR2L=DUTY2>>2
portd = usbrxbuffer[0]
'IF Plugged THEN GOSUB DoUSBOut ; only send when USB is connected
gosub SendIfReady
GOTO Main

;---- This just sends the received packet back to the PC -------------------
HandleRX:
ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
return

SendIfReady:
IF Plugged AND TX_READY THEN DoUSBOut
RETURN

WaitToSend:
WHILE Plugged and !TX_READY : WEND
IF TX_READY THEN GOSUB DoUSBOut
RETURN


Edit:
Ok, now looking at Darrel's post 221 http://www.picbasic.co.uk/forum/showthread.php?t=5418&p=80611#post80611 , he already made the program compatible with most of the original functions for the 18F4550. So I (also) lifted his code to transfer text to the PC. However, I only do this at power up, so I don't slow the analog transfers down.

pedja089
- 13th January 2011, 13:51
FormMain.frm is missing...

ScaleRobotics
- 13th January 2011, 17:38
FormMain.frm is missing...

Thanks pedja089, I just added it.

pedja089
- 13th January 2011, 18:56
Excellent project!
Not too complicated, but there are interesting examples of communication and usage of DT's include files.
Perhaps you should add the LCD.
Here is my example how to sendtext from winamp to lcd:
http://www.elektronika.ba/506/lcd-winamp-plugin-on-usb/
I hope that you will manage the translation...

mister_e
- 13th January 2011, 22:02
5 years later and this thread always evolve and got some more user in the "USB freaks" loops. Glad to see that. Congrats to all!

Now I wish I have time to revamp it and share some part of what i've done for .NET (C# & VB) ...VB6 being a dead duck for ages now... and the .dll not that suitable now (but still workable) and then on the top of it, new PBP version ;)

Helm PCB (Amr Bekhit) did a good work on my first .NET version though http://helmpcb.com/?p=166

jmgelba
- 8th February 2011, 23:15
Reading through this it looks like there was a sample of code were the 18F2550 was using an external resonator at 20mhz using the HS fuse. Looking at the datasheet, this would only enable low speed USB, right?

Darrel Taylor
- 9th February 2011, 02:54
With those chips ... you can get Full Speed with any crystal that's a multiple of 4Mhz (up to 24Mhz).
And the processor can run at 48Mhz too.

They have a really nice Oscillator/PLL.
Adjusting the Configuration bits is a little tricky though.