Has anybody worked with these PICs:
18F2455, 18F4455, 18F2550, 18F4550
and EaysHID yet?
Do you have any experience (or code) to share?
I have received my ICD2 today and started playing with a 18F4550.
(PICSTART+ doesn't suport the 18F4550!)
Has anybody worked with these PICs:
18F2455, 18F4455, 18F2550, 18F4550
and EaysHID yet?
Do you have any experience (or code) to share?
I have received my ICD2 today and started playing with a 18F4550.
(PICSTART+ doesn't suport the 18F4550!)
Last edited by NavMicroSystems; - 29th June 2005 at 16:18.
regards
Ralph
_______________________________________________
There are only 10 types of people:
Those who understand binary, and those who don't ...
_______________________________________________
I've used it, and if you're looking to get started with USB, then Dave's new
EasyHID & the PIC18F4550 are definitely the way to go.
Download & install EasyHID.
http://www.mecanique.co.uk/products/usb/easyhid.html
I have several projects for USB coming shortly, but in the mean time, I've
loaded the files for a complete USB project on our website.
The zip file contains PBP source code for a PIC18F4550, and VB source for a
USB analog data-logger. Should be fun for anyone interested in tinkering with
EasyHID and the new full-speed 18F USB parts.
Here are the files: http://www.rentron.com/mcstudio/EasyHIDPrj.zip
You'll need VB6 & SoftWire. You can download SoftWire from here. It's free.
http://www.softwire.com/swdownload/softwiredownload.htm
I used the activx controls in SoftWire for the analog meter interface. Really
nice stuff.
You'll also need PBP version 2.46 since this is the version offering support for
the newer 18F USB parts.
If anyone's looking for an excellent book on USB, then grab a copy of Jan
Axelson's new 3rd edition of USB Complete. We just got them in. I spent the
last few days reading mine, and it's awesome.
Jan has done an outstanding job on her 3rd edition of this book. Even "I" can
understand it now...;o]
I'm also in the middle of trying to use EasyHID. I'm just not sure where the USB18.ASM file fits in the grand scheme of things.
I used the PIC18F4550, PBP and VB. The file is in the project PBP folder.
I also got USB Complete as well as USB Design By Example. It's too bad they chose to use EZ-USB chips from Cypress or else I could have used their examples directly. Unfortunately I don't know enough about MPASM Assembler, let alone Cypress' version to convert things around.
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Is it complicated to get the generated code to be compatible with the slower USB speed? I'd like to be able to connect to PCs that do not yet have USB 2.0.
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Bruce,
I get a LOT more files generated on the PIC side?
It's that large Assembler file with all the VERY important USB routines that I don't know where that fits in. It doesn't seem to be linked with the PBP base program at all, or I missed something?
Robert
?
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Bruce,
Don't forget to add a README that mentions mcHID.dll and where the user can get it. Your PC-side code won't work without it.
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Hi Robert,
You should have 8 (PBP) files total generated by EasyHID. All this stuff is required, and included when you compile for the 18F USB part.
Look in your PBP\USB18 directory for USB.TXT. This explains what most of
the files are.
Thanks Bruce, that's the only place I hadn't looked for help.
"The header file for the device, the files USB18.ASM, USB18MEM.ASM, USB18.INC, USBDESC.ASM and the project descriptor file, as well as any desired sample programs, should be copied to the project source subdirectory before being used."
Ok, so we just have those files sitting there when we compile and the compiler takes care of everything, cool!
"For low-speed USB operation, the main changes are to set the system clock postscaler to divide by 4 and change the define for UCFG_VAL in the descriptor file for the project. The sample project descriptor files show settings of UCFG_VAL for both full-speed and low-speed. With these settings, for full-speed, the PIC core runs at 48MHz. For low-speed, the PIC core runs at 24MHz."
Ok, I haven't checked the details, but at least it's possible to adjust for low-speed USB, excellent!
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
This is a very interesting thread. I am especially interested in the data logger. I was thinking about putting together a PIC based scope project. Something that could clip onto a few pins and display the waveforms on a PC screen. Your project looks very interesting. Any special hardware being used? How to you hookup the inputs without fear of over voltage?
Do you get 0 to 5 volts readings or more like .7v to 4.xx readings?
hmm, softwire seems to be vb.net only.
I do not see vb6 support. Any chance you are using an older version of softwire?
I downloaded VB Express, it's free without any strings attached.
"How to you hookup the inputs without fear of over voltage?"
How to process the signals MCU-side, beats me. I'd do a search on comparing voltage, I've seen lots of stuff on that.
Just don't even consider feeding that through the USB line. Even a PIC has limitations, I would place some sort of step-down circuit before the PIC. Google is your friend.
Robert
Last edited by Demon; - 9th July 2005 at 17:08.
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Suppose to be available.. look hereOriginally Posted by mbramwel
Well as you want to build a kind of scope, it could be interesting that your input also provide an high impedance. So use a simple OP AMP buffer would do the trick IMHO.Originally Posted by mbramwel
But if don't need any buffer, a simple resistor between PIC and Unit wil do the job. Look at the datasheet, most PIC have two diode as 'Over/Under voltage protection...
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Thanks for the 'old' link for 3.1
The regular download button was only showing the newer VB.net version. I do have VB.net because of our University site license (less than $5 per copy) but have a hard time loading up gigabytes of compiler for what should be simple apps. Maybe I should byte the bullet and move up from vb6.
At least I can now try running the app posted earlier in this thread.
I'll read the datasheet for the pic chip. My concern was due to many sites saying never exceed the supply voltage on an input pin.
The scope project would be for hobby based projects. The PIC would monitor a few pins and transmit the data via USB to the PC. The PC would graph the result. If anything already exists that has source and is free, I would check it out. I do not mind starting from scratch. I do not copywrit anything I write, it would be for public consumption.
I've just started on this, having been encouraged by EasyHID.
I noticed that the interrupt check box is disabled if PBP is the device code genrator selected. Does this mean that PBP programs have to jump to service the USB every 10ms? That's surely not very practical.
Do ME Labs have a fix in the pipeline for this or do I feel an upgrade to my neglected Proton+ coming on?
I can't see me investing the time in making USB work with PBP if the USB connection cannot be maintained in the background.
Any advice greatly welcomed.
Brian Walsh
Glasgow
Scotland
I haven't started on the USB aspect yet, but offhand I would say that's the function of the "USBservice" command.
An easy way to manage this? I have absolutely no idea yet.
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Please somebody shoot me if i'm wrong, didn't find time to play enough with USB, BUT none of both compiler will do the refresh for you.. sorry. Timer interrupt one of the way to go or keep track of your code and sprinkle few USBSERVICE. No big deal
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Originally Posted by NavMicroSystems
You have try this circuit from this project
http://www.sixca.com/eng/articles/usbdaq.php
Hi,
I've built the simple piece of hardware using the 18F2550, it has been programmed as per the files generated by the EasyHID application.
Having plugged the hardware into the USB port, it states the device is not recognised. I was expecting it to come up with the device name as i stated in the EasyHID compilation.
I was expecting a .ini file or similar to be generated for the installation of the device.
Can anyone help why this might be.
Many thanks.
OK, seem to have that issue sorted now, it actually was something to do with the programming fuses.
Although it now connects OK, when i look at the device manager, it only shows up as a 'USB Human Interface Device' and HID-Compliant Device' and not as i set in the EasyHID maker.
Also, can anyone help with what is required at the VB and PIC end to light a simple LED. ie when i click a 'button' in the VB code, it turns an LED on one of the ports, ie PORTB.1.
Many thanks,
Steve
Can anybody help with the above request or point me in a direction of who / where might?
Many thanks,
Steve
Hi Steve,
If you have the PIC being recognized as an HID device, try this. It's real simple, but will allow you to control an LED from VB6 (should also work with VB5) but I don't have that to test it with.
Create your VB code with EasyHID. Open the project, and drop two command buttons on your form. Add this code for your buttons --
Private Sub Command1_Click()
BufferOut(8) = 0 ' LED on
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Private Sub Command2_Click()
BufferOut(8) = 1 ' LED off
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
Modify the PBP code created by EasyHID something like this --
PORTB = 0
TRISB = 0
usbinit ' initialise USB...
ProgramStart:
gosub DoUSBIn
PORTB = USBBuffer[7]
goto ProgramStart
Note this doesn't send data, it's just a sit & spin simple app reading USB input, and placing the value received in USBBuffer(7) on RB.
Bruce, thanks ever so much for taking the time to reply and for starting me in the right direction. Indeed i now have VB talking to the PIC over USB.
Do you have any knowledge of the EasyHID application? Having used EasyHID to set the base code etc, when i look at the device manager, it only shows up as a 'USB Human Interface Device' and 'HID-Compliant Device' and not as i set in the EasyHID maker, such as 'USB LED Controller'.
I was expecting an .inf file or similar to be compiled. Is this something that needs to be done manually? It would be a nice touch to have that when i plug in the device, in the task bar, the name of this device is displayed like any other USB device when connected.
Thanks again for you kind help,
Steve Tisseyre
Hi Steve,
The information you enter when creating USB framework files with EasyHID is just for the embedded side with a very handy .dll that handles host to function communications.
EasyHID just gives you the USB framework. As far as I know, it does not create a Windows .inf file. That's up to you to create.
If you don't have your own .inf file or HID driver, then Windows will install its own HID drivers, and your new USB gadget is just going to show up with the default Windows name in Device Manager like 'USB Human Interface Device' and 'HID-Compliant Device'.
If you're running XP, look in the Windows input.inf file, and you'll see why. It tries to match the descriptors, VID, PID with existing "certified" manufacturers & hardware. If your new USB gadget isn't in the list, Windows uses the default HID compliant description with generic HID drivers.
Download the Microchip USB framework and take a look at how they setup the .inf & driver files. That will help you understand what's required.
If you plan on making a USB enabled "product", then you might also want to grab a copy of Jan Axelson's USB Complete 3rd edition. It's worth every penny, and gives you details on how to get your USB product/manufacturer name to show up in Windows Device Manager.
EasyHID will get you started, (and really quick I might add), but there's still a lot left to the end user to figure out.
Hats off to Dave at Mecanique for putting in the HUGE amount of time & study required just to give everyone that nifty "free" utility.
Hi Bruce,
I have now ordered the book as you recommended, i'm sure it will come in very handy.
I have figured out that if you use EasyHID to set the maximum Buffer size to 32, then you can increase the amount of outputs on the PIC that you can set HIGH or LOW. ie the PIC side is odd numbers 1 - 31 and the VB side is even numbers 2 - 32.
ie on the PIC side requires:
PORTC.1 = USBBuffer[23]
where as on the VB side requires:
BufferOut(24) = 1 ' LED on
If i want to use all of PORTA and PORTB, is there an easy way of listing these in the two codes, or do they have to be done seperately? ie:
PIC
PORTA.1 = USBBuffer[1]
PORTA.2 = USBBuffer[3]
PORTA.3 = USBBuffer[5]
PORTA.4 = USBBuffer[7]
PORTA.5 = USBBuffer[9]
VB
BufferOut(2) = 1 ' LED on
BufferOut(4) = 1 ' LED on
BufferOut(6) = 1 ' LED on
BufferOut(8) = 1 ' LED on
BufferOut(10) = 1 ' LED on
Moving on from the switching of outputs HIGH or LOW, how would one send say text from the PIC to a text box in VB. For example, on the PIC, if a certain routine is executed, it sends a command to the VB application which is then displayed in a text window. Or is this getting too advanced for a quick explanation??
Thanks again for you assistance,
Steve
Hello. I don't know what happend but my EasyHID only create 4 files:
DESCUSBProject.asm
USBDESC.asm
USBProject.asm
USBProject.pbp
What i doing wrong? why it don't creat the other files like the USB18.c
Thanks for yours help!!!
Please if somebody have any example send it to me at: [email protected]
Thanks!
andresnavas,
I have sent the reply straight to your personal email address. It would appear that the files aren't generating properly. All i can suggest is check the compilation settings again. If that doesn't work, try installing the application again.
I certainly haven't had any problems like that.
Within the directory you specified in the project settings (default is C:\Program Files\Mecanique\EasyHID\) should see another directory as per your title, such as USBProject. Within that directory is 2 sub directories, one for the VB or C code and one for the Proton or PICBasic code.
I have sent you a zip file containing what you should expect to see for a default VB and PICBasic code using the PIC18F4550 also with all the default settings.
Hope this helps,
Steve
Hi all,
Absolutely brilliant thread, a lot of quality info and best of all can be done fast, cheers to all those involved. I am really new to this interfacing stuff, so if I'm asking too much or the newbie stink is unbearable, feel free to tell me to sling my hook.
I was wondering how one would go about changing the HID code provided by Easy HID USB code generator to simply read in up to three pulse width inputs (as far as I know the digital ins on the 18f2455 support this) and up to three analog ins through on board adc (ideally varying between -3 to +3v) simultaneously and as fast as possible, in fact how many samples per second is possible using the HID approach? Sin e.
I would greatly appreciate any help with this/direction to where help should be sought.
Thanks in advanced
Judy
Steve,
You're dealing with bytes. PORTA.1 = USBBuffer[1] isn't the way to go since you can't place a byte value on a single port "bit".
Just place the byte you need on the whole port. You can send a single byte value from the PC app, and simply place it on the port.
I.E. PORTA = USBBuffer[1] should work fine - assuming that's the byte element you want.
Sending data from the PIC to PC is equally simple. Here's one example. Note this isn't everything. Just the sections I added to the framework file created with EasyHID.
On the PC side, modify the USB framework file created with EasyHID something like this;Code:DEFINE OSC 48 DEFINE LOADER_USED 1 DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source /32 DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS DEFINE RESET_ORG 800h ' <-- I used the Microchip USB loader BufferSize con 8 DataBuffer Var Byte(BufferSize) ' data buffer DataBufferCount Var Byte ' buffer size Quanta con 1251 TRISD = 0 PORTD = 0 ' Variables X VAR byte Adval VAR WORD TRISA.0 = 1 ' RA0 input ADCON1 = %00001110 ' A/D channel 0 ADCON2 = %10000011 ' Right justify for 10-bit USBInit Main: GOSUB DoUSBIn PORTD = DataBuffer[7] ADCIN 0,adval ' Read A/D channel 0 into ADval variable ADval = ADval */ Quanta ' Quanta result ' Load data buffer DataBuffer(0) = Adval DIG 3 DataBuffer(1) = "." DataBuffer(2) = Adval DIG 2 DataBuffer(3) = Adval DIG 1 DataBuffer(4) = Adval DIG 0 GOSUB DoUSBOut FOR X = 0 to 99 ' Short delay between updates PAUSEUS 1000 USBSERVICE ' Maintain HID connection during delay period NEXT X GOTO Main
Dim MyText As String ' create your string storage space
In the OnRead sub-routine;
MyText = (CStr(BufferIn(1)) + Chr$(BufferIn(2)) + CStr(BufferIn(3)) + CStr(BufferIn(4)) + CStr(BufferIn(5)) + "V")
Label1.Caption = MyText ' Place string text into label displaying A/D value
Judy,
Reading three pulse widths or A/D values doesn't really have anything to do with USB. The USB PIC is just another PIC with the addition of the USB module. Using the onboard A/D is pretty much the same as any other PIC.
All you need here is the datasheet, and a little time to experiment getting your pulse measurement & A/D routines working. Sending this all to the PC via the USB module is no more than stuffing your values into the outgoing buffer like in the previous example.
Just be sure to keep the USB connection alive by avoiding the use of blocking functions, long delays, etc,,. It's really not that hard, but you will need to experiment a tad.
Bruce,
Would you mind posting all of your ADC code, i am getting errors. I've had a look, but can't figure it out.
The code posted above seems to be missing the DoUSBIn and DoUSBOut subroutines.
I also get an error on the DataBuffer(1) = "."
I want to use it as a 5v voltage monitor passing the results to Vb.
Many thanks,
Steve
Hi Steve,
Sure. Here's the complete file. Just be sure you've used EasyHID to generate the required USB support files.
Here's the PIC & VB source for a USB A/D datalogger http://www.rentron.com/mcstudio/USB_AD.zipCode:DEFINE LOADER_USED 1 DEFINE OSC 48 DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source /32 DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS DEFINE RESET_ORG 800h ' For Microchip USB loader BufferSize con 8 DataBuffer Var Byte(BufferSize) ' data buffer DataBufferCount Var Byte ' buffer size Quanta con 1251 TRISD = 0 PORTD = 0 ' Variables X VAR byte Adval VAR WORD TRISA.0 = 1 ' RA0 input ADCON1 = %00001110 ' A/D channel 0 ADCON2 = %10000011 ' Right justify for 10-bit USBInit Main: GOSUB DoUSBIn PORTD = DataBuffer[7] ADCIN 0,Adval ' Read A/D channel 0 into ADval variable ADval = ADval */ Quanta ' Quanta result ' Load data buffer DataBuffer(0) = Adval dig 3 DataBuffer(1) = "." DataBuffer(2) = Adval DIG 2 DataBuffer(3) = Adval DIG 1 DataBuffer(4) = Adval DIG 0 GOSUB DoUSBOut FOR X = 0 to 99 ' Short delay between updates PAUSEUS 1000 USBSERVICE ' Maintain HID connection during delay period NEXT X GOTO Main ' USB in... DoUSBIn: DataBufferCount = BufferSize USBService USBIn 1, DataBuffer, DataBufferCount, DoUSBIn RETURN ' USB out... DoUSBOut: DataBufferCount = BufferSize USBService USBOut 1, DataBuffer, DataBufferCount, DoUSBOut RETURN END
Great, thanks Bruce. Unfortuanatly i am still getting a big 0 in VB. I'm sure its only something small i am doing wrong (hopefully) !!
Here is the code, can you spot anything obvious that i have done wrong?
Its a PIC18F2455 where i am putting 5v onto RA0.
In VB, i have placed a label on the form and this is in the read event sectionCode:DEFINE LOADER_USED 1 DEFINE OSC 48 DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source /32 DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS 'DEFINE RESET_ORG 800h ' For Microchip USB loader BufferSize con 8 DataBuffer Var Byte(BufferSize) ' data buffer DataBufferCount Var Byte ' buffer size Quanta con 1251 ' Variables X VAR byte Adval VAR WORD TRISA.0 = 1 ' RA0 input ADCON1 = %00001110 ' A/D channel 0 ADCON2 = %10000011 ' Right justify for 10-bit USBInit Main: GOSUB DoUSBIn PORTB = DataBuffer[7] ADCIN 0,Adval ' Read A/D channel 0 into ADval variable ADval = ADval */ Quanta ' Quanta result ' Load data buffer DataBuffer(0) = Adval dig 3 DataBuffer(1) = "." DataBuffer(2) = Adval DIG 2 DataBuffer(3) = Adval DIG 1 DataBuffer(4) = Adval DIG 0 GOSUB DoUSBOut FOR X = 0 to 99 ' Short delay between updates PAUSEUS 1000 USBSERVICE ' Maintain HID connection during delay period NEXT X GOTO Main ' ************************************************************ ' * receive data from the USB bus * ' ************************************************************ DoUSBIn: DataBufferCount = BufferSize USBService USBIn 1, DataBuffer, DataBufferCount, DoUSBIn RETURN ' ************************************************************ ' * wait for USB interface to attach * ' ************************************************************ DoUSBOut: DataBufferCount = BufferSize USBService USBOut 1, DataBuffer, DataBufferCount, DoUSBOut RETURN END
Code:'***************************************************************** ' on read event... '***************************************************************** Public Sub OnRead(ByVal pHandle As Long) ' read the data (don't forget, pass the whole array)... If hidRead(pHandle, BufferIn(0)) Then MyText = (CStr(BufferIn(1)) + Chr$(BufferIn(2)) + CStr(BufferIn(3)) + CStr(BufferIn(4)) + CStr(BufferIn(5)) + "V") Label1.Caption = MyText ' Place string text into label displaying A/D value ' ** YOUR CODE HERE ** ' first byte is the report ID, e.g. BufferIn(0) ' the other bytes are the data from the microcontrolller... End If End Sub
Many thanks again.
Steve
Private Const VendorID = 6017
Private Const ProductID = 2000
Check to make sure the vendor & product ID numbers in your VB source match the vendor/product ID #'s in the PIC framework files generated by EasyHID. If these don't match, the VB app will never respond.
Although i have changed the ProductID from 2000 to 2005, the device is recognised.
The VB program displays a text box which says USB Device Connected or indeed Disconnected, depending on its status.
So, i think this bit is OK.
Steve
What exactly is happening? Are you getting nothing on the label caption? Have you verified your hardware with something simple like reading the A/D input, and displaying the result on an LCD, serial terminal, etc?
Basically i'm putting 5v on the PORTA.0 pin and just gettin 'label1' in the label of VB.
Should VB always be updating and looking at the USBinput or should there be a READ button thats calls the procedure?
Also on the VB side it has:
Most of it contains CStr but the bit thats contains Chr$, i presume thats for the "." as sent from the PIC.Code:MyText = (CStr(BufferIn(1)) + Chr$(BufferIn(2)) + CStr(BufferIn(3)) + CStr(BufferIn(4)) + CStr(BufferIn(5)) + "V")
I've tried playing around with it, but still no joy. If you have it, is it worth sending me the vb source file you have just for this bit?
Are you on messenger, i am, i thought it might be easier to converse?
Thanks again,
Steve
I'll be happy to send you the working source for one example. Email me directly at tech@rentron
Hi Bruce, do you have a link? I did a search on the Microchip site for <Microchip USB framework> and couldn't find a download.Originally Posted by Bruce
(I'm assuming this is some sort of compile utility that will help Windows XP make a link between the USB device and our EasyHID-generated VB code.)
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Hi Robert,
The Microchip USB framework files are C18 code for the USB PIC. Look under Development Tools for PIC Demo Boards. Go to the page for the full speed USB board. All files & app notes can be downloaded from that page.
When you run the setup program for the PIC USB demo board it installs the framework files. You'll want to grab all the associated app notes on the same page, and USB loader if you plan on using that.
With PBP v2.46 you use DEFINE RESET_ORG 800h to force user code to start at the proper location when using the Microchip USB loader.
Is the USB loader so you can bootload the PIC over USB with a new firmware?
Yes. It's the same USB boot-loader provided with the Microchip full speed PIC USB demo board.
Bookmarks