Pic 18f Usb


Closed Thread
Results 1 to 40 of 135

Thread: Pic 18f Usb

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    andresnavas's Avatar
    andresnavas Guest


    Did you find this post helpful? Yes | No

    Unhappy EasyHID Files

    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!

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    judy's Avatar
    judy Guest


    Did you find this post helpful? Yes | No

    Smile Newbie

    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

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    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
    On the PC side, modify the USB framework file created with EasyHID something like this;
    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce
    ...
    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.
    ...
    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.

    (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!

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Is the USB loader so you can bootload the PIC over USB with a new firmware?

  11. #11
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Yes. It's the same USB boot-loader provided with the Microchip full speed PIC USB demo board.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Tissy
    Is the USB loader so you can bootload the PIC over USB with a new firmware?
    Quote Originally Posted by Bruce
    Yes. It's the same USB boot-loader provided with the Microchip full speed PIC USB demo board.
    I wasn't planning on using In Circuit Serial Programming at first, but if we can include a user-friendly firmware upgrade feature then that changes everything.

    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!

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Ok, this is strange. I've downloaded the files from Microchip:
    http://www.microchip.com/stellent/id...&part=DM163025

    And these 3 files all install the same thing; MICROCHIP USB FRAMEWORK SOFTWARE:
    - USB_Bootloader_Setup.EXE
    - MCHPFSUSB_Setup
    - HID_Setup.EXE

    Do I have some sort of cookie problem going on? I've had something similar once with an old unzip program and was wondering if I was seeing straight.

    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!

  14. #14
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    OK. I haven't got the USB Demo board, i just use the 18F2550 and 18F4550.

    I will have to look at this, because the device i am designing is a USB device. So it would be good to be able to flash it for an upgrade using this facility over USB without worrying about other IcSP connections etc.

  15. #15


    Did you find this post helpful? Yes | No

    Unhappy helpme please...

    Hi Everybody...

    there is a schematic for Bruce's example...?

    Sorry but my english is not good....!

    Regards...!

    GIO
    Greetings from ECUADOR...!!!

  16. #16


    Did you find this post helpful? Yes | No

    Default

    Hi:

    Can anybody helpme whit a elemental example....? Im usin EasyHID, PIC 18F4550, VB and PBP... thanx.

    Lamento no poderme expresar bien en ingles, pero para alguien que me entienda, le estaria agradecido si me pudiera guiar con un ejemplo sencillo para un PIC 18F4550 con PBP VB y easyHID...

    Gracias...!
    Greetings from ECUADOR...!!!

  17. #17
    Join Date
    Jul 2005
    Posts
    93


    Did you find this post helpful? Yes | No

    Default Syntax error compiling code with ADCON1 & ADCON2

    Hi i've recently begun experimenting with the 18F4550 i've got a working example program that lets me flash an led connected to PORTB.7, I use VB6 on the PC side.

    Basically my project has been halted by an unexpected problem in compiling some code added to work the A/D. Both Bruce's USB_AD.zip example and my own code cannot compile this:

    ADCON1 = %00001110 ' A/D channel 0
    ADCON2 = %10000011 ' Left justify for 10-bit

    I get a syntax error.... any ideas - full code posted below.

    I'm running version 2.2.1.1 of microcode studio. I'm using the new beta program for the EPIC parallel programmer (with the 40 pin adapter)



    DEFINE OSC 20
    DEFINE LOADER_USED 1
    'ADC defines
    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
    Quanta con 1251
    Adval VAR WORD

    USBBufferSizeMax con 64 ' maximum buffer size
    USBBufferSizeTX con 64 ' input
    USBBufferSizeRX con 64 ' output

    ' the USB buffer...
    USBBuffer Var Byte[USBBufferSizeMax]
    USBBufferCount Var Byte
    x VAR BYTE


    TRISA.0 = 1 ' RA0 input

    ADCON1 = %00001110 ' A/D channel 0
    ADCON2 = %10000011 ' Left justify for 10-bit

    usbinit ' initialise USB...
    x = 0
    LOW PORTB
    BlinkLED:
    if x = 7 then ProgramStart
    x = x + 1
    HIGH PORTB.7
    PAUSE 1000
    LOW PORTB.7
    PAUSE 500
    goto blinkLED
    ProgramStart:
    x = 0
    gosub DoUSBIn
    gosub DoUSBOut
    goto ProgramStart

    ' ************************************************** **********
    ' * receive data from the USB bus *
    ' ************************************************** **********
    DoUSBIn:
    USBBufferCount = USBBufferSizeRX ' RX buffer size
    USBService ' keep connection alive
    USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available
    if usbbuffer[2] = 1 then
    high portb.7
    ENDIF
    IF USBbuffer[2] = 0 THEN
    LOW portb.7
    ENDIF
    goto DoAD
    return
    DoAD:
    ADCIN 0,adval ' Read A/D channel 0 into ADval variable
    ADval = ADval */ Quanta ' Quanta result

    ' Load data buffer
    USBBuffer[0] = Adval dig 3 'Y.LowByte
    USBBuffer[1] = "."
    USBBuffer[2] = Adval DIG 2
    USBBuffer[3] = Adval DIG 1
    USBBuffer[4] = aDVAL DIG 0
    RETURN
    ' ************************************************** **********
    ' * wait for USB interface to attach *
    ' ************************************************** **********
    DoUSBOut:
    USBBufferCount = USBBufferSizeTX ' TX buffer size
    USBService ' keep connection alive
    USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
    return

  18. #18
    Join Date
    Sep 2006
    Location
    Mexico
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    Hello Rytech, your code is ok, i tried to compile it and it works. Probably you need a newer version of pbp or microcode studio.
    Last edited by Raflex; - 10th June 2007 at 01:03.

  19. #19
    Join Date
    Jul 2007
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    I am trying to link my PC to my experimental board with PIC18F4550.
    I am using EasyHID (mcHID.dll in delphi - for PC, and PROTON IDE for firmware from PIC) but the speed transfer of data from PC to PIC is very slow - about 64KB/sec.
    I need more speed - I need over 240KB / sec. How can I make this data transfer to be fasterthan now?

    Thank you

  20. #20
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    This forum is for PBP not PROTON.

    The PROTON forum can be found here http://www.picbasic.org/forum/
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. Reading a slave USB with a pic
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th October 2008, 12:00
  3. Replies: 15
    Last Post: - 30th October 2007, 19:25
  4. USB communication with pic
    By Shamir in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th August 2006, 23:43
  5. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts