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

#use delay and OSC config

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eabir



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

#use delay and OSC config
PostPosted: Sat Oct 02, 2010 6:01 am     Reply with quote

Hello ,

There is something I don't understand regard the following:

When I set: #use delay(clock=4000000) then the code (routines) go less faster then if I set: #use delay(clock=1000000).

How the 1Mhz is faster then 4Mhz ?

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sat Oct 02, 2010 10:05 am     Reply with quote

It isn't.

The clock statement, doesn't change the physical clock speed (exception here if using the internal oscillator, where the clock setting will change this as well). It tells the compiler _what clock speed the processor is working at_.

If you have a processor that executed 1 million instructions per second (clock=4000000), and then use 'delay_ms(1000)', the compiler will generate code to perform one million instructions, to give exactly the delay you ask for. One second.
However if instead you tell the compiler that your processor only executes 250000 instructions per second, and then use the same delay statement, the compiler will generate code to produce 250000 instructions. If you then feed this code into a processor that is really running at 1MIPS, then it'll run four times faster than it should. problem then is that if the code contains delays that _must_ be certain durations to work, they will now run faster than they should. The processor doesn't run faster, but for delays, the compiler now generates shorter code.

You should set the clock speed to the actual speed your chip is running at, otherwise it'll make working times out _very_ hard, and prevent some of the libraries (like LCD ones, or the RS232 statements, which _depend_ on this value being right), from working. If you want the code to run faster, and have delays in the code, shorten them. Delay_ms(250), with a processor running at 1MIPS, will produce the same 250000 instruction code, as using the wrong clock statement...

Best Wishes
eabir



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

OSC setup
PostPosted: Sat Oct 02, 2010 10:21 am     Reply with quote

hi again,

Ok, how do I know how many MIPS are in the PIC10F222 ? (I assume MIPS is fixed per chip).

Is this line is enough for declaring the frequency ? : "#use delay(clock=4000000)".

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 02, 2010 2:17 pm     Reply with quote

Quote:

How do I know how many MIPS are in the PIC10F222 ?

Look on page 3 of the 10F222 data sheet, on the left side, in this section:
Quote:

High-Performance RISC CPU

http://ww1.microchip.com/downloads/en/DeviceDoc/41270E.pdf
It gives the features of the RISC processor. I have posted part of it
below. With those two pieces of information, you can easily calculate
the MIPS.

Code:
• All Single-Cycle Instructions Except for Program
Branches which are Two-Cycle

• Operating Speed:
- 500 ns instruction cycle with 8 MHz internal
clock
- 1μs instruction cycle with 4 MHz internal
clock
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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