|
|
View previous topic :: View next topic |
Author |
Message |
eabir
Joined: 16 Aug 2010 Posts: 19
|
#use delay and OSC config |
Posted: Sat Oct 02, 2010 6:01 am |
|
|
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: 19550
|
|
Posted: Sat Oct 02, 2010 10:05 am |
|
|
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
|
OSC setup |
Posted: Sat Oct 02, 2010 10:21 am |
|
|
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
|
|
Posted: Sat Oct 02, 2010 2:17 pm |
|
|
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 |
|
|
|
|
|
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
|