The A/D conversion module of TI's MSP430F5529 is at the P1.6 input end, named ADC12, and is an AD converter that uses a 12-bit digital register to store the conversion results. ***There are two reference voltages for conversion, the highest voltage VR+ and the lowest voltage VR- as the upper and lower limits of the conversion. If it is higher than or equal to VR+, the output is 0FFF, and if it is lower than or equal to VR-, the output is 0000. The digital value of the analog voltage Vin to be converted is calculated as Data=4095 x (Vin-VR-)/(VR+ -VR-). The program structure is as follows #include "msp430F5529.h" int tt=0,temp,kk; void delay(int ns) { while(ns--); } //******A/D conversion function settings****// void adc1() { P1SEL |=BIT6; //The converted analog signal is input from P1.6, and the conversion module is integrated inside ADC12CTL0 =ADC12ON + ADC12SHT0_8 + ADC12MSC; ADC12CTL1 =ADC12SHP + ADC12CONSEQ_2; ADC12MCTL0=ADC12SREF_0+ADC12INCH_6; ADC12CTL0 |=ADC12ENC; //////After a conversion is completed, a conversion interrupt is generated and the ADC interrupt function is called//// } int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT UCSCTL3 |=SELREF__REFOCLK; __bis_SR_register(SCG0); //disable the FLL control loop UCSCTL0=0X0000;// //Set lowest possible DCOx,MODxSCG0 UCSCTL1=DCORSEL_7; //Select DCO range 24MHz opreation //DCORSEL_x, where x can be 3, 4, 5, 6, 7 UCSCTL3=FLLD_0+731; //Set DCO Multiplier for 24MHz //(N+1)*FLLRef=Fdco //(731+1)*32768=24MHz //Set FLL DIV =fDCOCLK/2 /*__bis_SR_register(SCG0); //Enable the FLL control loopSCG0 UCSCTL4 |=SELA__DCOCLK+SELS__XT1CLK+SELM__DCOCLK;//MCLK Source select UCSCTL5 |=DIVPA_2; //ACLK output divide UCSCTL6 |=XT1DRIVE_3+XCAP_0; //XT1 cap */ P1DIR |= 0x01; // P1.0 output TA1CCTL0 = CCIE; // CCR0 interrupt enabled TA1CCR0 = 100; // Maximum count setting TA1CTL = TASSEL_2 + MC_2 + TACLR; // SMCLK, contmode, clear TAR __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts __no_operation(); // For debugger } // Timer1 interrupt service routine #pragma vector=TIMER1_A0_VECTOR __interrupt void TIMER1_A0_ISR(void) { if(kk==50) { kk=0; P1OUT ^= 0x01;// Toggle P1.0 } else kk++; TA1CCR0 += 10000; // Reload } #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR(void) { //Read the conversion result tt=ADC12MEM0; //The conversion data is stored in the 12-bit ADC12MEM0 register } ADC12 has 18 interrupt sources, ADC12IFG0----ADC12IFG15, overflow interrupt source ADC12OV, ADC12MEMx ADC12TOV, ADC12_A conversion time overflow. When ADC12MEMx stores the conversion result, the corresponding ADC12IFGx bit is set (changed to 1), and the corresponding ADC12IEx bit and GIE bit are also set to generate an interrupt request. //******************************************************************************* // MSP430G2x33/G2x53 Demo - ADC10, Sample A1, 1.5V, TA1 Trig, Set P1.0 if > 0.5V // // Description: A1 is sampled 16/second (ACLK/2048) with reference to 1.5V. // Timer_A is run in upmode and TA1 is used to automatically trigger // ADC10 conversion, TA0 defines the period. Internal oscillator times sample // (16x) and conversion (13x). Inside ADC10_ISR if A1 > 0.5Vcc, P1.0 is set, // else reset. Normal mode is LPM3.// //* An external watch crystal on XIN XOUT is required for ACLK *//
//
// MSP430G2x33/G2x53
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|RST XOUT|-
// | |
// >---|P1.1/A1 P1.0 |--> LED
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1; // TA1 trigger sample start
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
__enable_interrupt(); // Enable interrupts.
TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL0 |= ENC; // ADC10 Enable
ADC10AE0 |= 0x02; // P1.1 ADC10 option select
P1DIR |= 0x01; // Set P1.0 output
TACCR0 = 2048-1; // PWM Period
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 2047; // TACCR1 PWM Duty Cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
if (ADC10MEM < 0x155) // ADC10MEM = A1 > 0.5V?
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL0 |= ENC; // ADC10 Enable
ADC10AE0 |= 0x02; // P1.1 ADC10 option select
P1DIR |= 0x01; // Set P1.0 output
TACCR0 = 2048-1; // PWM Period
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 2047; // TACCR1 PWM Duty Cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
if (ADC10MEM < 0x155) // ADC10MEM = A1 > 0.5V?
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}TACCR0 = 30; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
LPM0; // Wait for delay.
TACCTL0 &= ~CCIE; // Disable timer Interrupt
__disable_interrupt();
ADC10CTL0 |= ENC; // ADC10 Enable
ADC10AE0 |= 0x02; // P1.1 ADC10 option select
P1DIR |= 0x01; // Set P1.0 output
TACCR0 = 2048-1; // PWM Period
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 2047; // TACCR1 PWM Duty Cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
if (ADC10MEM < 0x155) // ADC10MEM = A1 > 0.5V?
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
{
TACTL = 0;
LPM0_EXIT; // Exit LPM0 on return
}