MSP430 tutorial 14: MSP430 microcontroller adc12 Module

Source: Internet
Author: User

MSP430Modulus conversion module-adc12
The adc12 module of MSP430 is a 12-bit precision A/D conversion module, which features high speed and versatility. Most of them have built-in ADC modules, while some films without ADC modules can also achieve AD conversion by using the built-in analog comparator. In the product series, we can simply understand their ADC functions through the following list.

Series of ADC functions to achieve conversion Accuracy
Msp430x1xx2 comparator achieves 10 bits
12-bit msp430f13x ADC Module
12-bit msp430f14x ADC Module
12-bit msp430f43x ADC Module
12-bit msp430f44x ADC Module
MSP430X32X ADC Module 14-bit

The following figure shows that the adc12 module consists of the following parts: the input 16 analog switch, the ADC internal voltage reference source, the adc12 kernel, and the ADC clock source, collection and holding/trigger source, ADC data output, and ADC control registers.

Input 16 analog switches
The 16-way analog switch consists of 8 analog signal inputs outside the IC, 4 internal reference power inputs, 1 internal temperature sensor source and AVCC-AVSS/2 voltage source inputs. The external 8-channel input from the A0-A7 is mainly the analog variable signal during the external measurement. The four internal channels are veref + ADC internal reference Power Supply output main end, vref-/veref-ADC internal reference Power Supply negative end (internal/external ). 1-way AVCC-AVSS/2 voltage source and 1-way internal temperature sensor source. The on-chip temperature sensor can be used to measure the temperature on the chip, which can be used for some useful control during design. It is used more in actual applications. Other power supply reference source inputs can be used for adc12 verification and self-calibration during design.

ADC internal voltage reference source
The ADC voltage reference source is used for the adc12 kernel as a benchmark signal, which is an essential part of the ADC. In the adc12 module, the quasi-voltage source can be set to six different combinations through software. Avcc (VR +), vref +, veref +, AVSS (VR-), vref-/veref -.

Adc12 Kernel
The modules and kernels of adc12 are shared. The frontend analog switches are used to complete the collection input respectively. Adc12 is a 12-bit ADC kernel with one-bit Nonlinear Differential error and one-bit Nonlinear Integral Error. Two reference voltages are used in kernel conversion. One is the reference of the relative maximum input value, when the analog variables output by the analog switch are greater than or equal to the maximum value, the output number of the ADC kernel is full range, that is, 0 xfff; the other is the minimum value, when the analog variable size output by the analog switch is equal to or equal to the maximum value, the output number of the ADC kernel is the lowest range, that is, 0x00. The two reference voltages can be programmed and set through software.

ADC clock source
The clock sources of adc12 include adc12osc, aclk, mclk, and smclk. By programming, you can select one of the clock sources and select proper frequency division.

Collection and persistence, trigger source part
The adc12 module has a good collection and maintenance circuit, and is applied flexibly without being set. For more information about this, see the register description in the manual. We will make up this part later.

ADC data output
Each time the ADC kernel completes the conversion, it will store the output results on the corresponding channel to the corresponding channel buffer units, with a total of 16 channel buffer units. At the same time, the buffer units of 16 channels have corresponding control registers for more flexible control.

ADC control register
Adc12ctl0 conversion control register 0
Adc12ctl1 conversion control register 1
Adc12ie interrupt enable register
Adc12ifg interrupt mark register
Adc12iv interrupt vector register
ADC12MEM0-15 storage control registers 0-15
ADC12MCTL0-15 storage control registers 0-15

MSP430 adc12Module structure

 

Adc12Routine
//************************************** ****************************************

# Include <export x14x. h>
//************************************** ******
// Table area
Unsigned char number_table [] = {'0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9 '};
Unsigned char display_buffer [] = {0x00,0x00,0x00,0x00, 0xff };

// ******************** Baud rate *********** 300 600 1200 2400 38400 76800 115200 const
// ************************************ [0] ** [1] ** [2] * [3] ** [4] ** [5] ** [6] ** [7] ** * [8] **** [9] *
Unsigned char baudrateubr0 [] = {0x6d, 0x36, 0x1b, 0x0d, 0x06,0x03, 0xa0, 0xd0, 0x68, 0x45 };
Unsigned const char baudrateubr1 [] = {0x00,0x00,0x00,0x00,0x00,0x00, 0x01, 0x00, 0x00, 0x00 };
Unsigned const char baudrateumctl [] = {0x22, 0xd5, 0x03, 0x6b, 0x6f, 0x4a, 0xc0, 0x40, 0x40, 0x4a };

Unsigned char;
// Variable Area
Unsigned int adc0;
// Subroutine Declaration
Void Init (void); // Initialization
Void adc12setup (void); // adc12 Initialization
Void baudratesetup (unsigned char U0); // uart0 Initialization
Void data_converter (unsigned char * P, unsigned int vaule); // data transformation
Void send_data (unsigned char * P); // array sent through the serial port
//************************************** ******
Void main (void)
{
Init ();
// Main Loop
For (;;)
{
Lpm0;
Adc12ctl0 | = adc12sc; // sampling open. After the adconversion is complete (adc12busy = 0), the adc12sc is automatically reset;
While (adc12ifg & bit0) = 0); // The conversion ends.
Adc0 = adc12mem0; // read the converted data value and clear the adc12ifg0 flag
Data_converter (display_buffer, adc0); // Data Conversion
Send_data (display_buffer); // send data
}
}

//************************************** **************************************** **
Void Init (void)
{
Wdtctl = wdtpw + wdthold; // stop wdt
P1dir = 0x01; p1out = 0x0f; // led settings
Baudratesetup (6 );
Adc12setup ();
_ Eint (); // enable global interrupt
}

//************************************** **************************************** ****
// The serial port is interrupted and the lpm0 mode is exited.
# Pragma vector = usart0rx_vector
_ Interrupt void usart0_rx (void)
{
Lpm0_exit;
}

//************************************** **************************************** ****
// Adc12 Initialization
Void adc12setup (void)
{
// Set adc12 **************************
P6sel | = 0x01; // use A/D channel A0
Adc12ctl0 = adc12on; // enable the adc12 kernel and set sht0 = 2 (n = 4)
Adc12ctl1 = SHP; // select the sampcon signal as the sampling timer output.
// Adc12 internal reference voltage settings
Adc12ctl0 | = ref2_5 V; // The internal reference voltage is 2.5 V.
Adc12ctl0 | = refon; // internal reference voltage on
Adc12mctl0 | = sref_1; // R ++ = 2.5 v r-= VSS
// Conversion allowed
Adc12ctl0 | = ENC; // conversion allowed (rising edge)
Adc0 = 0x00;
}

//************************************** **************************************** ****
// Uart0 Initialization
Void baudratesetup (unsigned char U0)
{
Unsigned int I;
If (U0> 5) // when U0> 5, xt2 is enabled
{
Bcsctl1 & = ~ Xt2off; // start xt2,
Do
{Ifg1 & = ~ Ofifg; // specifies the oscfault flag.
For (I = 0xff; I> 0; I --); // delay wait
}
While (ifg1 & ofifg )! = 0); // check the oscfault. The conversion is complete when the value is 0.
Bcsctl2 | = sels; // smclk is xt2
}
// Uart0
P1out = 0x00;
If (U0> 5) {utctl0 = ssel1;} // clock source: smclk
Else {utctl0 = ssel0;} // clock source: aclk
Uctl0 & = ~ Swrst; // swrst reset, which is allowed by usart
Uctl0 = char; // 8bit
Me1 | = utxe0 + urxe0; // enable tx0, rx0
Ie1 | = urxie0; // RX enabling
Ubr00 = baudrateubr0 [U0]; // Low Frequency Divider factor
Ubr10 = baudrateubr1 [U0]; // High Frequency Divider factor
Umctl0 = baudrateumctl [U0]; // baud rate adjustment factor
P3sel | = 0x30; // convert p3.4 to 5 using the peripheral module = usart0 txd/rxd
P3dir | = 0x10; // set p3.4 to output (sent), and p3.5 to input (received) by default)
}

//************************************** **************************************** ****
// Data transformation
Void data_converter (unsigned char * P, unsigned int value)
{
Unsigned int m, n, j = 0;
P [0] = number_table [value/1000];
M = Value % 1000;
P [1] = number_table [m/100];
N = m % 100;
P [2] = number_table [N/10];
J = n % 10;
P [3] = number_table [J/1];
}

//************************************** **************************************** ****
// Array sent through the serial port
Void send_data (unsigned char * P)
{Unsigned int N;
IBD = rxbuf0;
For (n = 0; P [N]! = 0xff; n ++)
{
While (ifg1 & utxifg0) = 0); // usart0 sends utxifg0 = 1, indicating that utxbuf is ready to send a character
Txbuf0 = P [N];
}
}
//************************************** **************************************** ****
// The End Of The adc12 Module Routine

MSP430 tutorial 14: MSP430 microcontroller adc12 Module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.