On the next instruction execution, the PC will indicate the "MOVLW b'01010101'" instruction, and the PIC will execute the "GOTO Label_1" instruction and will fetch the "MOVLW b'01010101'" instruction. The PIC will execute the "MOVLW 0xFF" and will fetch the "GOTO Label_1". On the next instruction cycle, the PC will indicate the "GOTO Label_1" instruction. When the PC is on the "MOVLW 0xFF" instruction (line 2), the PIC will execute the "BSF Zero" instruction and will load the "MOVLW 0xFF". And why is that? Suppose we have this part of code to examine: the PIC will need 2 cycles to execute this instruction. Whenever the PC is forced (with a GOTO/CALL/RETURN instruction) to change. In this paragraph i explained that during the very first instruction execution of the program immediately after a power-on, the PIC will require 2 instruction cycles. But why does this happen? Well, if you have read and understood the first paragraph (4 pulses = 1 operation), then it will be easy to understand why. These are the GOTO instruction, the CALL and the RETURN (including RETLW and RETFIE). The second category with instructions that needs more than 1 cycle to be executed, contains all the instructions that will force the PC to change. This is something that you need to pay attention when calculating the instruction cycles required for a subroutine. In other words, the conditional branching instructions may need 1 or 2 instructions cycles to be executed, according to the condition result. The instructions that follows the BTFSS instruction will be executed normally! In this case, the BTFSS instruction must be calculated as an 1-Cycle instruction, and the following instruction must be taken into account accordingly. This example is the same as the previous one, but now we have CLEAR the Zero flag. But how is a conditional branch handled from the PIC? Let's see an example with BTFSS instruction:īTFSS Zero If Zero is SET, then SKIP the next instruction These are the BTFSS, BTFSC, DECSZ and INCSZ ( more info for the instructions here). The first category and most straight-forward to understand contains all the instructions that have a conditional branch. There are two categories of instructions that require 2 instruction executions in order to be fulfilled. Unfortunately, not all instructions are executed in a single operation (4 clock pulses). The sub-title is of course a rhetorical question. Due to the fact that during Q1-Q4 the PIC does 2 jobs simultaneously (fetch new instruction and execute previous instruction), on every PC increment (4 Clock Pulses) one instruction is executed, or better say that on every PC increment, on operation is carried out.Ĥ pulses = 1 operation, 1 operation = 1 instruction execution? This means that the PC will be increased 2 times, but only one instruction will be executed, right? WRONG! This would only happen during the very first instruction that the PIC will execute immediately after the power on. But you may also notice, that, for example, in order to execute the instruction in PC position = n+1, the PIC will need 8 clock pulses! During the first 4 pulses, it will fetch the instruction, and during the other 4 pulses it will execute it. This means that every 4 clock cycles, an instruction is executed. It is clear that the PC (Program Counter) is increased ONCE every 4 clock pulses. During these 4 clock pulses, the PIC will fetch the instruction that the updated Program Counter indicates, and simultaneously it will execute the instruction that was fetched during the PREVIOUS Q1-Q4 pulses! This is something that you will probably will never have to deal with, and that will never cause you any further frustration more than understanding how the PIC works. The Program Counter ( more info about the Program Counter) will be increased on every Q1. We will name these 4 pulses Q1 through Q4. The PIC will internally divide the clock input frequency by 4, in order to execute the program instructions. Until then, the only thing you need to know is that the no matter which input is selected (internal oscillator or external XTAL / RC circuit), we will refer to this input generally as " Clock Input", and the pulses from the Clock Input as "Clock Pulses". In later chapters we will discuss the different clock sources. When designing a PIC project, the first thing to consider is the oscillation clock source and frequency of the PIC. What is the relationship between the oscillator frequency of the PIC and the instruction cycle duration? In this page we will discuss about this very important subject. Instruction Cycle Duration and Calculated Delays Home Projects Experiments Circuits Theory BLOG PIC Tutorials Time for Science Home Contact Projects Experiments Circuits Theory BLOG PIC Tutorials Time for Science RSS Terms of services Privacy policy
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |