PDA

View Full Version : About Mhz speed



serandre
- 5th April 2006, 04:16
Hi,

I need to delay a 1us, I know theres also an instruction for this.

But I like to understand if this is true:

I 'm using a pic with an internal 4Mhz clock speed, this means 4 millions instructions per second, right ?

If I waste for example a 4 NOP or whatever instruction that have only 1 cycle, this means a will get a perfect 1us delay ?


Thanks

Melanie
- 5th April 2006, 10:02
The PICs instruction cycle is one quarter of the clock speed.

So a 4MHz PIC has a 1uS instruction cycle.

You only need one NOP to achieve this at 4MHz.

Le'neord
- 17th September 2006, 07:12
Hi Melanie,

Still in concept mode for project but wonder if precision clock of 4mHz to 20mHz depending on instructions would allow me to use loop for an accurate counter up to 65535 (WORD) with +/- 1 usec accuracy.

plain english, not basic yet

main:
If pin n low then goto main..............wait for high in
else count=count+1.......................start counting
if pin n+1 low then serout "count".....sent the result
goto main

(5 or 6 mHz) for 1usec counter?

project needs 20 to 40 1usec counters. may trigger with pin n and stop with pin n+1. This would make a nice $.75 to $1.00 counter for my application and eliminate a lot of other parts.

Thanks for your time,

Melanie
- 17th September 2006, 09:20
The best counters in a PIC are the integral Timers, even better if you have CCP (Capture Compare) Modules in the PICs hardware.

If you're trying to count uS in software then you have to take into account the software latency in achieving the count. 1uS will be tight to achieve... apart from the fact that in PICBasic you don't really know how long any given instruction will take to execute. In Assembler you have a better chance since each instruction (example NOP) is only one or two clock cycles (see Assembler instruction list at the back of any PIC Datasheet).

Finally, remember that 1uS will not be 1.000000000uS when relying on the PICs crystal because they're seldom that accurate... they vary with temperature, voltage, windspeed and direction, beer, garlic...