1671 views|0 replies

1668

Posts

0

Resources
The OP
 

MSP430F5438 ADC12 Study Notes [Copy link]

1. Introduction
In recent days, I have practiced the ADC12 function of MSP430. Although the AD function on the chip is relatively simple, I have learned some "tricks". This "tricks" is the difference between MSP430F5438A and MSP430F5438. Here, an example is used to illustrate the use of the on-chip ADC. First, the functions of UART and timer 1S overflow are realized. On the basis of the above functions, the AD conversion result is printed every 1S. The conversion channel is directed to channel 11, which corresponds to half of the interpolation of AVCC and AVSS. Since there is only one inductor connection between AVCC and the output of LDO, it can be understood that the conversion result is half of the LDO output voltage. If it is doubled, it is the actual output result of LDO. In the development board used in this article, the LDO output is 3.3V, and all printed results are as close to 3.3V as possible.
2. Code implementation and output results
Code implementation
// Clock default
// FLL clock FLL selects XT1
// Auxiliary clock ACLK selects XT1 32768Hz
// Main system clock MCLK selects DCOCLKDIV 8000000Hz
// Subsystem clock SMCLK selects DCOCLKDIV 8000000Hz
// TA1 selects ACLK, the maximum count value is 32768, and the interrupt frequency is 1HZ

#include <msp430.h>
#include <stdio.h>
#include <stdint.h>
void clock_config(void);
void select_xt1(void);
void dco_config(void);
void adc12_config(void);
void uart_config(void);
char second_flag = 0; // 1S flag

int main(void)
{
clock_config(); // Initialize clock
adc12_config(); // Initialize ADC12
uart_config();

TA1CCTL0 = CCIE; // Enable T1CCR0, compare match interrupt
TA1CCR0 = 32768; // Initialize the maximum value, the compare match interrupt frequency is 32768/32768 = 1Hz
TA1CTL = TASSEL_1 + MC_1 + TACLR; // Select ACLK, the maximum value is CCR0, clear the count value

_EINT(); // Initialize global interrupt

while(1)
{
if( second_flag )
{
second_flag = 0; // 1s time to

ADC12CTL0 |= ADC12SC; // Start conversion
while ( !(ADC12IFG & BIT0) ); // Wait for the conversion to complete

// The converted channel is channel 11 (AVCC-AVSS)/2;
// The conversion accuracy is 12 bits at this time-4096
// AVCC is connected to the output of LDO through an inductor
// Print the LDO output voltage and retain 3 bits of accuracy
float ldo_voltage = ADC12MEM0 / 4096.0 * 3.3 * 2;
printf("LDO Voltage %.3f\r\n",ldo_voltage);
}
}
}

void clock_config(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
select_xt1(); // Select XT1
dco_config(); // ACLK = XT1 = 32.768K
// MCLK = SMCLK = 8000K
}

void select_xt1(void)
{
// Start XT1
P7SEL |= 0x03; // P7.0 P7.1 peripheral function
UCSCTL6 &= ~(XT1OFF); // XT1 turns on
UCSCTL6 |= XCAP_3; // internal capacitor
do
{
UCSCTL7 &= ~XT1LFOFFG; // Clear XT1 error flag
}while (UCSCTL7&XT1LFOFFG); // Check XT1 error flag
}

void dco_config(void)
{
__bis_SR_register(SCG0); // Disable FLL function
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // DCO maximum frequency is 16MHz
UCSCTL2 = FLLD_1 + 243; // Set DCO frequency to 8MHz
// MCLK = SMCLK= Fdcoclkdiv = (N+1)X(Ffllrefclk/n)
// N is the only value that needs to be calculated
// Ffllrefclk FLL reference clock, default is XT1
// n takes the default value, which is 1
// (243 + 1) * 32768 = 8MHz
__bic_SR_register(SCG0); // Enable FLL function

// Necessary delay
__delay_cycles(250000);

// Clear error flags
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
// Clear all oscillator error flags
SFRIFG1 &= ~OFIFG; // Clear oscillator error
}while (SFRIFG1&OFIFG); // Wait for clearing to complete
}

void adc12_config(void)
{
// Only operate when ADC12ENC is reset
// ADC12SHT1X ADC12SHT0X ADC12MSC ADC12REF2_5V ADC12REFON ADC12ON
ADC12CTL0 &= ~ADC12ENC;

// Set the sample and hold time, the maximum time period to improve the conversion accuracy
// Note that MSP430F5438 does not have a REF module, the on-chip reference is invalid
// Operate ADC12REF2_5V, ADC12REFON is meaningless
ADC12CTL0 = ADC12SHT0_15 + ADC12SHT1_15 + ADC12ON;
// ADC12CTL0 = ADC12SHT0_15 + ADC12SHT1_15 + ADC12ON +
// ADC12REF2_5V + ADC12REFON;
// Sample hold pulse comes from sampling timer
ADC12CTL1 = ADC12SHP;
// Turn off internal temperature detection to reduce power consumption, pay attention or operate otherwise to modify the conversion accuracy
ADC12CTL2 |= ADC12TCOFF;
// Select AVCC for reference voltage, and select 11 channels——(AVCC-AVSS)/2
ADC12MCTL0 = ADC12SREF_0 + ADC12INCH_11;

__delay_cycles(75);
// ADC12 enables
ADC12CTL0 |= ADC12ENC;
}

void uart_config(void)
{
P3SEL = 0x30; // Select the multiplexing function of P3.4 and P3.5

UCA0CTL1 |= UCSWRST; // Software reset
UCA0CTL1 |= UCSSEL_1; // Select ACLK clock
UCA0BR0 = 3; // Look up the table to get
UCA0BR1 = 0; // UCA0BRX and UCA0MCTL values
UCA0MCTL |= UCBRS_3 + UCBRF_0; //
UCA0CTL1 &= ~UCSWRST; //

UCA0IE |= UCRXIE; // Enable receive interrupt
}

int putchar(int ch)
{
UCA0TXBUF = ch;
while(!(UCA0IFG & UCTXIFG));
return ch;
}

#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
second_flag = 1;
}


Figure 1 Reference voltage AVCC (3.3V)
3. Some points to note
3.1 Increase the sampling time
If conditions permit, the sampling time can be increased as much as possible, so that the conversion result can be more stable.
3.2 MSP430F5438 does not have a REF module
Now (October 2013), the sample code or data sheet reference manual that can be downloaded from the TI official website are all centered on the MSP430F5438A. However, many MCUs on the market are still MSP430F5438. In fact, there is a difference between MSP430F5438A and MSP4305438. MSP430F5438 does not have a REF module, so using the on-chip 2.5 reference power supply is still unstable. You can test it through the following implementation. The target of AD conversion is still LDO output.
The following parts of the code need to be modified
First:
ADC12CTL0 = ADC12SHT0_15 + ADC12SHT1_15 + ADC12ON; Modify to
ADC12CTL0 = ADC12SHT0_15 + ADC12SHT1_15 + ADC12ON +
ADC12REF2_5V + ADC12REFON;
Use to open the on-chip 2.5V reference power supply
Second:
ADC12MCTL0 = ADC12SREF_0 + ADC12INCH_11; Modify to
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_11;
Convert the reference voltage to Vref, that is, modify the 2.5V reference power supply set in 1

Third:
float ldo_voltage = ADC12MEM0 / 4096.0 * 3.3 * 2; Modify to
float ldo_voltage = ADC12MEM0 / 4096.0 * 2.5 * 2;
Replace the conversion formula, the reference voltage changes from 3.3V to 2.5V

The output results are as follows. It is found that the output voltage of LDO is 3.4V, which is 0.1V higher than the actual voltage.

Figure 2 Reference voltage VREF (2.5V)

Figure 3 MSP430 reference manual description

This post is from Microcontroller MCU
 

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