• AVR Freaks

Hot!how many clock cycles does directive takes

Author
student
Junior Member
  • Total Posts : 104
  • Reward points : 0
  • Joined: 2008/07/24 04:04:55
  • Location: 0
  • Status: offline
2008/08/14 01:09:44 (permalink)
2 (1)

how many clock cycles does directive takes

hi
for bankselection there are two ways to proceed
one is" bsf STATUS,RP0"
second is "banksel FILEREGISTER"/banksel is a directive/
while programming  which instruction is better to use? and why?please tell how many clock cycles does each instruction takes?
thank u
#1

13 Replies Related Threads

    leon_heller
    Super Member
    • Total Posts : 6413
    • Reward points : 0
    • Joined: 2004/08/17 13:19:45
    • Location: St. Leonards-on-Sea, E. Sussex, UK.
    • Status: offline
    RE: how many clock cycles does directive takes 2008/08/14 01:39:13 (permalink)
    +1 (1)
    Banksel generates the code for bank selection, using both bcf and bsf. It can take more code than doing it yourself with bcf and bsf, as sometimes you only need one of them.

    You can see this for yourself if you look at the disassembly listing and see the code generated by banksel.

    Leon
    post edited by leon_heller - 2008/08/14 01:41:23

    Leon Heller
    G1HSM

    #2
    danish.ali
    Super Member
    • Total Posts : 1721
    • Reward points : 0
    • Joined: 2004/11/16 02:02:02
    • Location: Surrey, UK
    • Status: offline
    RE: how many clock cycles does directive takes 2008/08/14 01:42:04 (permalink)
    +1 (1)
    I would recommend the use of BANKSEL.
    There are several reasons.
    1) You don't need to specify which bank FILEREGISTER is in. You just need to specify the FILEREGISTER. This reduces the risk of errors.
    2) Although on your current PIC there might only be two banks, and so you only need to set/reset RP0, if you move to a larger PIC you might find that both RP0 and RP1 need to be changed. While you stick with the small PIC, the BANKSEL will only generate one BSF/BCF instruction and be just as fast as if you explicitly wrote the BSF. But as soon as you switch to the larger PIC, BANKSEL will automatically code the two necessary instructions - without you having to go through all your code and make the necessary changes.
    3) As suggested in (2), BANKSEL is just as efficient as explicitly coding BSF or BCF bacause it translates directly into that instruction.

    Imho the only downside with banksel is that as you don't need to be as aware of which bank every register is in, you might end up having more BANKSELs than you need - e.g if writing to several TRIS registers you might do:
            banksel TRISA
            movlw   b'11101010'  ; some meaningful comment as to how the pattern was generated
            movwf   TRISA
            banksel TRISB
            movlw   b'00111111'  ; again a useful comment as to which bits are inputs and why
            movwf   TRISB
    Had you done the BSF STATUS, RP0 in place of each banksel, you would immediately see that the second one is unnecessary so you could choose to omit it. But things are less obvious with BANKSEL.

    Hope this helps,
    Danish
    #3
    student
    Junior Member
    • Total Posts : 104
    • Reward points : 0
    • Joined: 2008/07/24 04:04:55
    • Location: 0
    • Status: offline
    RE: how many clock cycles does directive takes 2008/08/14 01:58:02 (permalink)
    0
    hi leon and danish.ali
    thanks for yours valueble advice
    i didn't understand about pull up's
    please tell me how these pull up's are useful in pic microcontroller
    what will happen if we select these pull up's using OPTION_REG in pic 16F688?
    thank u
    #4
    P Lameijn
    Super Member
    • Total Posts : 1981
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: offline
    RE: how many clock cycles does directive takes 2008/08/14 03:10:49 (permalink)
    0
    please tell me how these pull up's are useful in pic microcontroller

    If you need pull-ups on the inputs, you can use the internal pull-ups.

    what will happen if we select these pull up's using OPTION_REG in pic 16F688?

    Well, if you select pull-ups, you'll get....just that. Pull-ups on the port a pins described in the datasheet...

    Regards,
    Peter
    #5
    Horowitz
    Super Member
    • Total Posts : 443
    • Reward points : 0
    • Joined: 2006/04/27 07:00:38
    • Location: Greece
    • Status: offline
    RE: how many clock cycles does directive takes 2008/08/14 14:35:34 (permalink)
    0
    ORIGINAL: student

    hi
    for bankselection there are two ways to proceed
    one is" bsf STATUS,RP0"
    second is "banksel FILEREGISTER"/banksel is a directive/
    while programming  which instruction is better to use? and why?please tell how many clock cycles does each instruction takes?
    thank u


    Hi,
    You can use the mplabsim and see the generated assembly ( for that directive ). This way you can see yourseft how many commands ( ..and ofcourse how many Fosc/4 are needed ). Also, each assembly command ( not directive ) captures 1 program memory space. So, you can also see how the PC is incremented.
    #6
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: how many clock cycles does directive takes 2008/09/05 14:36:55 (permalink)
    +1 (1)
    BANKSEL is also upward compatible with 18F parts Smile

    GENOVA :D :D ! GODO
    #7
    spkdd
    Starting Member
    • Total Posts : 79
    • Reward points : 0
    • Joined: 2020/09/09 13:45:31
    • Location: 0
    • Status: offline
    Re: RE: how many clock cycles does directive takes 2020/09/15 00:12:17 (permalink)
    -1 (1)
    I've been reading datasheets and as far as I understand it, the pic is a risc processor and pretty much all instructions only take one clock cycle to execute.
    So I'm wondering how to properly use this to make a delay routine with known delay from the clock speed, calculated.
    Examples I found with delay routines don't match this assumption of 1 clock cycle.
    So how does this work then?
    #8
    Mysil
    Super Member
    • Total Posts : 3796
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: RE: how many clock cycles does directive takes 2020/09/15 00:58:03 (permalink)
    +1 (1)
    Hi, spkdd
    You are tailing on to an existing thread more than 10 years old, and with a different question.
    This is regarded as bad behaviour in this forum.
     
    RISC processor architecture, is a term that was invented long after PIC microprocessors was designed and first produced, so the term is not relevant.
     
    Delay procedure typically will contain some test and loop logic,
    branch test instruction take 2 instruction cycles if the branch is taken,
    and jump instructions take 2 instruction cycles always.
     
        Mysil
    #9
    ric
    Super Member
    • Total Posts : 28660
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: RE: how many clock cycles does directive takes 2020/09/15 01:49:22 (permalink)
    +1 (1)
    spkdd
    I've been reading datasheets and as far as I understand it, the pic is a risc processor and pretty much all instructions only take one clock cycle to execute.

    Why make assumptions, when every PIC datasheet contains a table listing how many cycles EVERY instruction takes?
    You will find that the general rules mentioned by Mysil are pretty accurate.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    spkdd
    Starting Member
    • Total Posts : 79
    • Reward points : 0
    • Joined: 2020/09/09 13:45:31
    • Location: 0
    • Status: offline
    Re: RE: how many clock cycles does directive takes 2020/09/18 02:53:45 (permalink)
    0
    MysilYou are tailing on to an existing thread more than 10 years old, and with a different question.
    This is regarded as bad behaviour in this forum.

     
    Obviously no bad behavior was intended. And being quite on topic, I don't see anything wrong with appending to an existing thread instead of creating a new one for that same topic.
     
    MysilRISC processor architecture, is a term that was invented long after PIC microprocessors was designed and first produced, so the term is not relevant.

     
    It is relevant in one way: most RISC processors tend to have their instructions execute in a single clock cycle, as opposed to others like CISC that take many cycles to execute their much more complex instructions.
     
    Since this is the kind of thing that does come into account when trying to ascertain who many cycles some code will take to execute, and knowing how much time one cycle takes, it's what needs to be looked at to evaluate total execution times.
     
    One more thing that I just found out recently while researching this, and that I think is good and relevant to mention, especially on such a thread for that particular topic: there is a distinction to make about the PICs, that I didn't know about, which is that the instruction execution cycles for PICs are not the same as clock cycles, and although it may differ from PIC to PIC, I'm not sure about that, at least for the one I'm working on right now, the 16F688, it takes 4 clock cycles to make one execution cycle, so in fact, one typical PIC instruction takes 4 clock cycles to execute and not one.
     
    Quite important when calculating execution times. I found examples where none of this is mentioned and cycle lengths are just mentioned, and when I try to corroborate this by calculating cycle time from clock frequency, it just doesn't jive.
    It then start making more sense and jives once it is understood that it's not one clock cycle, but 4, for each execution cycles. I still don't know why it is that way, but I do now know it is. And this does answer the original question posed to start this thread.
    #11
    NorthGuy
    Super Member
    • Total Posts : 6349
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: RE: how many clock cycles does directive takes 2020/09/18 05:57:16 (permalink)
    +2 (2)
    spkdd
    It is relevant in one way: most RISC processors tend to have their instructions execute in a single clock cycle, as opposed to others like CISC that take many cycles to execute their much more complex instructions.

     
    PIC24/dsPIC33 executes most of its far more complex instructions in a single cycle.
     
    #12
    spkdd
    Starting Member
    • Total Posts : 79
    • Reward points : 0
    • Joined: 2020/09/09 13:45:31
    • Location: 0
    • Status: offline
    Re: RE: how many clock cycles does directive takes 2020/09/18 07:52:12 (permalink)
    0 (2)
    NorthGuyPIC24/dsPIC33 executes most of its far more complex instructions in a single cycle.


    Confirming the PICs are mostly RISC or similar and most do execute in a single cycle.
     
    But what is important to note, is the fact that one clock cycle isn't = to one execution cycle, so when trying to calculate delays, one must first make sure to find out how many clock cycles make one execution cycle.
     
    At the moment, knowing only about the 16F688, I don't know about how that goes with other types, but the thing to note about it is: 4 clock cycles make 1 execution cycle, so at its default clock rate of 4mhz, that's 4 times .25us => 1us of execution cycle
    #13
    1and0
    Access is Denied
    • Total Posts : 11325
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: RE: how many clock cycles does directive takes 2020/09/18 08:22:29 (permalink)
    0
    spkdd
    But what is important to note, is the fact that one clock cycle isn't = to one execution cycle, so when trying to calculate delays, one must first make sure to find out how many clock cycles make one execution cycle.
     
    At the moment, knowing only about the 16F688, I don't know about how that goes with other types, but the thing to note about it is: 4 clock cycles make 1 execution cycle, so at its default clock rate of 4mhz, that's 4 times .25us => 1us of execution cycle

    spkdd
    It then start making more sense and jives once it is understood that it's not one clock cycle, but 4, for each execution cycles. I still don't know why it is that way, but I do now know it is.

    Most of the time, you just have to know the "instruction cycle" time. On ALL 8-bit PIC devices, one instruction cycle takes four oscillator cycles. These four Q cycles are Decode, Read, Process, and Write taken to execute an instruction.
     
    #14
    Jump to:
    © 2020 APG vNext Commercial Version 4.5