In 430, one clock cycle = the inverse of the MCLK crystal oscillator. If MCLK is 8M, then one clock cycle is 1/8us;
one machine cycle = one clock cycle, that is, each action of 430 can complete a basic operation;
one instruction cycle = 1 to 6 machine cycles, depending on the specific instruction.
In addition: the instruction length is just a storage unit and has no necessary relationship with time.
MSP430 can choose to use up to 3 oscillators depending on the model. We can choose the appropriate oscillation frequency according to the needs, and can turn off the oscillator at any time when not needed to save power. The three oscillators are:
(1) DCO Digital Controlled RC Oscillator. It is inside the chip and can be turned off when not in use. The oscillation frequency of the DCO is affected by the ambient temperature and the operating voltage of the MSP430, and the frequencies generated by the same type of chip are also different. However, the adjustment function of the DCO can improve its performance. Its adjustment is divided into the following three steps:
a: Select BCSCTL1.RSELx to determine the nominal frequency of the clock;
b: Select DCOCTL.DCOx to make a rough adjustment in segments based on the nominal frequency;
c: Select the value of DCOCTL.MODx for fine adjustment.
(2) LFXT1 is connected to a low-frequency oscillator. Typically, it is connected to a 32768HZ clock oscillator. In this case, the oscillator does not need to be connected to a load capacitor. It can also be connected to a 450KHZ~8MHZ standard crystal oscillator. In this case, a load capacitor is required.
(3) XT2 is connected to a standard crystal oscillator of 450KHZ~8MHZ. At this time, a load capacitor needs to be connected, which can be turned off when not in use.
Low-frequency oscillators are mainly used to reduce energy consumption, such as battery-powered systems. High-frequency oscillators are used to respond quickly to events or provide the CPU with a large number of calculations. Of course, the high-end 430 also has frequency-locked loop (FLL) and FLL+ modules, but you don't need to consider so many at the beginning.
MSP430 has three clock signals: MCLK system main clock; SMCLK system sub-clock; ACLK auxiliary clock.
(1) MCLK system main clock. In addition to the CPU operation using this clock, peripheral modules can also use it. MCLK can select any clock signal generated by an oscillator and divide it by 1, 2, 4, or 8 as its signal source.
(2) SMCLK system sub-clock. For use by peripheral modules. It can be divided by the registers of each module before use. SMCLK can select the clock signal generated by any oscillator and divide it by 1, 2, 4, or 8 as its signal source.
(3) ACLK auxiliary clock. For use by peripheral modules. It can be divided by the registers of each module before use. However, ACLK can only be divided by 1, 2, 4, or 8 by LFXT1 as a signal source.
After PUC reset, the signal sources of MCLK and SMCLK are DCO, and the default oscillation frequency of DCO is 800KHZ. The signal source of ACLK is LFXT1.
The MSP430 contains a crystal oscillator failure monitoring circuit that monitors the clock signals output by LFXT1 (working in high-frequency mode) and XT2. When the clock signal is lost for 50us, the monitoring circuit detects the oscillator failure. If the MCLK signal comes from LFXT1 or XT2, the MSP430 automatically switches the MCLK signal to DCO, which ensures that the program continues to run. However, the MSP430 does not monitor the LFXT1 working in low-frequency mode.
Look at the picture: As can be seen from the picture, the second function of P5.4, P5.5, and P5.6 can output the clock
Sample code:
Copy code
#include <msp430x14x.h>
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
DCOCTL = DCO0+DCO1+DCO2; // means setting all three bits to 1 to maximize the internal frequency
BCSTL1 = RSEL0+RSEL1+RSEL2; // set BCSCTL1
BCSCTL2 |=SELS; // set BCSCTL2
P5DIR |=0x70; // set the input and output of P5.5, P5.6, P5.7
P5SEL |=0x70;
while(1);
}
|