当前位置:网站首页>[msp430g2553] graphical development notes (2) system clock and low power consumption mode
[msp430g2553] graphical development notes (2) system clock and low power consumption mode
2022-07-24 20:11:00 【Beryllium oxyacetate】
Catalog
platform :
Code Composer Studio 6.2.0 + Grace 2.2.0
MSP430G2553 LaunchPad Development Kit (MSP-EXP430G2ET)
Most of the following is taken from 《LaunchPad Pocket experiment platform —— MSP-EXP430G2 piece 》 Fu Qiang 、 Yang Yan Huang, (TI University program embedded microcontroller technology series )
Overview of system clock
The manufacturing process of modern single chip computers is almost the same , The potential of energy saving by electronic components themselves is very limited . The low power consumption of single chip microcomputer mainly depends on intermittent work , The method of intermittent work is to start and stop the system clock . If like ordinary 51 Single chip microcomputer has only one clock , Turning off the clock means that the single chip computer will stop working , While saving energy, it can't be used normally . So for the need of low power consumption ,MSP430 The system clock of single chip microcomputer is divided into MCLK、SMCLK and ACLK Three , You can close one, several or all of them as needed .
MCU The units that need clocks in include CPU And some internal and external devices , The functional differences of the three clocks are as follows :
- MCLK: Master clock (Main system Clock) , Specially designed for CPU Run the clock provided .MCLK The higher the frequency configuration ,CPU The faster the execution . although CPU The faster the speed, the higher the power consumption , But high frequency MCLK It can make CPU Shorter working hours . Therefore, the correct low-power design is not to minimize MCLK, It's not used CPU Close immediately MCLK. In most applications , need CPU The operation time is very short , therefore , Intermittent opening MCLK ( Wake up the CPU) The energy-saving effect of this method is very obvious .
- SMCLK: Subsystem clock (Sub-main Clock) , It is designed to provide services for some on-chip and off-chip devices that need high-speed clocks , Such as timers and ADC Sampling, etc . When CPU When dormant , as long as SMCLK Turn on , Timers and ADC Still working ( Generally, the interrupt is triggered after the internal and external devices of the chip complete their work , Wake up the CPU To do follow-up work ).
- ACLK: Auxiliary clock (Auxillary Clock), The frequency of the auxiliary clock is very low , So even if it is turned on all the time, the power consumption is not large , Of course, it's OK to turn it off . The auxiliary clock can supply those on-chip and off-chip devices that only need a low-frequency clock , such as LCD controller , It can also be used to generate beat time base , Cooperate with timer to wake up intermittently CPU.
MCLK、SMCLK and ACLK The relationship between the three is the main force in a more vivid metaphor (MCLK)、 The first troops (SMCLK)、 Guard the sentry (ACLK) The relationship between .
- There is not much time to use the main force , Generally, they are in a state of rest , To save “ provisions ”( Power waste ).
- Problems that can be solved only by the leading forces , Don't use the main force , After the vanguard troops complete their tasks , Please come again .
- When there is no reality “ The enemy ” When , Both the main force and the leading force can rest , But put sentinels on guard , Find out “ The enemy ” Can wake up the main force at any time .
BCS+ Basic structure of module unit
MCLK、SMCLK and ACLK And its source structure in MSP430x2xx It is called Basic Clock Module+ unit , As shown in the figure below .
At first glance, the block diagram shown in the following figure is extremely complex , There are as many registers to set . But we need to understand a little bit , The designer of single chip microcomputer has finished all the things that can be completed for users , The reserved register must be controlled by “ master ” Control various switches . Compared with the design of actual hardware circuit will encounter various problems , Nothing is simpler than turning the switch . After understanding the design intention of the single chip microcomputer designer , Again with the help of Grace Configuring various registers will get twice the result with half the effort 、 have a well-thought-out plan .
The three boxes on the right side of the figure below are the three clocks used by the final MCU , The left shows the possible sources of these clocks , There are a series of source selection switches in the right box 、 Frequency division control switch 、 Output switch . The left part of the figure below is the possible source of the clock , In order to give consideration to accuracy 、 Cost and ease of use , The source of the clock is divided into 3 Categories: , Low frequency oscillator 、 high frequency ( Quartz crystal ) oscillator ( at present MSP430G Series MCU does not support ) And CNC oscillator .
Click on "Device Overview( Equipment Overview ) " link , You can view the peripheral modules available for configuration ( Describe in blue ).

The block diagram with background color can be clicked with the mouse , Are user configurable resources . The current is 3 There are , They are the clock (Oscillators Basic Clock System+),P1 mouth (Port P1), watchdog (Watchdog WDT+), Indicates that the current default configuration is enabled 3 Resources of modules . Click on other modules with background , You can configure the selected module .
In the above figure, there is a power drop-down box , Default display 1.8V, Some beginners think that how many volts will be set in this place in the future “ Inside ” How much voltage will be produced , The causality of this view is wrong . How many volts is the actual SCM power supply , How many volts should be selected in the box ,Grace It is necessary to know the actual supply voltage of single chip microcomputer , Because at low voltage , Some peripherals cannot be used ,Grace The function of the peripheral will be automatically shielded and configured .
We click the clock to configure , As shown in the figure below , Check... By default Enable Clock in my configuration( Enable the clock in my configuration ), And then there will be Overview、Basic User、Power User、Register Four buttons . The default is to stay at Overview state , So in the figure below Overview It is gray and cannot be clicked .
The clock - overview

This introduction Turn over as follows :
Introduce
Basic clock module +(BCS+) Support low system cost and ultra-low power consumption . Use three internal clockticks , Users can choose the best balance between performance and low power consumption . Under complete software control ,BCS+ It can be configured to work without any external components , Use an external resistor , Use one or two external crystals , Or use a resonator .
BCS+ An oscillator fail safe function is integrated , Can be detected LFXT1 and XT2 The oscillator of is faulty . If the corresponding crystal oscillator is turned on and does not work properly , Then the crystal oscillator fault bit LFXT1OF and XT2OF To be placed . As long as the fault condition exists , The fault bit is always set , If the enabled oscillator functions normally , It will automatically clear .
When oscillator failure is detected (LFXT1OF or XT2OF) when ,OFIFG The oscillator fault flag is set . If OFIE To be placed ,OFIFG Request one NMI interrupt . When interrupts are allowed ,OFIE Automatically reset .OFIFG The flag must be cleared by software . The source of the fault can be determined by checking each fault bit .
If detected as MCLK The power supply crystal oscillator is faulty ,MCLK Will automatically switch to DCO As its clock source .
Basic User Pattern
Click on Basic User after , As shown in the figure below , We have entered the basic configuration mode . This model is more appropriate to say “ A fool ” Pattern . We can see from the picture , Just pull down the menu , You can complete the configuration of the clock , There is no unnecessary nonsense .
For beginners who want to get started quickly , have access to Grace Of Basic User Mode configuration clock , In an instant . As shown in the figure below ,DCO The frequency can be set to 1/8/12/16MHz, this 4 Frequencies are factory calibrated , More accurate . If the external watch crystal is not welded , Low frequency signal source selection 12kHz Internal oscillator , Weld the watch crystal and choose 32.768kHz.
Power User Pattern
Click on Power User , As shown in the figure below , Configurable options suddenly increased . This is probably known BCS+ Graphical configuration mode for semi skilled workers of principle , Note that the lower right corner also includes the “ Interrupt event function ” Configuration of .
Part content Turn over : The system uses a low frequency oscillator . The frequency can be in 4kHz to 20kHz Change between . See specific equipment data sheet .
Note 1:
By enabling interrupt handlers ,Grace stay src In the folder InterruptVectors init.c A fully working interrupt service program is generated in the file . Users can go to ISR Insert code in the specified area of , And the code is preserved . When the user disables the interrupt handler , The code inserted by the user will remain at the bottom of the file , If the user re enables the interrupt handler , Will automatically reinsert . Users can also delete these codes manually , When it no longer …
Note 2:
Manual configuration DCO Frequency may cause +/-10% Frequency deviation of . Pre calibrated DCO Yes +/-3% Frequency deviation of . See the data sheet for more information .
Note 3:
Set a delay value in milliseconds according to the rise time of the system , To ensure that there is no violation VCC And MCLK The relationship between . It is strongly recommended to set a non default system clock frequency , Ensure the normal startup of the system .

For further understanding BCS+ Structure , Combined with the marked in the above figure 10 A knowledge , The following points 10 A summary to explain .
1. CNC oscillator DCO
MSP430G At present, series single-chip computers can only pass the internal numerical control oscillator DCO To get a high-frequency clock , In the future, models supporting high-frequency external crystal oscillators may be introduced .
DCO The principle of is actually an open-loop controlled oscillator ,DCO Module built-in series ( Oscillate ) resistance , Optional frequency range (RSELx common 4 position ,16 files ), That is to say RSELx Pipe rough adjustment . Next, divide the oscillation frequency (DCOx Yes 3 position , common 8 files , The gear step is about 10%), That is to say DCOx Be responsible for fine adjustment . The setting diagram of oscillation frequency range and gear division is shown in the figure below .
What if the rough adjustment and fine adjustment still fail to meet the requirements ? For example, as mentioned above DCOx Each frequency step is about 10%, If I want the frequency to only increase 5% What do I do ? In order to get more frequencies ,MSP430 Single chip microcomputer introduces the concept of fractional frequency division . As shown in the figure below , Using mixers Modulator, It can output alternately DCOx and DCOx+1 Two frequencies , If the 1:1 The proportion , It is equivalent to output DCOx+0.5 This gear frequency .
Of course, the mixer can also not press 1:1 mixing , register MODx common 5 position , Used to set two frequencies at 32 Proportion of pulses , The complete period after mixing (32 individual CLK) It can be expressed by the following formula :
t = ( 32 − M O D x ) ∗ t D C O + M O D x ∗ t D C O + 1 t=(32-MOD_x)*t_{DCO}+MOD_x*t_{DCO}+1 t=(32−MODx)∗tDCO+MODx∗tDCO+1
You may be curious about what you get in this way “ equivalent ” Can the frequency clock work ? The answer is, of course, useful , It can be used to configure the baud rate of communication . If MODx The set value is not 0, Obviously, the oscillation waveform obtained by mixing will “ shake ”, For occasions requiring high instantaneous stability of the clock, mixing should be avoided .
2. Factory pre calibration frequency
DCO With some models MSP430 Configured digital frequency locking ring (FLL) Different ,DCO It is not an oscillator with feedback , The error of open-loop output frequency is very large . in other words RSELx Rough reconciliation DCOx The fine tuning of is nonlinear . How to ensure DCO Output frequency accuracy ? At the time of delivery , Every single chip microcomputer has been calibrated 4 Frequency values (1/8/12/16MHz), Will this 4 Verification parameters of frequency values (RSELx/DCOx/MODx The value of ) It exists in the chip Flash Of Info A In the paragraph .
In the following BCS+ Initialization configuration code , Set up DCO by 1MHz, In fact, it is to call factory calibration parameters CALBC1_1MHZ and CALDCO_1MHZ.
void BCSplus_init(void) {
...
BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */
DCOCTL = CALDCO_1MHZ;
...
}
Since it is a verification parameter , Then every single chip computer will be different , MSP430G2553 Single chip microcomputer DCO Calibration parameters CALBC1_xMHz and CALDCO_xMHz stay Flash ROM The address in is shown in the following table .1 The height of a word 8 Bits are used to store CALBC1_xMHz Parameters , It will be used to configure BCSCTL1 register .1 The low of the words 8 Bits are used to store CALDCO_xMHz Parameters , It will be used to configure DCOCTL register .
- MSP430 You can read and write directly 1 A word (2 Bytes , because MSP430 Of CPU yes 16 Bit ).
- You can also read and write one byte only ( Addressing to bytes ).
- But you can't read it directly 1 position ( Unable to address in place ).

The last column in the above table is the base address and offset address (Tag Address and Offset), When we operate on a continuous memory , Macros are often used to define base addresses , Then operate the offset address method to increase the reliability of the program ( With the base address , It is not easy to write other memory segments by mistake ) And readability ( The offset address is very small , It's easy to see the rules ).
We can still do that CCS Check the calibration parameter value of single chip microcomputer in the software , Plug in LaunchPad Development board , Establish any project operation simulation , Then you can go to Registers Medium Calibration_Data Find CALDCO_xMHz and CALBC1_xMHz Each of them Value value . because Flash The value of the memory can be artificially rewritten , In the future, everyone will learn Flash When the controller , It is likely that misoperation will Calibration_Data Data deletion . Therefore, it is suggested that you put yourself on hand G2 Medium Calibration_Data write down , Keep it in reserve , In case of deletion , You can also find a way to recover .
Grace The code is configuring DCO by xMHz front , There is a code :“if (CALBC1_xMHZ != 0xFF)”, This is for judgment Flash Check whether the parameters are still in (Flash Once erased , All the seats are 1), To prevent misoperation .
3. Low frequency oscillator VLO
In order to save costs and simplify external circuits as much as possible ,MSP430x2xx A low-frequency oscillator is also integrated inside VLO, Used in place of 32.768kHz Watch crystal . The nominal value of the low frequency oscillator is 12kHz, It is associated with DCO equally , The actual frequency is affected by temperature and supply voltage ( Range 4kHz~20kHz).
VLO It is generally used in occasions that do not require high frequency accuracy .
4. Internal matching capacitance
Used to 51 Readers of SCM know , The crystal oscillator pin may need to be connected to a capacitor to work properly . Or based on the purpose of cost saving and simplifying the circuit , When using an external crystal oscillator , Optional... Can be provided by the MCU 1/6/10/12.5pF Crystal oscillator capacitor .
5. Delay start
Depending on the supply voltage ,MSP430 The maximum working frequency of single chip microcomputer is different . The following figure shows the running program ( read Flash ROM) And programming ( Erasure Flash ROM) The required supply voltage is the same as CPU Frequency relationship . for example ,MSP430 Minimum can 1.8V Power supply , But at this time, the highest working frequency is 6MHz, And can only run programs , Do not wipe Write Flash ROM.
When the single chip microcomputer is just powered on ,VCC It gradually reaches the rated value , If in VCC When it is very low, it will MCLK If the setting frequency is very high, it will conflict with the limiting conditions shown in the above figure . Set number ms Time delay of , wait for VCC Reconfigure after reaching the rated value MCLK Frequency can solve this problem . The specific code is :
if (CALBC1_8MHZ != 0xFF)
{
/* Adjust this accordingly to your VCC rise time */
__delay_cycles(10000); // wait for VCC Reach the rated value
DCOCTL = 0x00;
BCSCTL1 = CALBC1_8MHZ; /* Set DCO to 8MHz */
DCOCTL = CALDCO_8MHZ;
}
6. Automatic selection MCLK Source
MCLK The clock is provided to CPU Of , without MCLK SCM is “ die ”. therefore ,MSP430 There is an intelligent mechanism in , No matter what the software is set MCLK What is the clock source , Final CPU Always find one “ normal ” The clock makes itself “ Come alive ”. This is automatic selection MCLK, This function does not need to be set , Forcibly delivered .
7. Clock output
Theoretically MSP430 Single chip microcomputer 3 A clock MCLK、SMCLK、ACLK Can be exported , But some microcontrollers suffer IO Restrictions on the number of mouths , No reservation CLK outlet . such as MSP430G2553 Single chip microcomputer , Reserved SMCLK、ACLK outlet , however No, MCLK outlet .
8. Oscillator failure interrupt
When an external crystal oscillator is configured , The external crystal oscillator does not work properly ( No oscillation 、 Or the oscillation frequency is not high enough ), SCM has a protection mechanism ,MCLK Will automatically switch to using the internal DCO Work . meanwhile ,XT2OF or LFXT1OF Two error identification bits will be set (MSP430G2553 There is no corresponding high-frequency crystal oscillator XT2OF), An interrupt can be raised to inform the user of this event , Unless the external oscillator returns to normal , Otherwise, the error identification bit will remain . The frequency range of judging failure depends on the specific model .
9. Interrupt event handler
stay Grace in , You can directly name an interrupt event handler , This function will appear in the interrupt service subfunction in the future , This kind of writing is highly readable . Because the interrupt function itself is very scattered ( Even in different files ), Code written in interrupts is always hard to read , So try to write only the event handler in the interrupt “ Empty shell ”, And the actual interrupt event handling functions are collected into a file , Concentrated reading .
#pragma vector=NMI_VECTOR
__interrupt void NMI_ISR_HOOK(void)
{
/* Oscillator fault interrupt handler */
BCS_OF();
/* No change in operating mode on exit */
}
10. Exit the power saving option after interruption
MSP430 in , The energy saving settings before and after the interrupt can be modified in the interrupt service subfunction .Grace Provides a quick way to modify , Directly select from the drop-down menu .
Registers Pattern
Click on Registers , As shown in the figure below , all BCS+( The clock ) The relevant registers are suddenly listed . Some of these registers are checked with the mouse , Some combinations require mouse down , But all bits will be prompted when the mouse hovers . This mode , Belong to really understand BCS+ Principle people can configure .
Use Grace Change the system clock

After modifying the configuration ,Ctrl+S preservation , And click on the small hammer 
After compilation, there are more in the project src Folder , After unfolding, we get a series Grace The configuration file , among Basic clock system + The initialization file name of the module is BCSplus_init.c, This is the clock configuration we just set graphically .

Low power mode
MSP430x2xx A series of single chip computers CPU share 5 The two working modes are AM(Active Mode)、LPM0(Low Power Mode 0)、LPM1、LPM2、LPM3, Pictured 4.9 The current values in various working modes are shown . Compared with Active Working mode 300μA, frequently-used LPM3( Sentry alert ) The current of mode is less than 1μA, and LPM4 Mode power consumption 0.1μA Smaller than the battery leakage current , It can be used directly when it is turned off .
stay MSP430 In the single chip microcomputer , How to control the low power consumption mode ? We spend 10 Second, turn back to the principle block diagram shown in the figure below , Some switches are underlined , These switches decide whether to stop the oscillator , Whether to close the output .
- “ stop it ” and “ close ”, The difference between the two is that stopping the oscillator consumes less power . however , “ stop it ” If you want to restart the oscillator after , It takes time until the oscillator can stabilize its output , The length of this time can be found in the device specification of the specific model .
- Do not stop the oscillator , But turn off the output , You can quickly switch to the normal output state .
- The combination of all these switches constitutes the activity mode of the single chip microcomputer (ActiveMode) And the other 4 A low-power sleep mode (Low Power Mode), See the table below .

all 4 In one mode ,LPM0( The main force sleeps , The leading troops work ) and LPM3( The main force and leading forces are dormant , Only guard sentinels ) The most commonly used ,LPM4 When it is turned off .
Directly configure the system clock
We learned how to use Grace Configure clock , In fact the MSPG2553 Single chip microcomputer ,MCLK and SMCLK It's basically using DCO( No external high-frequency crystal oscillator is available ). Yes 32.768kHz Watch crystal , be ACLK choose 32.768Hz, No, just choose 12kHz Of VLO. therefore , It is also convenient to configure the clock directly , Call directly DCO Factory calibration parameters are sufficient .
- take MSP430G2553 The clock of is set to MCLK and SMCLK Are all 8MHz,ACLK Set to 32.768kHz.
DCOCTL = CALDCO_8MHZ; // After the factory calibration is retrieved, it is stored in Flash Parameters in
BCSCTL1 = CALBC1_8MHZ; // BCSCTL3 Parameters are not set by default
- take MSP430G2553 The clock of is set to MCLK and SMCLK Are all 16MHz,ACLK Set as internal low-frequency oscillator .
DCOCTL = CALDCO_16MHZ; // After the factory calibration is retrieved, it is stored in Flash Parameters in
BCSCTL1 = CALBC1_16MHZ;
BCSCTL3 |= LFXT1S1; // Set as internal low-frequency oscillator
- take MSP430G2553 The clock of is set to MCLK and SMCLK Are all 16MHz,ACLK Set to use 32.768kHz Crystal vibration and 4 frequency division .
DCOCTL = CALDCO_16MHZ; // After the factory calibration is retrieved, it is stored in Flash Parameters in
BCSCTL1 = CALBC1_16MHZ;
BCSCTL1 |= DIVA_2; // Supplement and modification BCSCTL Of DIVAx position ,4 frequency division
- take MSP430G2553 The clock of is set to MCLK4MHz,SMCLK by 2MHz,ACLK Set to use 32.768kHz Crystal oscillator .
DCOCTL = CALDCO_8MHZ; // First set to 8MHz
BCSCTL1 = CALBC1_8MHZ;
BCSCTL2 |= DIVM_1+DIVS_2; // Right again MCLK 2 frequency division ,SMCLK 4 frequency division
边栏推荐
- English grammar_ Demonstrative pronoun this / these / that / those
- MySQL advanced
- Risk control system, implemented by flink+clickhouse!
- Sword finger offer 47. the maximum value of gifts
- Know typescript
- Mass modify attribute values in objects in JS
- Unity3d eventsystem (event)
- Solve the problem that gd32f207 serial port can receive but send 00
- Each blogger needs to ask himself seven basic questions
- Lunch break train & problem thinking: thinking about the problem of converting the string formed by hour: minute: second to second
猜你喜欢

01 | opening words: teach you to build a blog website hand in hand

Setting up a dual machine debugging environment for drive development (vs2017)
![[training Day6] dream [priority queue] [greed]](/img/1b/309b53618b8a116862971799ce4e78.jpg)
[training Day6] dream [priority queue] [greed]

Talk about your transformation test development process

从服务器批量下载文件到本地

Introduction to fastdfs high availability

Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket

Duilib actual combat 1- imitate Baidu online disk login interface

ATL container - catlmap, crbmap

Batch download files from the server to the local
随机推荐
Framework API online viewing source code
[training Day8] [luogu_p6335] staza [tarjan]
Each blogger needs to ask himself seven basic questions
Review the code implementation of memcpy function
strlen函数剖析和模拟实现
01 | 开篇词:手把手教你搭建一个博客网站
纯C实现----------尼科彻斯定理
Flink Window&Time 原理
Hcip early summary
Working principle of envy of istio I
Sword finger offer 42. maximum sum of continuous subarrays
C form application treeview control use
The beginning of winter in the year of bitterness and ugliness
Bypass using the upper limit of the maximum number of regular backtracking
Luogu - p1616 crazy herb picking
[training Day9] light tank [dynamic planning]
Sword finger offer 40. minimum number of K
Substr and substring function usage in SQL
Basic idea of regularization
Pix2seq: Google brain proposes a unified interface for CV tasks!