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

Turn Led on - USB PIC
Goto page Previous  1, 2, 3, 4  Next
 
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: 9134
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Aug 08, 2014 7:03 am     Reply with quote

OK, though it's been 2-3 years since I last worked with the 4550, I'm pretty sure you can use a 4MHz xtal,then set the PLL prescaler to /1 which runs the PLL at 4MHz(it HAS to). From there you can divide the PLL output to run the CPU at 4 different speeds.
Perhaps someone that uses the PIC will comment.I have a lot of 4MHz xtals from the 16C84 days and am trying to use them up!

cheers
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Fri Aug 08, 2014 8:51 am     Reply with quote

You are right.
You can run full speed USB with the 4550, from a crystal at:

4, 8, 12, 16, 20 or 24MHz.

Then CPU at

48, 32, 24, or 16MHz
from any of these.

or at crystal /1, /2, /3 or /4 for the CPU from all of these as well.

So from 20MHz, CPU at 20, 10, 6.66, or 5MHz as well. (HS operation, rather than HSPLL)

However generally CPU rates below 8MHz, can start to become 'problematic' for USB operation, so for the slower crystals, the 'direct' divisions are best avoided.

With an external oscillator (as opposed to the crystal), you can also work off 40Mhz, and 48Mhz.

4MHz, is fine for USB, but you may find you need a series resistor for reliable operation (the PLL is slightly 'more fussy' off the 4MHz crystal - it is vital that the PLL is fed off a symmetrical 50:50 waveform - the prescalers other than /1 ensure this).

Key is that the USB PLL still runs if XT, HS, EC, or ECIO are selected, but the CPU then clocks off the crystal, not the PLL. The PLL still runs for USB though, unless USBDIV is turned off.

I use 8MHz, and 12MHz a lot (slightly lower power consumption, than the faster crystals).

Have fun.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 08, 2014 3:08 pm     Reply with quote

Based on Ttelmah's results, I un-installed the compiler and did a clean
install of vs. 5.011. Then it worked. Everything worked. I can press
'1' and turn on the LED, and press '0' and turn it off.

Also, I made an LED blinking program, and it blinked at the correct rate.
It's not running at 1/4 speed. It blinks the LED at 1 Hz with vs. 5.011:
Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,BROWNOUT,PUT,PLL5,CPUDIV1
#use delay(clock=48M)

//=================================
void main()
{

while(1)
  {
   output_toggle(PIN_B0);
   delay_ms(500);
  }

}


----------------------------
Another topic:
I think CCS's multi-versioning system just doesn't work reliably. I had
5.026 installed (command line version) and installed 5.011, and went to
the PIC-C Versions application (provided by CCS), and double-clicked
5.011 to make it active. But then upon compiling, it said it didn't like the
VREGEN fuse.

I didn't realize it yesterday, but in fact it wouldn't take any fuse. It rejects
them all. Somehow the installation gets screwed up. I've seen this before.
It's CCS's multi-versioning system and it just isn't reliable. It used to be,
before vs. 5, I could do a fast, clean install every time and it was 100%
reliable.

One more thing - If you go to Control Panel / Add or Remove Programs
and un-install the compiler from there, you will get CCS's tickbox window
asking you what items you want to installed. (At least, with vs. 5.026).
I discovered that even if you don't select the tickbox to remove your
Projects folder, it will wipe it out anyway. Along with your .CRG
registration files and everything else. Fortunately I had backed up both
those items in My Documents. Otherwise I would have lost years worth of
project files. Be very cautious about using the CCS un-install program.
Back up everything first, and do it some place other than the CCS folder.

I just emailed CCS support about this. Under no circumstances should
the un-installer ever wipe out a person's own project files. If it has to
be done, the person should do it manually.
nando88



Joined: 25 Aug 2013
Posts: 28

View user's profile Send private message

Circuit schematic
PostPosted: Sat Aug 09, 2014 4:53 pm     Reply with quote

Thanks for all the help you've given me.
Could you please share the circuit schematic you used to build the circuit to turn on the led with orders sent from the PC?
I have seen a lot of schematics, but none of them seem to work.
I also think I rather use a 20 MHZ crystal.
could you also share the code you used, the one in CCS and the other in java (If you used java to send the 1 and 0).
Thanks for your help!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 09, 2014 5:35 pm     Reply with quote

The code I used is from my previous post, here:
http://www.ccsinfo.com/forum/viewtopic.php?t=52722&start=8

The Teraterm setup instructions and link to the download for it is here:
http://www.ccsinfo.com/forum/viewtopic.php?t=39388&start=18
TeraTerm is used to send the '1' and '0' characters to the COM port.
Remember to look in Windows Device Manager to see what COM port
has been assigned to the USB board. You have to select that same
COM port (ie., COM4 or COM6 or whatever it is) in TeraTerm.

I'm using the older non-Rohs version of the PicDem2-Plus. The schematic
is in the back of this PDF:
http://ww1.microchip.com/downloads/en/DeviceDoc/PICDEM%202Plus%20Old%20Version%2051275b.pdf

On the Vusb pin of the 18F4550, I have a 4.7uF Tantalum capacitor.
I know Ttelmah says that's wrong, the value is too high, and I basically
agree, but I also know it works on my board and I didn't have a 470 nF
capacitor so I left it in there.

As I said in my post that I linked to above, the PicDem2-Plus has a 4.7K
pullup on pin C4 that had to be removed so it wouldn't interfere with the
USB pins.

I have a USB connector mounted on the board. I connected the ground
to the board's ground, and the D+ and D- pins to the 18F4550. I carefully
verified the pinout of the USB connector to make sure I had D+ and D-
going to the correct pins.

Here's a good schematic:
http://320volt.com/en/usb-uygulamalari-ccs-pic18f4550-pic18f2550/
The 1K on the MCLR is too low. Microchip wants it to be 10K for the ICD3
and CCS wants it to be 47K for their ICD-U64. I don't use the 1 Meg
resistor across the crystal. I've never found it necessary with the PICs
or crystals (ECS brand) that I use.

I also have the USB connection sense circuit installed. It consists of two
100K resistors. It was described in a ASCII Art schematic in an older
version of the CCS compiler example files. I can't find an example
right now. I'll post that later.
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Sun Aug 10, 2014 1:10 am     Reply with quote

As a comment PCM_programmer, I've kept on using the 'old' way of working with CCS. I found very early on that the automatic updating, and version switching, was a classic 'not working properly' bit of CCS code (why can't they concentrate on the compiler, not the frills?). The version switching, doesn't seem to always correctly change the include files used properly, and if the devices.dat is from a much older compiler version, it doesn't get handled correctly (I think this is what caused your problem).

I delete the automatic update utility (ccsload), when I install a new version, and just install each new version separately as I always used to do. This way it never tells me about 'new versions' (I can just check every few weeks, or if I see a comment here about something now working). It is far easier/safer than letting CCS stick their 'nose' into the update side of things!....

Though the reliability of the code has improved markedly in the last few years, I'm still a believer in not trusting any new release, and being 'sure' I know which release of everything, I'm actually using.

On the 4.7uF, the 'big' problem, is people fitting things like 4.7uF aluminium electrolytic capacitors thinking 'bigger is better' here, which then have poor HF performance. The better performance of tantalum means this is not a problem. The other problem is the same one as most regulators, that if the main supply rail drops faster than the USB rail, the regulator gets reverse biased. With something really large like 100uF, I'd get 'worried' by that, but at 4.7uF I'd be quite happy. Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 10, 2014 1:28 pm     Reply with quote

I don't have a ccsload file with the command line compiler.
In c:\Program Files\PICC, the closest thing I have is ccscon.exe.
Deleting that file did not get rid of the multi-versioning system.

I'm going to make a batch file that deletes the DLL directory, Devices,
Drivers, and all the files in c:\Program Files\PICC.

CCS also has ccsc.ini and pcw.ini in this directory (on XP):
c:\Documents and Settings\<user name>\Application Data\PICC
I'm going to delete those too.

Edit:
This is the batch file I made. It seems to work. I get a clean install
of the desired version, without any old versions left in the PICC directory.

This was only tested on Windows XP, and wouldn't work with other
versions of Windows because they don't have deltree. But a work-around
could be done with del and rd. This batch file is only for removal of
the command line versions of the compiler. Also, it doesn't do anything
to the registry settings. It leaves them unchanged. MPLAB has to be
closed when running this batch file, or you will get an "access denied"
on at least one .DLL file.
Code:

@echo off
cd "c:\Program Files\PICC"
deltree /y DLL
deltree /y Examples
deltree /y Devices
deltree /y Drivers
deltree /y ico
del UNWISE.EXE
del Default.mcp
del Suite_CCSPic.dll
del CCSCON.exe
del Readme.txt
del Ccsc.chm
del Ccsc.exe
del ccsuninstall.exe
del install.log
del Checkgdiplus.exe
cd "c:\Documents and Settings\<user name>\Application Data\PICC"
del pcw.ini
del ccsc.ini
cd "c:\Program Files\PICC"
dir
pause

It's not perfect. It doesn't check for the existence of files or directories
before attempting to delete them.

Edit:
Actually, XP doesn't come with deltree.exe. You have to download it from
the web. For example, this site has it:
https://www.raymond.cc/blog/download/did/1707/
Put it in the c:\Windows directory. Then the above batch file will work.


Last edited by PCM programmer on Tue Aug 19, 2014 1:52 pm; edited 1 time in total
nando88



Joined: 25 Aug 2013
Posts: 28

View user's profile Send private message

CCS & MPLab
PostPosted: Tue Aug 12, 2014 10:36 am     Reply with quote

Do I have to install mplab in order to use this code you provided?
From what I read, you used the mplab plugin.
I tried to compile the code only using ccs, but it gave me an error.
I also need to make this work for windows 7, 8, 8.1,etc.
Please tell me how to do this.
Thanks in advance!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 11:06 am     Reply with quote

Quote:
Do I have to install mplab in order to use this code you provided?

I assume you're talking about the code that is linked to, in my previous
post here:
http://www.ccsinfo.com/forum/viewtopic.php?t=52722&start=19
No, MPLAB isn't required. The CCS IDE should work fine.


Quote:
I tried to compile the code only using ccs, but it gave me an error.

You've got to tell us what the error is. Post the error messsage.

Quote:
I also need to make this work for windows 7, 8, 8.1,etc.

I can't help you with that because I'm a retro person still stuck on XP.
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 1:46 pm     Reply with quote

However the CCS side, doesn't change with XP, Vista, W7, 8, etc..

It's just the different .inf file needed when the device is first attached to the system.
Everything else remains the same.
nando88



Joined: 25 Aug 2013
Posts: 28

View user's profile Send private message

error
PostPosted: Tue Aug 12, 2014 2:57 pm     Reply with quote

Here is a picture showing the error that I'm getting:
https://www.mediafire.com/?3cchx7qg11v97xs
Please tell me how to fix it.
Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 3:12 pm     Reply with quote

OK, I see what you mean. To fix this problem, go to the CCS Examples
directory, and find ex_usb_common.h, and copy that file into your
project directory. Then it should compile OK.
Ttelmah



Joined: 11 Mar 2010
Posts: 19260

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 3:17 pm     Reply with quote

Are you using MPLAB?.

If so, only the 'main' source file wants to be in the 'source files' tab.

It's behaving as if you are trying to compile 'usb'h' on it's own (so no #device exists).

MPLAB will try to compile _all_ files in the source tab....

Other reason would be that you are including the file too early in the main file.
nando88



Joined: 25 Aug 2013
Posts: 28

View user's profile Send private message

another error
PostPosted: Tue Aug 12, 2014 9:47 pm     Reply with quote

I already copied the example to my working directory, but now I'm having another error:
https://www.mediafire.com/?0sqyy6rf5z7ggw8
Please tell me how to fix this error.
Thanks!
nando88



Joined: 25 Aug 2013
Posts: 28

View user's profile Send private message

Compiler used
PostPosted: Wed Aug 13, 2014 9:23 am     Reply with quote

I'm not using mplab, I'm only using ccs. The thing is I still don't know how to fix this error that says device required in the usb.h.
Can someone please help me out?
Thanks in advance!
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, 3, 4  Next
Page 2 of 4

 
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