PIC frequency

Discussion in 'General Electronics Chat' started by dhruv1128, Aug 10, 2014.

  1. dhruv1128

    Thread Starter New Member

    Jun 28, 2014
    6
    0
    Hello all,

    I am using pic18f4550 and i am interfacing a crystal of 20Mhz. I want to know the execution time of 1 instruction cycle. I am having a great confusion. Please help me.

    Also, suggest me the method to do so please.

    Thanking you in advance
     
  2. blah2222

    Well-Known Member

    May 3, 2010
    554
    33
    From page 387 of the datasheet:

    Instruction Cycle Time (Tcy) = 4*Tosc = 4/Fosc with a minimum of 83.3 ns.

    Fosc for you is 20 MHz. I'm sure you can do the rest...
     
    dhruv1128 likes this.
  3. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    1 instruction cycle should take 4/(20*10^6) seconds.
     
    dhruv1128 likes this.
  4. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    I'll go even further: 200 ns
     
    dhruv1128 likes this.
  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    762
    In case of doubt, using the simulator, MPLAB Sim, just by stepping through a simple series of NOPs, you could see how much time is spent in each instruction cycle.

    Look for the "stopwatch" function.
     
    dhruv1128 likes this.
  6. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,129
    266
    Very common problem, there are so many clocking options to consider.
    I usually test the clock frequency like this:

    loop:
    btg LATX,X ;toggle IO pin state
    bra loop

    Measure the frequency of the output to confirm the clock speed.
    This saves much confusion about what is really going on, it's easy to get confused and set the clock bits wrong, then drive yourself insane trying to set a UART Baud rate.
     
    dhruv1128 likes this.
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    But how long is a bra? I go a another step when pounding this out:

    loop:
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bfs LATX,X ;toggle IO pin state
    bcs LATX,X ;toggle IO pin state
    bra loop

    Then I look with a scope, and it is right there in my face what the instruction rate is.
     
  8. Alec_t

    AAC Fanatic!

    Sep 17, 2013
    5,797
    1,103
    Depends on the lady it's designed for :).
     
    atferrari and blah2222 like this.
Loading...