View previous topic :: View next topic |
Author |
Message |
caldera_
Joined: 21 Aug 2008 Posts: 3
|
18F4550 USB Error |
Posted: Sat Nov 27, 2010 12:22 pm |
|
|
I have 2 LEDs connected to 18F4550. I put two buttons to pc software. Each button turns on one LED while turning of the other one. I am controlling the microchip via usb. My problem is it works if I press one of the buttons once. After second press the pc software freezes and microchip does nothing. Strangely it works fine with Proteus simulation. Can anyone help me solve this problem?
I use the code below.
Code: |
#include <18F4550.h>
#fuses HSPLL,USBDIV,PLL5,CPUDIV1,VREGEN,NOWDT,NOPROTECT,NOLVP,NODEBUG,NOMCLR,PUT
#use delay(clock=48000000)
#define USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK
#define USB_EP1_TX_SIZE 2
#define USB_EP1_RX_SIZE 3
#include <pic18_usb.h>
#include <PicUSB.h>
#include <usb.c>
#include <types.h>
#define LED1 PIN_D2
#define LED2 PIN_D3
#define LED_ON output_high
#define LED_OFF output_low
#define mode receive[0]
#define param1 receive[1]
#define param2 receive[2]
void main(void) {
int8 receive[3];
int8 send[2];
usb_init();
usb_task();
usb_wait_for_enumeration();
LED_ON(PIN_D1);
while (TRUE)
{
usb_task();
if (usb_kbhit(1))
{
usb_get_packet(1, receive, 3);
if (mode == 1)
{
LED_ON(LED1);
delay_ms(25);
LED_OFF(LED2);
}
if (mode == 2)
{
LED_ON(LED2);
delay_ms(25);
LED_OFF(LED1);
}
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 28, 2010 2:35 pm |
|
|
Apparently you are doing an HID project ? Use the forum's search page
and search for:
You will find many suggestions on how to make it work. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=42690
With regard to Proteus, it's a simulator. It's an abstraction. It only
simulates a subset of the features of a complex interface, such as USB.
In the real world, the size of the filter cap on the Vusb pin of the PIC
makes a lot of difference. Does Proteus even care about the value,
or the type of capacitor on the Vusb pin ? Probably not. Here is the
thing: Don't believe Proteus is "godlike". It's just a program. It has
bugs, and limitations. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9172 Location: Greensville,Ontario
|
|
Posted: Sun Nov 28, 2010 2:50 pm |
|
|
Why blame the PIC software? As I see it, it only listens for either a 1 or a 2 to come from the PC. Hard to see how that can freeze the PC program. You say the PC software freezes. It can easily be the program you wrote to send the 1 or 2 when the button is pressed to the PIC, or the PC hardware, or conflicts with the other programs you're running on the PC.
Proteus is just another lamebrain simulator, NOT the real world, NEVER trust it ! |
|
![](templates/subSilver/images/spacer.gif) |
MikeP
Joined: 07 Sep 2003 Posts: 49
|
|
Posted: Sun Nov 28, 2010 10:11 pm |
|
|
8 bytes is the min for bulk transfers. Even if you are only sending 2 or 3 bytes the USB code handles that.
Code: |
#define USB_EP1_TX_SIZE 8
#define USB_EP1_RX_SIZE 8
|
|
|
![](templates/subSilver/images/spacer.gif) |
caldera_
Joined: 21 Aug 2008 Posts: 3
|
|
Posted: Tue Nov 30, 2010 2:50 pm |
|
|
temtronic wrote: | Why blame the PIC software? As I see it, it only listens for either a 1 or a 2 to come from the PC. Hard to see how that can freeze the PC program. You say the PC software freezes. It can easily be the program you wrote to send the 1 or 2 when the button is pressed to the PIC, or the PC hardware, or conflicts with the other programs you're running on the PC.
Proteus is just another lamebrain simulator, NOT the real world, NEVER trust it ! |
Its not a HID project. The main project is a minimized temperature control system. I will use 3 DS18B20s and fans etc. but I couldn't even send any temperature values to PC. Then I made this sample test circuit but it doesn't work properly either.
MikeP wrote: | 8 bytes is the min for bulk transfers. Even if you are only sending 2 or 3 bytes the USB code handles that.
Code: |
#define USB_EP1_TX_SIZE 8
#define USB_EP1_RX_SIZE 8
|
|
Thank you MikeP for your advice. I made the changes you mentioned but it's still not working. |
|
![](templates/subSilver/images/spacer.gif) |
MikeP
Joined: 07 Sep 2003 Posts: 49
|
|
Posted: Tue Nov 30, 2010 5:01 pm |
|
|
You need to find out if its the PC app or the PIC with the problems.
What happens if you kill the PC app and restarted it after the lockup? does it work again or do you have to do a power cycle on the pic hardware for it to work again? |
|
![](templates/subSilver/images/spacer.gif) |
caldera_
Joined: 21 Aug 2008 Posts: 3
|
|
Posted: Thu Dec 02, 2010 3:30 pm |
|
|
It doesn't work until I make a power cycle on the pic. What could be the problem? |
|
![](templates/subSilver/images/spacer.gif) |
MikeP
Joined: 07 Sep 2003 Posts: 49
|
|
Posted: Thu Dec 02, 2010 11:41 pm |
|
|
What are you using for the PC code?
Can you post your PC app code? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19365
|
|
Posted: Fri Dec 03, 2010 9:09 am |
|
|
Looking at what is posted, what device class are you actually trying to use?.
You haven't posted PICUsb.h, which presumably (hopefully) contains your usb descriptor, so we have no hope of working out what the actual nature of the interface you are setting up is.... You are presumably trying to set up something like the test and measurement class?.
Your best bet, would be to get a USB 'sniffer' program, and see what is actually being sent, and how this relates to the class you are trying to use. Though the USB stack, is a lot more rugged than it used to be, it will still get confused if a device does not behave as it is meant to. Your problem has all the sounds of a USB descriptor, which is not valid for the class you are trying to use....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Fri Dec 03, 2010 8:41 pm |
|
|
For such a simple task, I would not bother using HID. Why don’t you use CDC? It will make it easy to debug (you can just use hyper term to view what the pic is sending) and you will not need to write any drivers for the device.
Have a look at ex_usb_serial.c for a good start point.
Mark |
|
![](templates/subSilver/images/spacer.gif) |
|