CPU Clock Pulses and Clock FrequencyThe CPU is a finite state machine whose transitions are triggered by a circuit called and oscillator that periodically generates "clock pulses." One pulse duration is commonly called a "clock cycle" or "clock period." We will use these terms interchangeably.The frequency (rate) that clock pulses are generated is measured in "Hertz" (abbreviated Hz). The units are in pulses/second, so the delay between pulses is the reciprocal of frequency. Typical clock frequencies range from just under one million to a bit more than two billion pulses per second (1 MHz to 2 GHz). The MSP-430 is a family of specialized processors designed to control small energy-constrained devices (e.g blood pressure monitors). Their clocks can be configured by software to generate pulses at a variety of clock frequencies ranging from just under 1MHz to between 16 and 32MHz (varies by model). We examine how clock frequency is controlled in another chapter. Number of Clock Cycles Per Instruction The execution of an instruction includes several memory operations and not all instructions execute the same number of memory operations. Furthermore internal processing of some instructions requires more clock cycles than others. On the MSP430, each memory operation requires one clock cycle. Thus, you should not be surprised that the the execution time (in cycles) of an instruction varies by instruction.
More details: see section 3.4.4 "Instruction Cycles and Lengths" of the MSP430x2xx Family User's Guide
*see notes above on exceptions. Example problem:Q: How long does the following delay method execute on a MSP430 with a 2MHz clock: delay: mov 1000, r15 again: sub #1, r15 jnz again ret Solution: 1. 1 clock cycle is 1/2000000s = 5x10-7s = 0.5us 2. cycles/instruction delay: mov 1000, r15 ; 2 cycles outside loop again: sub #1, r15 ; 2 cycles inside loop (#1 in extension word) jnz again ; 2 cycles inside loop ret ; 3 cycles outside loop 3. cycles / execution of the routine
Total execution time (accurate to three decimal places): 4.005x103 cycles * 5*10-7 s/cycle = 20*10-4s = 2*10-3s = 2ms |