CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Request: USB HID Test code for 18LF14K50 12MHz
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 8227
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 23, 2021 5:35 am     Reply with quote

I thought CCS supplied an example, maybe in newer versions of the compilers ?
dyeatman



Joined: 06 Sep 2003
Posts: 1840
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Oct 23, 2021 6:30 am     Reply with quote

Yes. In my latest version compiler I have a total of 42 USB related driver and
example files but, as you know, we are not allowed to post them or give them
to anyone. The OP will have to request them from CCS.
_________________
Google and Forum Search are some of your best tools!!!!
temtronic



Joined: 01 Jul 2010
Posts: 8227
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 23, 2021 7:14 am     Reply with quote

wow ! 42 USB examples !! That's more than the TOTAL number of examples from the 1st version of CCS I bought !!

providing the OP has registered his compiler, CCS will probably send him the 'examples' folder. They did that for me. I asked ,just to see how they 'cut code', to save me time reinventing the wheel .
Ttelmah



Joined: 11 Mar 2010
Posts: 17485

View user's profile Send private message

PostPosted: Sat Oct 23, 2021 8:46 am     Reply with quote

Yes, and the CDC example will work with the LF. All you have to do is change
the header to be for the LF instead of the F, and it runs. The E3 board header
works with the LF chip (I've used it).
PCM programmer



Joined: 06 Sep 2003
Posts: 21508

View user's profile Send private message

PostPosted: Sat Oct 23, 2021 9:32 am     Reply with quote

FFT wrote:
Nobody has a test code?

I have located a board, the PIC, and the USB cable to test this.
I can do it this evening or tomorrow. I don't think you have ever
posted your CCS compiler version. It would be helpful if you did.
I could test it with your version.
Ttelmah



Joined: 11 Mar 2010
Posts: 17485

View user's profile Send private message

PostPosted: Sat Oct 23, 2021 10:24 am     Reply with quote

PCM, I used a board with the same layout as the E3 board, except with a
3.3v supply to the chip. Using compiler 5.101, and just copied the
usb common file to use the LF where the F was used for this board.
5.101 was the latest compiler when I did this, and it ran file with
ex_usb_serial.
So if your board is compatible with the E3, this is where I would start.

Best wishes.
FFT



Joined: 07 Jul 2010
Posts: 64

View user's profile Send private message

PostPosted: Sun Oct 24, 2021 2:35 am     Reply with quote

Hello guys,

I will give you more details;

* Here is my schematic (simplified - usb+pwr only) https://ibb.co/Fn762XN
VBUS pin is connected to 3.3V VCC externally, but I see 3.1V when I cut the connection. I tested both. It seems VBUS is connected to VCC internally too.

* I use CCS v5.104

* I have 12 Mhz NX5032 crystal with 22pF caps

I have shared a test code before, here is the latest code derived from mouse example (please remove if it's not allowed)
I tested several delay configs and fuses but there is absolutely no action when usb is plugged in. PIC's USB plays dead!

Code:
#include <18LF14K50.h>

// I have 12 Mhz NX5032 crystal with 22pF caps
#FUSES NOWDT, CPUDIV1, HS, PLLEN, NOMCLR, NOLVP, NOXINST, PUT, USBDIV1
#use delay(clock=48Mhz)
//#use delay(clock=48MHz,oscillator=12MHz,USB_FULL)
//#use delay(clock=24MHz,oscillator=12MHz,USB_LOW)

//#define USB_USE_FULL_SPEED 0
//#define USB_INTERNAL_PULLUPS 1
//#define USB_EXTERNAL_PULLUPS 1
#define USB_ISR_POLLING 1
#include <pic18_usb.h>
#include <usb_desc_mouse.h>
#include <usb.c>

typedef unsigned int16 TICK;
#use timer(timer=1, bits=16, tick=1ms)

#define MOUSE_UPDATE_RATE_TICKS  (TICKS_PER_SECOND/100)  //10ms rate

void main(void)
{
   TICK t;

   #define MOUSE_SEQUENCE_STEPS  16
   const char mouse_seq[MOUSE_SEQUENCE_STEPS]=
      {0, 1, 3, 4, 4, 4, 3, 1, 0, -1, -3, -4, -4, -4, -3, -1};

   int8 out_data[4];
   unsigned int8 x_seq;
   unsigned int8 y_seq;
   unsigned int8 count;

   x_seq = 0;
   y_seq = MOUSE_SEQUENCE_STEPS/4;
   count = 0;

   delay_ms(100);

   usb_init_cs();

   while (TRUE)
   {
      usb_task();

      if (
            usb_enumerated() &&
            ((get_ticks() - t) > MOUSE_UPDATE_RATE_TICKS) &&
            usb_tbe(1)
         )
      {
         t = get_ticks();

         out_data[0] = 0;
         out_data[1] = mouse_seq[x_seq];
         out_data[2] = mouse_seq[y_seq];
         out_data[3] = 0;

         if (usb_put_packet(1,out_data,4,USB_DTS_TOGGLE))
         {
            if (++count > 10)
            {
               if (++x_seq>=MOUSE_SEQUENCE_STEPS) {x_seq=0;}
               if (++y_seq>=MOUSE_SEQUENCE_STEPS) {y_seq=0;}
               count=0;
            }
         }
      }
   }
}


I started to think that I have a HW issue, such as my original PicKit3 burns the D+ and D- pins of the LF PIC...
I also tested internal pull ups definition but it seems it is already comes defined. So I can test placing an external pullup resistor.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21508

View user's profile Send private message

PostPosted: Sun Oct 24, 2021 7:07 am     Reply with quote

I made it work right now. I used an 18F14K50 (not LF) running
at +5v. I made a project for Ex_usb_serial.c in MPLAB vs. 8.92.
I used CCS vs. 5.103 simply because it was already installed.
I created the project in the CCS Examples folder, and named the
project "Ex_usb_serial". I added Ex_usb_serial.c to the project.

In Ex_usb_common.h, I commented out this line:
Code:
// #define USB_HW_CCS_PIC24F

and I uncommented this line:
Code:
#define USB_HW_MCHP_18F14K50

Those are the only changes I made to the files.

I installed a 12 MHz crystal on pins 2 and 3 of the PIC, with 22pf caps to
ground on each pin. I have a 10K pullup on pin 4, for MCLR. I have a
10uF tantalum on pin 17 for Vusb because I don't have a .22uf to .47uf
ceramic in stock.

I have D+ and D- and ground connected to the USB connector.

I programmed the PIC with a Pickit 3. It gives a warning about how you
must use an AC164114 adapter. I didn't have one. It worked anyway.
I think the warning may be for older programmers such as ICD 2.

I plugged the USB cable into a Windows 10 Pro system. It enumerated
immediately. Device Manager shows:
Code:

Ports (COM & LPT)
   USB Serial Device (COM3)

I also plugged the USB cable into an older XP system.
The Device Manager says:
Code:

Ports (COM & LPT)
   USB to UART (COM4)

If I pull out the USB cable, those enumerations go away.
Ttelmah



Joined: 11 Mar 2010
Posts: 17485

View user's profile Send private message

PostPosted: Mon Oct 25, 2021 12:34 am     Reply with quote

When you say that you cut the Vusb connection, are you still leaving D+
and D- connected to the USB bus?. If so, what happens then is that the
transceivers get reverse biased, and power is fed through them into the
Vusb pin. I've known people successfully run the USB, without Vusb
connected (though with terrible reliability), because this happens....

There is a possible issue with the resistor values used on your detection
of the usb power connection. You have 10K+15K, so a voltage divider
giving 3v out from 5v. Usb V+, is only warranted to be 4.4v minimum.
The pin you are using for the Vbus detection has a schmitt input, so the
signal needs to get to above 2.64v. If the supply voltage on your USB bus
is at the lower end of the scale, and there is any resistance drop in the
plug, the chip won't be detecting that the bus is powered....
I'd suggest dropping the upper resistor to 8.2k. This might be causing an
issue.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group