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.
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.
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,
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...
Bookmarks