• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18 and USB

Mity Eltu

Member
I am having trouble with the pic18 simulator demo program. I copied the program exactly as it appears on the website (reposted below), but when I try to compile it I get the error "Support for USB implementation not enabled". I don't understand this error. The simulator is set to use 18F4550 with 20MHz clock. If I read the config words right, it looks to me like the USB hardware is enabled. Can anyone tell me what I need to do to get this to work? I have struggled with USB ever since I started with microcontrollers more than a decade ago and have never managed to get one to work. Any help will be greatly appreciated.

Define CLOCK_FREQUENCY = 20
Define CONFIG1L = 0x24
Define CONFIG1H = 0x0c
Define CONFIG2L = 0x3e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

UsbSetVendorId 0x1234
UsbSetProductId 0x1234
UsbSetVersionNumber 0x1122
UsbSetManufacturerString "OshonSoft.com"
UsbSetProductString "Generic USB HID Device"
UsbSetSerialNumberString "1111111111"
UsbOnIoInGosub input_report_before_sending
UsbOnIoOutGosub output_report_received
UsbOnFtInGosub feature_report_before_sending
UsbOnFtOutGosub feature_report_received

AllDigital
ADCON1 = 0x0e
TRISB = 0
PORTB = 0xff
UsbStart
PORTB = 0

Dim an0 As Byte

loop:
Adcin 0, an0
If an0 < 50 Then
PORTB = 0
UsbStop
While an0 < 100
Adcin 0, an0
Wend
PORTB = 0xff
UsbStart
PORTB = 0
Endif
UsbService
Goto loop
End

feature_report_received:
Toggle PORTB.7
Return

feature_report_before_sending:
UsbFtBuffer(0) = UsbFtBuffer(0) - 1
UsbFtBuffer(1) = UsbFtBuffer(1) - 1
UsbFtBuffer(2) = UsbFtBuffer(2) - 1
UsbFtBuffer(3) = UsbFtBuffer(3) - 1
UsbFtBuffer(4) = UsbFtBuffer(4) - 1
UsbFtBuffer(5) = UsbFtBuffer(5) - 1
UsbFtBuffer(6) = UsbFtBuffer(6) - 1
UsbFtBuffer(7) = UsbFtBuffer(7) - 1
Return

output_report_received:
Toggle PORTB.6
Return

input_report_before_sending:
UsbIoBuffer(0) = UsbIoBuffer(0) + 1
UsbIoBuffer(1) = UsbIoBuffer(1) + 1
UsbIoBuffer(2) = UsbIoBuffer(2) + 1
UsbIoBuffer(3) = UsbIoBuffer(3) + 1
UsbIoBuffer(4) = UsbIoBuffer(4) + 1
UsbIoBuffer(5) = UsbIoBuffer(5) + 1
UsbIoBuffer(6) = UsbIoBuffer(6) + 1
UsbIoBuffer(7) = UsbIoBuffer(7) + 1
Return
 

Mity Eltu

Member
I did not know there was a different license for USB. I just went to the Oshonsoft website and saw this, but when I go to the registered users download area there is not a different version for USB. I presume the difference would be in the registry key? Oh well, I don't have the funds for that right now. I'll just have to wait. Thank you for pointing that out.
 

Mity Eltu

Member
I have the licenses for pic and pic18, but they are personal licenses only. I noticed on the license page that the costs are significantly higher for the licenses that include basic support for USB. I presume the difference is not in the pic18 software but in the installed license key. That is, I assume the license key for the USB support will 'unlock' the basic compiler for USB support.
 

towlerg

New Member
Hi Mity,

those config fuses are a pain aren't they. Here's an extract of just the relevant USB stuff from a working prog (not Oshonsoft). You need to end up with 48Mhz to run high speed.

I find its easier to experiment with config settings if you declare them by function (if the language allows) rather than arbitary hex bytes.

Device = 18F4550
Xtal = 48

Config_Start
PLLDIV = 5 ;Divide by 5 (20 MHz oscillator input)
CPUDIV = OSC1_PLL2 ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
USBDIV = 2 ;USB clock source comes from the 96 MHz PLL divided by 2
FOSC = HSPLL_HS ;HS oscillator, PLL enabled (HSPLL)
VREGEN = On ;USB voltage regulator enabled
Config_End

I'm sure there's guys on this board who know a lot more about it than I do, but I don't think Oshonsoft USB support is going to help you that much. As I understand it, unlike other simulators (eg. Proteus) simulate the process with PC app and USB device running simultaneously.

George
 

Mity Eltu

Member
Thank you for the replies, but it seems I don't have the license for the USB support. I'll contemplate the purchase, but since I don't really have a NEED for it (I was just tinkering around to see if I could get it to work), I'm not sure the purchase would be useful. I can always use USART/SPI/I2C for communications if I need it. Thaks again.
 

Latest threads

EE World Online Articles

Loading

 
Top