About Mhz speed


Closed Thread
Results 1 to 4 of 4

Thread: About Mhz speed

Hybrid View

  1. #1
    serandre's Avatar
    serandre Guest

    Default About Mhz speed

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Le'neord's Avatar
    Le'neord Guest


    Did you find this post helpful? Yes | No

    Default Accuracy of speed instruction cycle

    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,

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

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

Similar Threads

  1. TSA5512/5511 code for PIC16F877/84
    By Marin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th August 2013, 06:16
  2. USB Speed
    By Rony in forum General
    Replies: 0
    Last Post: - 21st August 2008, 22:15
  3. Closed loop speed controller
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 26th January 2008, 14:15
  4. NEWB Help HPWM coding
    By Seafurymike in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st January 2008, 21:52
  5. Replies: 14
    Last Post: - 26th September 2007, 05:41

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts