PDA

View Full Version : Hello World help please 18F14K50 config



Bonxy
- 3rd August 2011, 16:45
Hi all, can anyone check my config in the picture below..

I am trying to get a 18f14k50 usb to work but I just keep getting the 'USB Device not recognized' message from windows.

I'm using a lab-x1 board with the clock set to 12mhz and the config settings below
Can anyone give a hello world example or config that will get this device going, I've been at it all day and I'm going nuts lol :eek:
Ps: i've read the datasheet and the other postings about config, i'm no wiser.

5816

ScaleRobotics
- 3rd August 2011, 17:16
You might try looking at Darrel's sample here: http://www.picbasic.co.uk/forum/showthread.php?t=5418&p=80434#post80434

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

Bonxy
- 3rd August 2011, 18:02
Thanks for sharing that config, I tried it but it does not work, I still get the device not recognized message, any ideas ?

ScaleRobotics
- 3rd August 2011, 18:10
I am on a dial-up connection right now, so it's sort of painful to look it up myself. But I didn't think the X-1 was made for the 14K50? You might try looking at the schematic for the low pin count 14k50 board from Microchip, and note any differences. It sounds like a hardware issue, as the code from Darrel definitely works.

Bonxy
- 3rd August 2011, 18:14
Hi yeah dial-up can be a pain.

I used the prototype area on the lab-x1 for the 14k50, I tried darrels code and it gives the same problem but darrels code does not tell you what config settings to use ?.

ScaleRobotics
- 3rd August 2011, 18:21
I think it does show most of the configs to use:



'************************************************* **************************
'* 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, 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

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)
ANSEL = %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

Bonxy
- 3rd August 2011, 18:35
Hi, yes, I just noticed that, ok I copied that config into the program and also into the INC file and still device unrecognized :-(

ScaleRobotics
- 3rd August 2011, 18:53
Have you looked at the schematic for the low pin count kit, and compared it to what you have? http://ww1.microchip.com/downloads/en/DeviceDoc/41356B.pdf

Are you applying power to the Vusb like the schematic?

ScaleRobotics
- 4th August 2011, 07:24
What code are you using for the usb part? DT_HID260.pbp, with DT_INTS-18.bas or something else?

Bonxy
- 4th August 2011, 09:32
Hi, I am going to check the vusb voltage today, the 18f14k50 / 13k50 is the cheapest usb part ?.

Bonxy
- 4th August 2011, 14:24
Ok, it is now working :-), the config from darrel's code above works, the problem was something to do with my PC, when I turned it on this morning and plugged im my 14k50 it enumerated straight away, it looks like my pc had become corrupted somehow from using a bad configuration previously.

anyway, thanks to scalerobotics for your help :-)

ps: scalerobotics, would it be ok to PM you with another 14k50 question perhaps ?

Thanks again

ScaleRobotics
- 4th August 2011, 17:35
That's great! Glad you got it working.

Sure, PM me anytime.

-Walter