|
|
View previous topic :: View next topic |
Author |
Message |
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
USB PICF18F4550, WIN 7 64 bit |
Posted: Wed Dec 22, 2010 9:23 am |
|
|
Hi,
Im using ex_usb_serial.c example to send some data from PIC to PC.
Iv tried Proteus to simulate this example but there was no sucess because of CDC driver which is provided by proteus that does not work with CCS code example.
I believe that i should quit proteus and try on real work example.
Q1. In example there is a "USB connection sense pin" RB2. Is this critical step in process of usb connection.
Q2. Lets say i connect pic to a Win7 64bit PC. What will happen? Where i can get drivers for microchip USB. If i need to install microchip MCHPFSUSB Framework, then what i shoul do next?
Q3. There is no hyper-terminal in Win7 what i should use to see data coming from PIC ?
Thank you in advance! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Wed Dec 22, 2010 9:30 am |
|
|
Yes, Proteus is unreliable for USB on the PIC.
Q1, Depends..... You can turn the use of this pin on/off in the software. Generally, it does help to make the negotiation more reliable.
Q2 The CCS USB example, has Win7 drivers, which do work with W7-64, provided you have a 'recentish' example.
Q3 Install a terminal program. There are literally hundreds of ones on the web that do work, most better than Hyperterm (which is rather an abortion....).
Best Wishes |
|
|
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
|
Posted: Thu Dec 23, 2010 3:31 pm |
|
|
Ttelmah, Thank You !
Your reply helped me alot.
But still I do have problems. When I "power on" PIC connected to USB, 32bit XP tells that device is unknown.
My target is to send data from PIC to PC via USB. Data like variable values, not rapidly.
-How to use XP hyperterminal? Maybe there are better tools for PIC USB?
-As I understood I do not need to install or browse any drivers, before or during USB connection ? The version of compiler is 4.106.
I've added small part of example code that I've modified. Maybe is could help ?
Code: |
#use delay(clock=48000000)
// 4 000 000 ?= char lcd printed random numbers, my guess is that delay function do not work correctly because of delay nr.
//I've got 4M external xtal osc.
fuses are -USBDIV,PLL1,CPUDIV1
//set to 1 to use a PIC's internal USB Peripheral
//set to 0 to use a National USBN960x peripheral
#define __USB_PIC_PERIF__ 1
//if using a 16bit PIC on an Explorer 16 borad, set this to 1
#define __USB_PIC_EXPLORER16__ 0
#if (defined(__PCM__) || defined(__PCB__))
#error USB CDC Library requires PIC18, PIC24, dsPIC30 or dsPIC33
#endif
#if __USB_PIC_PERIF__
#DEFINE LED1 PIN_A5
#if defined(__PCH__)
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
#use delay(clock=48000000) // 4 000 000 ?= char lcd printer random numbers, my quess is that dealy function do not correctly.
//iv got 4M external xtal osc.
//#elif defined(__PCD__)
//#include <24FJ256GB110.h>
//#fuses HS,PR_PLL,NOWDT,DISUVREG,ICSP2
//#if __USB_PIC_EXPLORER16__
//#use delay(clock=32M) //8MHz clock is 4x because of PLL
//#fuses PLL2 //Divide 8MHz by 2 to get the 4MHz required for USB
//#pin_select U1TX = PIN_F5
//#pin_select U1RX = PIN_F4
//#endif
#endif
//#else //use the National USBN960x peripheral
//#DEFINE LED1 PIN_B3
//#include <18F452.h>
//#fuses HS,NOWDT,NOPROTECT,NOLVP
//#use delay(clock=20000000)
//#endif //endif check to see which peripheral to use
/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here. If you are
// not using connection sense, comment out this line. Without connection
// sense you will not know if the device gets disconnected.
// (connection sense should look like this:
// 100k
// VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
// |
// +----/\/\/\/\/\-----GND
// 100k
// (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
///only the 18F4550 development kit has this pin
#if __USB_PIC_PERIF__ && defined(__PCH__)
#define USB_CON_SENSE_PIN PIN_B2
#endif
#use rs232(UART1, baud=9600, errors)
#include <usb_cdc.h>
/////////////////////////////////////////////////////////////////////////////
//
// Configure the demonstration I/O
//
/////////////////////////////////////////////////////////////////////////////
#if defined(__PCD__) && __USB_PIC_EXPLORER16__
#undef LED1
#define LED1 PIN_A0
#define LED2 PIN_A1
#define LED3 PIN_A2
#define LED_ON(x) output_high(x)
#define LED_OFF(x) output_low(x)
#define BUTTON_PRESSED() !input(PIN_D6)
#else // need peaksid olema valitud
#define LED2 PIN_B4
#define LED3 PIN_B5
#define LED_ON(x) output_low(x)
#define LED_OFF(x) output_high(x)
#define BUTTON_PRESSED() !input(PIN_A4)
//printf("PIC18F4550\n");
#endif
#include <flex_lcd.c>
|
I'm sorry for posting example code :S.
----Later----
Sorry for confusion, I found USB drivers in PICC/Drivers folder and intalled them.
I did some test with Proteus and it seemed like something actually worked.
Hyper-terminal wast hard to understand, actually the only thing I had to do was choosing right COM port (after that left all braud rate type settings untouched).
Still, by applying all the changes to real example, I'm getting "device not recognized" message and updating drives does not help or work. It is only my assumption that the problem is in hardware. So PIC is not correctly wired or set up.
The hardware is on breadboard, char LCD, some pushbuttons and leds, VUSB pin is connected to ground with 470nF cap. The PIC with 4Mhz ext osc. is powered by 9V battery power supply or PICkit3. USB D- and D+ pins should be connected right way ... I've never tried using "USB_CON_SENSE_PIN PIN".
The code... I've tried many fuses and delay variations. Delay seems not to work, because char LCD does not show right stuff. Last fuses and delay values were:
Code: |
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN
#use delay(crystal=48000000, clock=4000000) //
|
Thank you in advance! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Fri Dec 24, 2010 1:47 pm |
|
|
Have you got an external _oscillator_, or a crystal?.
If the oscillator, switch to ECPLL, if the crystal, XTPLL. HSPLL, is not the correct fuse in either case, for 4MHz.
If the crystal, this is unlikely to work on a breadboard with USB. The capacitance of the board makes it very hard to get the frequency close enough for USB operation.
Best Wishes |
|
|
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
|
Posted: Fri Dec 24, 2010 7:00 pm |
|
|
Ttelmah, Thank You for reply.
I suppose it is answer to my question ("unable to recognize device" problem) because unfortunately im using t 4Mhz crystal oscillator with exact 27pF caps.
-What is your opinion? Should i trust Proteus outputs till final stages of design, till PCB design?
Proteus because till this point i did all UI and pretty much all using it... and because USB CDC examples works in Proteus very well.
-Im not very clear what i want :D. Can i design a small WIN application using CDC variant later. If not ... or it is more complicated... or not as good as something else... Should i choose HID or ...?
-Can i modify breadboard in a way that i will get at least one successful USB test?
merry xmas :D and
Thank You in advance! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Sat Dec 25, 2010 3:32 am |
|
|
Happy Christmas.....
You need to get _data_.
What is the specified loading capacitance for your crystal?.
What is the capacitance of the 'breadboard' you are using - there are lots of things described as 'breadboard', ranging from 'strip-board', through push in contact boards. For the former, you can calculate the capacitance per mm of the board. For the later, the 'better' manufacturers give figures for the typical strip to strip capacitance.
Now, the formula for the crystals to use, is:
Cl=C/2+Cs
Where 'Cl' is the loading seen by the crystal, 'C' is the capacitors you add, and 'Cs', is the stray capacitance.
Cs here is the stray capacitance between the crystal pins (capacitance of strip to strip on the breadboard, plus the pin to pin capacitance of the PIC). 'C', is the _sum_ of the capacitor value you are using, and and other stray capacitance's in parallel with this to ground.
Now, the plug in breadboards, vary massively, with capacitance's between a couple of pF, and some 20+pF per contact point, to the adjacent row. On the standard board layout, and a unit with say 5 contacts per row, if you are 'lucky', you get say 10pF between the rows, but on some cheap units, the capacitance can already be as high as 125pF, before you plug anything in.
Your crystal, then sees a loading already present, of the strip to strip capacitance of the board, and with the supply pin adjacent to one crystal pin, and the pin on the other side, being a TTL source, that is also effectively connected to DC, You get the formula coming as:
Cl = (10+2 - for a 'good' board) + (Cl+10+2)/2
So for a crystal requiring (say) 22pF loading, You can get a solution, with:
22 = (12) + (8+12)/2, and added load capacitances of just 8pF!....
However for the board with 25pF/contact, and the same crystal, even with no load added, the formula gives+
127 + (127/2) = 190.5pF, so way out of spec, that the crystal _won't_ give anywhere near it's desired frequency...
USB2 requires the clock to have a maximum error, of 0.05%. Not hard, if the loading is close to right, but with many breadboards, not 'doable'....
You are much better off, using one of the standard crystal oscillator 'modules', since (within reasonable limits), these don't mind the load capacitance.
So you need to find out the strip to strip capacitance of your 'breadboard', and the specified load capacitance of your crystal, and then you may be able to calculate if it is 'possible' to get close to the required loading on your board.
Best Wishes |
|
|
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
|
Posted: Sun Dec 26, 2010 7:29 am |
|
|
Ttelmah, Thank You !
I feel like I'm obligated to create a substantial reply.
The breadboard is High-q Solderless Breadboard
The oscillator is 4.000MHz " HC49 " type
http://www.golledge.com/pdf/products/xtl_ld/hc494h.pdf
The circuit conditions are D - 16 pF.
From PIC18F4550 datasheet:
On my breadboard:
Caps are 27 pF, exact as it is mentioned in PIC datasheet. The distance from cap contacts to voltage regulator contact is ~24 holes.
-------------------------
The breadboard specs tell that "14-pins IC capacity: 9" What does it means? Does it mean that between 2 contact push true holes capacitance is 9/14 pF ?
-------------------------
Can I solve this problem by bending 2 MCU osc pins up and creating point to point connection between osc pins and voltage regulator ground pin.
-------------------------
Thank you in advance! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 27, 2010 1:26 pm |
|
|
Quote: | The breadboard specs tell that "14-pins IC capacity: 9" What does it means? |
No. It means the breadboard has space for a maximum of 9 IC's of
the 14-pin type to be installed at the same time. |
|
|
matheuslps
Joined: 29 Sep 2010 Posts: 73 Location: Brazil
|
|
Posted: Mon Jan 03, 2011 2:50 pm |
|
|
I will help you with this issue.
The CDC protocol is very simple to use. Let start with a simple hardware and simple code.
Basic circuit to connect PIC>USB/COM>PC:
http://img526.imageshack.us/img526/7327/semttuloazq.png
Your cristal is corret, 4Mhz and 27pF. BUT remember, never forget the capacitor off 47uF on PIN 18. It is for USB stability.
Vdd and Vss come from USB cable. You need a capacitor at least of 100nF between + and - of USB.
A small program to test the hardware:
Code: | #include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN //For 4Mhz cristal
#use delay(clock=48000000)
#include <usb_cdc.h>
void main()
{
usb_cdc_init(); // Start cdc
usb_init(); // Start USB
for(;;) //Forever
{
usb_task(); // Test usb
if (usb_enumerated())
{
printf(usb_cdc_putc,"Testando Conexao USB->Serial!\n\r");
delay_ms (100);
}
}
} |
After connecting to your USB port, verify this:
http://img228.imageshack.us/img228/3172/reconhecidowindowsvirtu.png
Open Hyperterminal and configure the right COM and set baud rate to 9600 and see this:
http://img708.imageshack.us/img708/5649/simulaorodando.jpg
Proteus i svery usefull to TEST the circuit. But do not trust him all the time.
The CDC protocol works on windows 7 64 bits but Proteus do not.
To work on Win7 64 make a copy of the file cdc_NTXPVista.inf on folder drivers and modify with this:
Code: | ; Windows 2000, XP and Vista setup File for CCS CDC demo
; see examples ex_usb_serial.c and ex_usb_serial2.c
[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%CCS%
LayoutFile=layout.inf
[Manufacturer]
%ProviderName%=DeviceList, NTx86, NTamd64
[CCS]
%CCS_CDC%=Reader, USB\VID_0461&PID_0033
[Reader_Install.NTx86]
;Windows2000
[DeviceList.NTamd64]
%CCS_CDC%=Reader, USB\VID_0461&PID_0033
[DestinationDirs]
DefaultDestDir=12
Reader.NT.Copy=12
[Reader.NT]
Include=mdmcpq.inf
CopyFiles=Reader.NT.Copy
AddReg=Reader.NT.AddReg
[Reader.NT.Copy]
usbser.sys
[Reader.NT.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[Reader.NT.Services]
AddService = usbser, 0x00000002, Service_Inst
[Service_Inst]
DisplayName = %Serial.SvcDesc%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_DEMAND_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\usbser.sys
LoadOrderGroup = Base
[Strings]
CCS = "Custom Computer Services, Inc."
CCS_CDC = "USB to UART"
Serial.SvcDesc = "USB Serial emulation driver" |
Save and use it.
Sorry for my english mistakes.
bye |
|
|
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
|
Posted: Fri Jan 07, 2011 8:30 am |
|
|
matheuslps, Thank You !
You reply helped me much, now I've got virtual PC running on my main Win7 laptop and I managed to fix some issues with Proteus (you might want to re-install Proteus USB driver every time you start the program).
Also thank you for this minimized examples for 18F4550 USB.
Later I will build PCB and will do a reply on my progress. |
|
|
gmua
Joined: 07 Feb 2011 Posts: 11
|
|
Posted: Mon Feb 07, 2011 11:28 am |
|
|
matheuslps wrote: | A small program to test the hardware:
Code: | #include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,VREGEN //For 4Mhz cristal
#use delay(clock=48000000)
#include <usb_cdc.h>
void main()
{
usb_cdc_init(); // Start cdc
usb_init(); // Start USB
for(;;) //Forever
{
usb_task(); // Test usb
if (usb_enumerated())
{
printf(usb_cdc_putc,"Testando Conexao USB->Serial!\n\r");
delay_ms (100);
}
}
} |
|
Greetings matheuslps, what version of CCS are you using to compile the code?
I am getting the following warnings when I compile it, and when I try to simulate it in Proteus, it doesn't work (the USB analizer shows nothing).
Quote: | >>> Warning 203 "C:\Archivos de programa\PICC\drivers\pic18_usb.c" Line 531(1,1): Condition always TRUE
>>> Warning 216 "USBPROJ.c" Line 24(0,1): Interrupts disabled during call to prevent re-entrancy: (usb_token_reset)
>>> Warning 216 "USBPROJ.c" Line 24(0,1): Interrupts disabled during call to prevent re-entrancy: (usb_tbe)
>>> Warning 216 "USBPROJ.c" Line 24(0,1): Interrupts disabled during call to prevent re-entrancy: (usb_cdc_flush_out_buffer)
Memory usage: ROM=14% RAM=20% - 23%
0 Errors, 4 Warnings. |
I have some sample HEX files from other sites that do work, so I'm guessing the problem is with my version of the compiler (I'm using v4.106).
Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Mon Feb 07, 2011 3:37 pm |
|
|
No.
These are _warnings_ only.
They are just pointing out some things that _might_ be potential problems. They are not.
The 'condition always TRUE', comes from the infinite loop to keep the code from dropping off the end. Normal.
The warnings about interrupts being disabled, are because a couple of things in the library call code inside and outside interrupts. Perfectly OK, since the routines involved are short.
Best Wishes |
|
|
gmua
Joined: 07 Feb 2011 Posts: 11
|
|
Posted: Mon Feb 07, 2011 7:16 pm |
|
|
Ttelmah wrote: | No.
These are _warnings_ only.
They are just pointing out some things that _might_ be potential problems. They are not.
The 'condition always TRUE', comes from the infinite loop to keep the code from dropping off the end. Normal.
The warnings about interrupts being disabled, are because a couple of things in the library call code inside and outside interrupts. Perfectly OK, since the routines involved are short.
Best Wishes |
Thanks for the reply Ttelmah, I compiled the program using version 3.249 and it didn't show any of the warnings, but still doesn't work with Proteus.
The included USB samples in Proteus 7.5 SP3 do work, so I must be connecting something wrong. |
|
|
geolover
Joined: 08 Feb 2011 Posts: 18
|
|
Posted: Tue Feb 08, 2011 6:24 pm |
|
|
Thank you matheuslps!
Noob question:
I'm currently trying to implement 18F4550 on Explorer 16 to transmit data to PC with Matlab. It was connected to a 20MHz crystal. How should I reconfigure the code in order to get it working? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19495
|
|
Posted: Wed Feb 09, 2011 3:10 am |
|
|
The USB support with 3.249, differs from that on 4.106, taking less space, but creating the last couple of warnings to do so. The USB libraries for V4, won't work with 3.249. You can turn which warnings are given on/off.
With the standard libraries, these warnings are _normal_.
USB, in Proteus is poor. You _can_ get an occasional small program to work, but more fail than do. I have not got a single 'full scale' program that works in the real world, to work in Proteus. As far as I'm concerned, the USB simulation in Proteus, is not worth wasting time on.
Best Wishes |
|
|
|
|
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
|