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 CCS Technical Support

USB HID library error?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

USB HID library error?
PostPosted: Mon Nov 02, 2009 2:15 pm     Reply with quote

Hi! I've found a strange feature of your usb library:
When I connect my device to computer with Win7 it's always defined by OS.
When I connect it to computer with winXP, it can be defined, and can be not, it depends.
I've tried to rewrite my code on mikroC and use their library, the device is defined everytime I connect it to PC.
But I need some ccs functionality.

I think that it's your usb code error Sad
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Nov 02, 2009 4:41 pm     Reply with quote

What do you mean with "defined by OS"? What's exactly the error?
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Mon Nov 02, 2009 5:31 pm     Reply with quote

Sorry for poor english
In XP:
"USB device was not recognized"... An yellow ballon near to tray.
In device manager I see exclamation sign near hid device icon.
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Mon Nov 02, 2009 5:56 pm     Reply with quote

Error code 10

It seems that the device is not recognised when microcontroller clock frequency is other than 48 MHz

I use 20 MHz crystal -> HSPLL -> PLLDIV5 -> CPUDIV#
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 02, 2009 10:55 pm     Reply with quote

Quote:
It seems that the device is not recognised when microcontroller clock frequency is other than 48 MHz
To start off - this is not a "HID library error". I think you're having problems with selecting the right oscillator fuses. The '2455/'2550/'4455/'4550 have an architecture that allows for various different clock speeds while keeping the USB clock at 48MHz.

The USB clock is driven from the primary clock source, which may range from 4MHz to 48MHz, but by a clever use of PLLs and dividers, the USB clock is kept at 48MHz.

Page 24 of the '4550 datasheet shows the oscillator block diagram. The primary oscillator (OSC1/OSC2) is fed to a prescaler which divides the clock down to 4MHz. Naturally, the prescale factor _and_ the crystal frequency (ie Fosc) have to be selected such that (Fosc/Prescale factor = 4MHz). This 4MHz is PLL'ed to 96MHz, divided by 2 to get 48MHz and then used as the USB clock.

The 96MHz is also sent to the PLL postscaler, divided by a suitable factor, and used as the CPU clock.

Fosc may directly be sent to a clock divider and used as CPU clock source.

Also, if the Fosc is a stable 48MHz, it may directly be sent to the USBDIV mux and be used as the USB clock.

The above explanation may sound confusing, but its easy enough to understand if you have the block diagram with you. As long as you chose the right combination of fuses you can use a wide range of crystal frequencies.

Rohit
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 12:48 am     Reply with quote

Thanks, but I have already read about this in datasheet. I always read it before I want to create something.

Datasheet says that my device can be low-speed and a speed. As I don't need hi-speed transfer, I want to obtain a low-speed one. I change fuses according to datasheet.

When I use CCS hid library, XP does not correctly recognise device from time to time. There's about 1 error for 5 connections. TOO much.

When I write the same code using mikroC, (the same frequency options, the same descriptor!), there are no errors when i plug the device to computer.

That's why I think there's an error in ccs usb lib.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 1:22 am     Reply with quote

By mentioning the oscillator frequency point, you suggested yourself insufficient reading of the datasheet and incorrect programming on your side as the most likely reason for the said problem. It must not neccessary be the case.

As a fact, other users (me too) didn't yet experience the problems in the way you described them. Generally, I suggest to use a USB software monitor to clarify what's actually seen by the PC at the USB port. In my opinion, the most common fault in using the USB libaries is blocking the service of USB interface by your application, either by disabling interrupts or not servicing usb_task() longer than tolerated by the USB host.
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 1:30 am     Reply with quote

There can be only one point where I can interfere with usb - I've added timer0 interrupt.
I toggles led on and off.

By the way, don't tell me that there can be no errors in ccs! Timer0 DIV_128 and DIV_256 give the same interrupt frequency Wink
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 1:31 am     Reply with quote

... for 18f2550
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 2:36 am     Reply with quote

I'll be one of the last to say, there are no errors in CCS examples and no compiler bugs. I told, I didn't yet
experience it with the HID driver and suggested a more precise analysis.

I understand, that the question HID library error? intendeds to ask others, if they experienced similar problems.
I didn't (in this particular case). I'm interested to hear, if others did.
Ttelmah
Guest







PostPosted: Tue Nov 03, 2009 3:13 am     Reply with quote

Start with the following. You talk about 'your HID library'. Understand, this forum, is _not_ CCS. 99% of the people who post here, are nothing whatsoever to do with CCS (one moderator works for the company, but he rarely posts).

Now, the HID library does work, which suggests that there is a problem with the setup you are using for 20MHz, or a specific fault with your compiler version. So, post the following:

Your fuses - you don't say what you are using for CPUDIV. This is vital, since it affects the actual clock used by the CPU, and some timing factors.
Your CLOCK setup line. This too affects the same things.
Your compiler version number - this is in the format x.xxx, and is shown near the top of the .lst file.

Your fault does sound like a basic setup problem, some of the things you have to do to set things up 'right' for the CCS library, are poorly documented, so it is not uncommon to have problems with this.

Best Wishes
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 8:39 am     Reply with quote

compiler 4.093
18f2550, Three computers with OS: win7, xp, xp
('bad' means there are more than 1 error device recognition per 5 connections)

20 MHz - HSPLL, USBDIV, PLL5, CPUDIV4 - win7 - good/ xp-bad / xp-bad
20 MHz - HSPLL, USBDIV, PLL5, CPUDIV3 - win7 - good/ xp-better / xp-bad

16 MHz - HSPLL, USBDIV, PLL4, CPUDIV4 - win7 - good/ xp-better / xp-bad
16 MHz - HSPLL, USBDIV, PLL4, CPUDIV3 - win7 - good/ xp-better / xp-bad
16 MHz - HSPLL, USBDIV, PLL4, CPUDIV2 - win7 - good/ xp-good / xp-good But not every packet is accepted by computer (eg I press "a", then release button, and computer doesn't receive terminating null report)

Code:

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL4,CPUDIV2,VREGEN
#use delay(clock=16000000)

#include <pic18_usb.h>
#include "usb_headers.h"
#include "usb.c"

void main (void)
{
    usb_init_cs()
    {
        while(TRUE)
        {
        usb_task()

            if (usb_enumerated)
            {
                  usb_put_packet(1,buffer,2,USB_DTS_TOGGLE);
            }
            delay_ms(10);
        }
    }
}
Ttelmah
Guest







PostPosted: Tue Nov 03, 2009 9:13 am     Reply with quote

You are not posting the corresponding clock lines.
#use_delay.
This is _vital_.

So:

20 MHz - HSPLL, USBDIV, PLL5, CPUDIV4 - win7 - good/ xp-bad / xp-bad
Needs #use_delay(clock = 16000000)

20 MHz - HSPLL, USBDIV, PLL5, CPUDIV3 - win7 - good/ xp-better / xp-bad
Needs #use delay(clock=24000000)

16 MHz - HSPLL, USBDIV, PLL4, CPUDIV4 - win7 - good/ xp-better / xp-bad
Needs #use_delay(clock=16000000)

16 MHz - HSPLL, USBDIV, PLL4, CPUDIV3 - win7 - good/ xp-better /
xp-bad
Needs #use_delay(clock=24000000)

16 MHz - HSPLL, USBDIV, PLL4, CPUDIV2 - win7 - good/ xp-good / xp-good
Needs #use_delay(clock=32000000)

I'd guess that you actually have the #use_delay, left at 48M, which is the default in the CCS example, and in the last case, things are getting 'close enough' to start working.

The value needed is the real frequency the CPU is running at. The CPUDIV fuses, give fuse patterns, corresponding to their number-1, so CPUDIV2, gives the fuse pattern 01. You then look in the data sheet, which shows that if using the PLL, this pattern gives division by 3. Then, 96M/3 = 32M, and this value _MUST_ be put into the clock statement, for the code to work.

The same is true with any of the other compilers. They _all_ require that you either use the settings exactly 'as written', or you _must_ adjust these parameters to match what you are setting. This is not a CCS specific problem.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 03, 2009 2:43 pm     Reply with quote

Also review this list of tips on using the CCS Ex_hid_usb.c demo file:
http://www.ccsinfo.com/forum/viewtopic.php?t=38897&start=1
KT315



Joined: 27 Oct 2009
Posts: 19

View user's profile Send private message

PostPosted: Mon Nov 23, 2009 4:19 pm     Reply with quote

Hi!
I had a pause in creating the device, and now I continue... I still have problems with usb recognition on some computers.

That was surprise for me with the clock I need to write:
Quote:
20 MHz - HSPLL, USBDIV, PLL5, CPUDIV4
Needs #use_delay(clock = 16000000)

Cause in datasheet is written that microcontroller works on 24 MHz frequency.

So... Now I'm using 20 MHz quartz, this is my code:
Code:
#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV2,VREGEN
#define __USB_PIC_PERIF__ 1
#device ADC=8
#use delay(clock=32000000)

#include <pic18_usb.h>
#include "usb_headers.h"
#include "usb.c"

With this settings my device is successfully recognized by 3 of 4
computers. But problems with one of them make me very sad.
(This computer was bought about a month ago, it's not broken or
something else)

If I use other combinations of plldiv/cpudiv/clock the device is recognized only by one computer.

Please, help me. What should I change to use my device with all computers?
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 1, 2  Next
Page 1 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