Author Topic: Problem with Pic 18f4550 USB  (Read 23843 times)

selvabha

  • Member
  • ***
  • Posts: 9
Problem with Pic 18f4550 USB
« on: March 13, 2011, 03:44:12 am »
Hi,
 
I used microc compiler to write firmware for pic 18f4550.and i used generic Hid template from lakeview.
It seems working fine in some of my systems.But it failed to work with my new i3 processor pc Machine and in some of our pcs.

The problem is the device was detected in all of our pcs as hid but it failed to communicate with application after some 5mts or 10 mts of time.
Also At that time i am getting a Error in application .

"UNEXPECTED EXCEPTION"
EXCEPTION:SAFE HANDLE HAS BEEN CLOSED
MODULE:HID
METHOD:CANCELIO


I tried in My computer ->manage and i see my device was detected and it stilll remains "after a scan for hardware changes".

so i tried by closing my application and disabled->enabled my hid driver, after this i opened the app and it seems to communicate for some time after that same thing happens again.

also if i restart the microcontroller it seems to work fine.
i can't figure exactly where the problem is because in some systems it is working fine.

Please guide me to figure it out .........

Thankyou
« Last Edit: March 13, 2011, 03:51:06 am by selvabha »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Problem with Pic 18f4550 USB
« Reply #1 on: March 13, 2011, 12:14:30 pm »
Use whatever debugging tools you have to isolate the problem.

If my example firmware works OK, start with that and make incremental changes.

A protocol analyzer will show what is happening on the bus.

Use watch variables, etc. in MPLAB.

Jan

selvabha

  • Member
  • ***
  • Posts: 9
Re: Problem with Pic 18f4550 USB
« Reply #2 on: March 15, 2011, 11:39:56 am »
Dear Jan,

The problem is my chip hangs while executing the firmware.
This thing happens only on my i3 core processor desktop.............
Why it happens? due to selfpower
Any Advice from your side will be greatly appreciated

Thanks......
« Last Edit: March 15, 2011, 11:42:22 am by selvabha »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Problem with Pic 18f4550 USB
« Reply #3 on: March 15, 2011, 12:41:48 pm »
You need to find out where the firmware is hanging and go from there.

Jan

selvabha

  • Member
  • ***
  • Posts: 9
Re: Problem with Pic 18f4550 USB
« Reply #4 on: March 15, 2011, 01:12:26 pm »
Dear Jan,

According to you, can you say about the pic 18f4550 performance?
is it perfectly detected by all the systems and is it working fine without any problem all the times for you?

Because if the performance is not good ,I will change my chip...

Thanks for the help and Advice.

selvabha

  • Member
  • ***
  • Posts: 9
Re: Problem with Pic 18f4550 USB
« Reply #5 on: March 15, 2011, 02:55:14 pm »
Dear Jan,

As you said early,i debugged my firmware while it hangs.

It hangs in Hid write() function.As the functions are inbuilt with my Microc compiler it doesn't show up where it exactly hangs inside Hid write() function.

so i decided to add a blinky program to see the microcontroller was running all the time. Again my blinky led stops flashing after hid write () function.

After this i disable the device in My->computer-> Manage and i enable the device.
And i shocked my microcontroller starts flashing the led.oops!!!!

There May only two reasons:
Reason-1
 am wondering that this problem is may due to Micro controller waiting for Acknowledgment from os?

Reason-2
And may also due to polling time because i set it for 1ms.

Mr.Jan can you tell me my Assumptions are correct?And if  am wrong pls say from your point of view.


Thankyou



selvabha

  • Member
  • ***
  • Posts: 9
Re: Problem with Pic 18f4550 USB
« Reply #6 on: March 16, 2011, 01:11:52 pm »
Dear Jan,

Sorry if i ask you any thing wrong.
At the time of hanging .The device is still alive but i cant get any data in my usb Analyzer.
Any help would be greatly Appreciated. Because my product will be released by this month.

This is my product:

http://www.youtube.com/watch?v=l5aYrrhqMI0&feature=feedu

Thanks
« Last Edit: March 16, 2011, 01:18:00 pm by selvabha »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Problem with Pic 18f4550 USB
« Reply #7 on: March 16, 2011, 02:20:26 pm »
The PIC works fine for HID applications. There are other USB controllers that are easier to program but less flexible, such as FTDI USB UART, which you access like a serial port.

The host will quit trying to access the device on receiving no response (ACK or NAK) after repeated tries.

To isolate the problem, try things such as:

Repeated reads
Repeated writes
Slower polling interval

and see if it fails.

A hardware analyzer would show what is happening on the bus.

Is your software doing a command/response, or can the host and device each send data at any time? Are you using control or interrupt transfers?

Jan




selvabha

  • Member
  • ***
  • Posts: 9
Re: Problem with Pic 18f4550 USB
« Reply #8 on: March 16, 2011, 03:37:57 pm »
Dear Jan,

First of all thanks for the wonderful Book "USB Complete" I own one original Hard copy with me.

Actually my Board is a DAQ board, which is having two temperature sensors sending temperature values
Continuously to my software for every 500 ms to display the values.

And also user can select the temperature to turn ON the Ports of the microcontroller,by clicking a button from my software.


So iam writing data continuously and reading data when user clicks button that may happen at anytime.
And iam Polling for 10ms and Iam using Interrupt.

THIS IS MY CONFIG FILE

//******************************************************************************
//
// File Version 1.01
//
//******************************************************************************

#include "Definit.h"
#include "VARs.h"

//******************************************************************************
// The number of bytes in each report,
// calculated from Report Size and Report Count in the report descriptor
//******************************************************************************
unsigned char const HID_INPUT_REPORT_BYTES      = 30;
unsigned char const HID_OUTPUT_REPORT_BYTES     = 30;

unsigned char const HID_FEATURE_REPORT_BYTES    = 2;
//******************************************************************************
// Byte constants
//******************************************************************************
unsigned char const NUM_ENDPOINTS               = 2;
unsigned char const ConfigDescr_wTotalLength    = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN);
unsigned char const HID_ReportDesc_len          = 47;

unsigned char const Low_HID_ReportDesc_len      = HID_ReportDesc_len;
unsigned char const High_HID_ReportDesc_len     = HID_ReportDesc_len >> 8;

unsigned char const Low_HID_PACKET_SIZE         = HID_PACKET_SIZE;
unsigned char const High_HID_PACKET_SIZE        = HID_PACKET_SIZE >> 8;



//******************************************************************************
// Descriptor Tables
//******************************************************************************
unsigned char const DescTables[USB_DEVICE_DESCRIPTOR_ALL_LEN*2] = {

// Device Descriptor
    USB_DEVICE_DESCRIPTOR_LEN, 0,           // bLength               - Length of Device descriptor (always 0x12)
    USB_DEVICE_DESCRIPTOR_TYPE, 0,          // bDescriptorType       - 1 = DEVICE descriptor
    0x00, 0,                                // bcdUSB                - USB revision 2.00 (low byte)
    0x02, 0,                                //                                           (high byte)
    0x00, 0,                                // bDeviceClass          - Zero means each interface operates independently (class code in the interface descriptor)
    0x00, 0,                                // bDeviceSubClass
    0x00, 0,                                // bDeviceProtocol
    EP0_PACKET_SIZE, 0,                     // bMaxPacketSize0       - maximum size of a data packet for a control transfer over EP0
    0xXX, 0,                                // idVendor              - Vendor  ID (low byte)
    0xXX, 0,                                //                                    (high byte)
    0xXX, 0,                                // idProduct             - Product ID (low byte)
    0x00, 0,                                //                                    (high byte)
    0x01, 0,                                // bcdDevice             - ( low byte)
    0x00, 0,                                //                         (high byte)
    0x01, 0,                                // iManufacturer         - String1
    0x02, 0,                                // iProduct              - String2
    0x00, 0,                                // iSerialNumber         - ( None )
    0x01, 0,                                // bNumConfigurations    - 1

// Configuration Descriptor
    USB_CONFIG_DESCRIPTOR_LEN, 0,           // bLength               - Length of Configuration descriptor (always 0x09)
    USB_CONFIG_DESCRIPTOR_TYPE, 0,          // bDescriptorType       - 2 = CONFIGURATION descriptor
    ConfigDescr_wTotalLength, 0,            // wTotalLength          - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
    0x00, 0,                                //                         ( high byte)
    0x01, 0,                                // bNumInterfaces        - Number of interfaces
    0x01, 0,                                // bConfigurationValue   - Configuration Value
    0x00, 0,                                // iConfiguration        - String Index for this configuration ( None )
    0xA0, 0,                                // bmAttributes          - attributes - "Bus powered" and "Remote wakeup"
    250, 0,                                  // MaxPower              - bus-powered draws 250*2 mA from the bus.

// Interface Descriptor
    USB_INTERF_DESCRIPTOR_LEN, 0,           // bLength               - Length of Interface descriptor (always 0x09)
    USB_INTERFACE_DESCRIPTOR_TYPE, 0,       // bDescriptorType       - 4 = INTERFACE descriptor
    0x00, 0,                                // bInterfaceNumber      - Number of interface, 0 based array
    0x00, 0,                                // bAlternateSetting     - Alternate setting
    NUM_ENDPOINTS, 0,                       // bNumEndPoints         - Number of endpoints used in this interface
    0x03, 0,                                // bInterfaceClass       - assigned by the USB
    0x00, 0,                                // bInterfaceSubClass    - Not A boot device
    0x00, 0,                                // bInterfaceProtocol    - none
    0x00, 0,                                // iInterface            - Index to string descriptor that describes this interface ( None )

// HID Descriptor
    USB_HID_DESCRIPTOR_LEN, 0,              // bLength               - Length of HID descriptor (always 0x09)
    USB_HID_DESCRIPTOR_TYPE, 0,             // bDescriptorType       - 0x21 = HID descriptor
    0x01, 0,                                // HID class release number (1.01)
    0x01, 0,
    0x00, 0,                                // Localized country code (none)
    0x01, 0,                                // # of HID class descriptor to follow (1)
    0x22, 0,                                // Report descriptor type (HID)
    Low_HID_ReportDesc_len, 0,
    High_HID_ReportDesc_len, 0,

// EP1_RX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             // bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        // bDescriptorType       - 5 = ENDPOINT descriptor
    0x81, 0,                                // bEndpointAddress      - In, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         // bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 // wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                //                       - max packet size - high order byte
    10, 0,                                  // bInterval             - polling interval (10 ms)

// EP1_TX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             // bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        // bDescriptorType       - 5 = ENDPOINT descriptor
    0x01, 0,                                // bEndpointAddress      - Out, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         // bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 // wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                //                       - max packet size - high order byte
    10, 0,                                  // bInterval             - polling interval (10 ms)

// HID_Report Descriptor
    0x06, 0,                                // USAGE_PAGE (Vendor Defined)
    0xA0, 0,
    0xFF, 0,
    0x09, 0,                                // USAGE ID (Vendor Usage 1)
    0x01, 0,
    0xA1, 0,                                // COLLECTION (Application)
    0x01, 0,
//  The Input report
    0x09, 0,                                // USAGE ID - Vendor defined
    0x03, 0,
    0x15, 0,                                //   LOGICAL_MINIMUM (0)
    0x00, 0,
    0x26, 0,                                //   LOGICAL_MAXIMUM (255)
    0x00, 0,
    0xFF, 0,
    0x75, 0,                                //   REPORT_SIZE (8)
    0x08, 0,
    0x95, 0,                                //   REPORT_COUNT (2)
    HID_INPUT_REPORT_BYTES, 0,
    0x81, 0,                                //   INPUT (Data,Var,Abs)
    0x02, 0,
//  The Output report
    0x09, 0,                                // USAGE ID - Vendor defined
    0x04, 0,
    0x15, 0,                                //   LOGICAL_MINIMUM (0)
    0x00, 0,
    0x26, 0,                                //   LOGICAL_MAXIMUM (255)
    0x00, 0,
    0xFF, 0,
    0x75, 0,                                //   REPORT_SIZE (8)
    0x08, 0,
    0x95, 0,                                //   REPORT_COUNT (2)
    HID_OUTPUT_REPORT_BYTES, 0,
    0x91, 0,                                //   OUTPUT (Data,Var,Abs)
    0x02, 0,
//  The Feature report
    0x09, 0,                                // USAGE ID - Vendor defined
    0x05, 0,
    0x15, 0,                                //   LOGICAL_MINIMUM (0)
    0x00, 0,
    0x26, 0,                                //   LOGICAL_MAXIMUM (255)
    0x00, 0,
    0xFF, 0,
    0x75, 0,                                //   REPORT_SIZE (8)
    0x08, 0,
    0x95, 0,                                //   REPORT_COUNT (2)
    HID_FEATURE_REPORT_BYTES, 0,
    0xB1, 0,                                //   FEATURE (Data,Var,Abs)
    0x02, 0,
//  End Collection
    0xC0, 0                                 // END_COLLECTION
};
//******************************************************************************
unsigned char const LangIDDescr[8] = {
    0x04, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    0x09, 0,                                // LangID (0x0409) - Low
    0x04, 0                                 //                 - High
};
//******************************************************************************
unsigned char const ManufacturerDescr[28] = {
    14, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    'A', 0, 0, 0,
    'R', 0, 0, 0,
    'I', 0, 0, 0,
    'S', 0, 0, 0,
    'T', 0, 0, 0,
    'A', 0, 0, 0
};
//******************************************************************************
unsigned char const ProductDescr[120] = {
    60, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    'A', 0, 0, 0,
    'R', 0, 0, 0,
    'I', 0, 0, 0,
    'S', 0, 0, 0,
    'T', 0, 0, 0,
    'A', 0, 0, 0,
    ' ', 0, 0, 0,
    'T', 0, 0, 0,
    'E', 0, 0, 0,
    'M', 0, 0, 0,
    'P', 0, 0, 0,
    'E', 0, 0, 0,
    'R', 0, 0, 0,
    'A', 0, 0, 0,
    'T', 0, 0, 0,
    'U', 0, 0, 0,
    'R', 0, 0, 0,
    'E', 0, 0, 0,
    ' ', 0, 0, 0,
    'C', 0, 0, 0,
    'O', 0, 0, 0,
    'N', 0, 0, 0,
    'T', 0, 0, 0,
    'R', 0, 0, 0,
    'O', 0, 0, 0,
    'L', 0, 0, 0,
    'L', 0, 0, 0,
    'E', 0, 0, 0,
    'R', 0, 0, 0
};
//******************************************************************************
unsigned char const StrUnknownDescr[4] = {
    2, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0
};
//******************************************************************************


Please Let me Know if anything is wrng in my config file.


Thanks



« Last Edit: March 16, 2011, 03:44:21 pm by selvabha »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Problem with Pic 18f4550 USB
« Reply #9 on: March 18, 2011, 06:00:59 pm »
Does the HID Write function send data to the PC or receive data from the PC? (Hard to tell from the name, since USB names everything from the perspective of the host, but firmware sometimes names things from the perspective of the device.)

Jan

selvabha

  • Member
  • ***
  • Posts: 9
Re: Problem with Pic 18f4550 USB
« Reply #10 on: March 27, 2011, 02:56:32 am »
Dear Jan,

Yesterday we purchased the new version of the compiler because they said that they have improved the USB HID library .It works perfect ;D