1828 views|0 replies

2015

Posts

0

Resources
The OP
 

MSP430G2553 Study Notes [Copy link]

MSP430G2553 Overview
Low supply voltage range: 1.8V to 3.6V
Ultra-low power
– Run mode: 230μA (at 1MHz and 2.2V)
– Standby mode: 0.5μA
– Off mode (RAM retention): 0.1μ
5 power-saving modes
Ultra-fast wake-up from standby mode in less than 1μs
16-bit reduced instruction set (RISC) architecture with 62.5ns instruction cycle time
Basic clock module configuration
– Internal frequency up to 16MHz with four calibrated frequencies
– Internal ultra-low-power low-frequency (LF) oscillator
– 32kHz crystal
– External digital clock source
Two 16-bit Timer_A with three capture/compare registers each
Up to 24 I/O pins with touch sensing support
Universal Serial Communication Interface (USCI)
– Enhanced Universal Asynchronous Receiver Transmitter (UART) with automatic baud rate detection
– IrDA Encoders and Decoders
– Synchronous SPI
– I2C
On-chip comparator for analog signal comparison functions or slope A/D conversion
10-bit 200ksps A/D converter with internal reference, sample and hold, and auto-scan
Brown-out detector
Serial on-board programming, no external programming voltage required, programmable code protection with security fuse
On-chip emulation logic with Spy-Bi-Wire interface

The system clock
MSP430G2553 has three clock functions:
MCLK:
main clock, a clock specifically provided for CPU operation
SMCLK:
subsystem clock, specifically for some on-chip peripherals that require high-speed clocks, such as timers and ADC sampling
ACLK:
auxiliary clock, for those on-chip peripherals that only require low-frequency clocks, such as LCD controllers

//Set the clock of MSP430G2553 to: MCLK and SMCLK are both 16MHz, ACLK is set to the internal low-frequency oscillator
DCOCTL=CALDCO_16MHz; //Call out the parameters stored in Flash after factory calibration
BCSCTL1=CALBC1_16MHz;
BCSCTL3 |=LFXT1S1; //Set to internal low-frequency oscillator
//Set ACLK to use 32.768KHz crystal and divide by 4
BCSCTL |=DIVA_2;
//Set the clock of MSP430G2553 to: MCLK is 4MHz, SMCLK is 2MHz, ACLK is set to use 32.768KHz crystal
DCOCTL=CALDCO_8MHz; //Set to 8MHz first
BCSCTL1=CALBC1_8MHz;
BCSCTL2 |=DIVM_1+DIVS_2; // Divide MCLK2 and SMCLK4 again

GPIO and interrupt function
I/O port direction register: PxDIR
I/O port input register: PxIN
I/O port output register: PxOUT
Control internal pull-up and pull-down resistor register: PxREN
MSP430G2553 MCU P1 and P2 ports have interrupts
Whether to allow I/O interrupt register: PxIE
Interrupt flag register: PxIFG
Interrupt edge selection register: PxIES
MSP430G2553 MCU is a write bit operation, the example is as follows:

//Set P1.0 to 1, P1.1 to 0, and P1.2 to invert, without affecting other bits
P1OUT |=0X01; //Press bitwise "OR", equivalent to setting 1
P1OUT &=~0x02; //Press bitwise "AND" after inversion, equivalent to setting 0
P1OUT ^=0x04; //Press bitwise "XOR", equivalent to inversion
//Set P1.0, P1.1, and P1.2 to 1, without affecting other bits
P1OUT |=BIT0+BIT1+BIT2; //Batch settings can be performed using addition

In actual programming, macro definitions can be used to eliminate the inconvenience caused by "wired AND" logic. For example, setting P1.0 to "wired AND" logic output can be described by the following macro definition:

#define P10_ON P1DIR &=~BIT0 //I/O is set as input, which is equivalent to "wired AND" output 1
#define P10_OFF P1DIR |=BIT0;P1OUT &=~BITO //I/O is set as output, output 0

The steps for using external interrupts for MSP430G2553 are as follows:
1: Set the I/O port direction to input through PxDIR
2: Write PxIES to determine whether the edge of the interrupt is a rising edge, a falling edge, or both
3: If it is a mechanical button input, you can enable the internal pull-up (down) resistor through PxREN. According to the connection method of the button, set PxOUT to determine whether it is a pull-up resistor or a pull-down resistor
4: Configure the PxIE register to enable I/O interrupts, and "_enable_interrupts();" can enable general interrupts
5: In the interrupt subfunction, query the specific interrupted I/O port through the if statement. If it is a mechanical button input, the debounce code is also required
6: Write an event handling function based on the input of the specific I/O port
7: Before exiting the interrupt, use "PxIFG=0;" to clear the I/O interrupt flag

The overall structure of the Timer_A module of the MSP430G2553 microcontroller
includes a 16-bit timer and three capture/compare modules.
Since the capture module Caputre and the comparison module Comparator share the TACCRx register, the function of the capture module Caputre is to write TACCRx, while the function of the comparison module Comparator is to read the TACCRx module, so capture and comparison cannot be used at the same time. The CAP register bit is used to select the capture/compare working mode, CAP=0 for comparison, CAP=1 for capture.
CCRx can choose to detect the rising edge or the falling edge, or both. When CCRx is used to measure the signal pulse width, it is only necessary to record the rising edge moment and the falling edge moment respectively, and the subtraction of the two moments is the pulse width; when measuring the frequency, two rising moments are recorded continuously, and the subtraction is the period.
The difference between the external interrupt method and the capture method of the 51 single-chip microcomputer:
External interrupt method: edge detection - trigger interrupt - enter interrupt sub-function - read the timer value, at this time the read timer value and the actual edge time have a large error
Capture method: edge detection - immediately read the timer value TAR and latch it into the TACCRx register in the CCRx module - trigger interrupt - read TACCRx at any time. Such an error delay is only 10ns level The
comparison mode is used to set the timer cycle
The OUTMODx setting of the comparison module. In normal PWM, the leading PWM (rising edge at the main timer 0 position) configuration mode 7, the lagging PWM configuration mode 3; in PWM with dead zone, both outputs must be turned on, and one mode is 6, and the other must be 2.
Note: Although each Timer_A module has 3 capture/compare modules (CCR0/1/2), the register TACCR0 of CCR0 has been used to set the PWM frequency, so CCR1 and CCR2 can generate up to 2 independent PWM signals. The comparison value TACCR0 of CCR0 is used to set the period, and the comparison value TACCR1/2 of CCR1/2 is used to set the duty cycle.

WDT timer
WDT (Watch Dog Timer) is commonly known as watchdog.
The reset pin is set to NMI non-maskable interrupt. This interrupt has interrupt sub-functions like ordinary I/O external interrupts. The difference is that NMI interrupt does not need to open the general interrupt enable (because it is non-maskable, it has the highest priority). NMI interrupt enable will be automatically turned off after each NMI interrupt.

//When the watchdog is set to 1s reset timer, the code for "feeding the dog" is as follows:
WDTCTL=WDT_ARST_1000; //This macro definition contains the code for feeding the dog and resetting the watchdog timer value.

Variable knowledge points:
Global variables:
have global scope. Global variables only need to be defined in one source file to apply to all source files.
Static global variables:
have global scope. The difference between them and global variables is that if the program contains multiple files, they apply to the file in which they are defined and cannot apply to other files. That is, variables modified by the static keyword have file scope.
Local variables:
have local scope. They are automatic objects (auto). They do not exist all the time during the program execution, but only during the function execution. After a call to the function is completed, the variable is revoked and the memory it occupies is also recovered.
Static local variables:
have local scope. They are initialized only once and exist from the first time they are initialized until the end of the program execution.

int a = 0; //global variable
static int b=0; //static global variable
main()
{
int c; //local variable
static int d; //static local variable
}

State machine knowledge point:
state machine is also called finite state machine, or state machine for short. The concept of state machine comes from sequential logic circuit, and is further divided into Mealy state machine and Moore state machine. The difference between the two is whether the output result can be obtained based on the state.
The ideas of these two state machines are borrowed in the single-chip microcomputer, and two programming methods of single-chip microcomputer states are derived: "judging events in state" and "querying state in event".
Judgment of events in state:
This method is similar to the Mealy state machine (not completely the same), that is, in the switch statement, it is necessary to judge the Event to determine the output result.

//--------Query events in state (Mealy state machine)---------
switch(State)
{
case 0: if(Event_0) Action2(); //Path 1
if(Event_1) {State=2; Action0();} //Path 3
if(Event_2) State=2; //Path 4
break;
case 1: if(Event_0) State2; //Path 5
if(Event_2) {State=0; Action2();} //Path 2
break;
case 2: if(Event_1) {State=1; Action1();} //Path 6
break;
default: break;
}


Query state in event:
This method is similar to the Moore state machine (not completely identical). In the switch statement, there is no need to judge the Event. The result can be known from the current state.

//--------Query state in event (Moore state machine)---------
if(Event_0) //Interrupt or scan to know that Event0 has occurred
{
switch(State)
{
case 0: Action2(); break; //Path 1
case 1: State=2; break; //Path 5
default: break;
}
}
if(Event_1) //Interrupt or scan to know that Event1 has occurred
{
switch(State)
{
case 0: State=2; Action0(); break; //Path 3
case 2: State=1; Action1(); break; //Path 6
default: break;
}
}
if(Event_2) //Interrupt or scan to know that Event2 has occurred
{
switch(State)
{
case 0: State=2; break; //Path 4
case 1: State=0; Action2(); break; //Path 2
default: break;
}
}

Advantages and disadvantages of the two state machines and differences:
1: If Event is directly triggered by an interrupt, it can be judged without polling by if statement, then the Moore-type state machine (query state in event) has fast execution speed. This is because you only need to execute the switch (State) statement corresponding to the Event, and the State in the switch only needs to be judged to output the result.
2: If the Event itself needs to be polled to obtain, the code using the Mealy state machine (querying events in the state) is simpler. This is because there is only one switch (State) statement to query events in the state.

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list