News:

;) This forum is the property of Proton software developers

Main Menu

USB revival for 18F2550 - USBPoll skipped

Started by picsels, Feb 09, 2021, 10:12 PM

Previous topic - Next topic

picsels

I'm trying to progress on an old USB project; first with a simple PoC to get USB working.
I tried to use the example program that's listed with the USBOut command in the manual (the mouse pointer 'rotator').
The change I made was to replace the 18f4550 with 18f2550 and to change the clock settings to a 20MHZ crystal (see below).
However the program does not stop in the USBPoll loop when no USB cable is attached.
It skips right over it.
Any hints on what I'm doing wrong would be highly appreciated.


 Device = 18F2550
 Declare Xtal = 48

'------------------------------------------------------------------------
' Configure the 18F2550 for 48MHz operation using a 20MHz crystal
Config_Start
    PLLDIV = 5 ' Divide by 5 (20 MHz oscillator input)
    CPUDIV = OSC1_PLL2 ' [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
    USBDIV = 2 ' USB clock source comes directly from the primary osc

...

    Repeat
      USBPoll ' Wait for USB to become attached
    Until USB_tConnected = 1 Or USB_tConfigured = 1


RGV250

Hi,
I am not sure I understand correctly, are you saying you had it working correctly with the 4550, the example I have uses 2550.
I think I tried it a while ago and it is not possible with a 20mhz xtal, try it with a 12mhz xtal as per the example and see what happens.

Regards,
Bob
 

RGV250

Another thought, you are declaring the xtal as 48 but you are using a 20mhz xtal??

Bob

picsels

Sorry for the confusion.
No I never had it working with an 18F4550; immediately started with the 18F2550 (I do have a spare 18F4550, but no 12MHZ xtal).
I left it at 48MHZ, same as the manual, because of the PLL (datasheet figure 2.1 Clock diagram):
- PLLDIV = 5 to get it to 4MHZ as input for the PLL (to 96MHz)
- CPUDIV = OSC1_PLL2 brings it down to 48MHZ
- USBDIV = 2 so the clock source is the 48MHZ from the PLL and no longer the external 20MHZ crystal.

I did a crude check to verify the 48MHZ timing:
Put in a delayMS 20000 and timed with a stopwatch. This correctly resulted in a 20 second delay.
Hence my guess that the timings were set up correctly.

I was hoping it would work with 20MHZ because I have an old experiment board that contains the 18F4550 with a 20MHz xtal and AFAIK that one used to work (unfortunately not usable anymore) and I found some examples on line that use 20MHz as well that seem to work (but built with C, not PIC BASIC).

RGV250

Hi,
I am no expert on USB but I suspect that there is an issue with the xtal,I did look into when i tried it and failed but have forgotten. I think it was due to an incompatible configuration.
I would try it with a 12 mhz xtal as I think that may be your is your issue.

The PIC might be fine with it but the USB side might not be.

Bob   

towlerg

IIRC one of the USB modules has fuse config perhaps USB_Defs.Inc if that module is used. Maybe wrong, never used the command version of USB. For completeness below is all the fuses for 18F2550 with 20Mhz fuse. BTW 12Mhz is used for Full and Low speed.

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)
  FCMEN = OFF           ;Fail-Safe Clock Monitor disabled
  IESO = OFF           ;Oscillator Switchover mode disabled
  PWRT = On             ;PWRT enabled
  BOR = On             ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 3             ;Minimum setting
  VREGEN = On           ;USB voltage regulator enabled
  WDT = OFF             ;WDT disabled (control is placed on the SWDTEN bit)
  WDTPS = 32768         ;1:32768
  CCP2MX = On           ;CCP2 input/output is multiplexed with RC1
  PBADEN = OFF         ;PORTB<4:0> pins are configured as digital I/O on Reset
  LPT1OSC = OFF         ;Timer1 configured for higher power operation
  MCLRE = OFF           ;RE3 input pin enabled; MCLR pin disabled
  STVREN = On           ;Stack full/underflow will cause Reset
  LVP = OFF             ;Single-Supply ICSP disabled
  XINST = OFF           ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF           ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins