1507 views|0 replies

1662

Posts

0

Resources
The OP
 

ADC10 multi-channel input of msp430g2553 [Copy link]

This post was last edited by Hot Ximixiu on 2020-12-1 22:05

msp430g2553 has 8 external channels for input. The following program will complete the 3-way input to control the on and off of 3 LEDs.
Register Description
msp430g2553 ADC10 register
Code Description
After being familiar with several registers of adc10, let's look at the code
1. ADC10CTL1 = INCH_5+CONSEQ_1; The control register sets the highest channel and conversion mode.
2. ADC10AE0|= BIT5+BIT4+BIT3; The input enable register sets the pin to be input.
3. Sampling times and storage location:
ADC10DTC1 = 0x03; Set the sampling times
unsigned int a[]={0};
ADC10SA = (unsigned int)a; Storage address
If p1.5, p1.4, p1.3 are input, sampled 3 times, and the channel sequence is single (conversion mode),
then a[0] stores the sampling result of p1.5, then a[1] stores the sampling result of p1.4, and then a[2] stores the sampling result of p1.3
If p1.5, p1.4, p1.3 are input, sampled 6 times, and the channel sequence is repeated (conversion mode)
, then a[0] stores the sampling result of p1.5, then a[1] stores the sampling result of p1.4, and then a[2] stores the sampling result of p1.3
Then a[3] stores the sampling result of p1.5, then a[4] stores the sampling result of p1.4, and then a[5] stores the sampling result of p1.3
eg: 4 channels and 4 repeated sampling
unsigned int adc[4];
unsigned int adc_temp[16];
for(i=0;i<4;i++)
adc =(adc_temp +adc_temp[i+4]+adc_temp[i+8]+adc_temp[i+12])>>2;divide by 4

#include <msp430.h>
unsigned int a[]={0};
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = INCH_5+CONSEQ_1; // A5/A4, single sequence
ADC10CTL0 = ADC10SHT_1 + MSC + ADC10ON +ADC10IE;
ADC10DTC1 = 0x03; // 2 conversions
ADC10AE0|= BIT5+BIT4+BIT3; // P1.3,2,1 ADC10 option select
P1DIR |= BIT0+BIT1+BIT2; // Set P1.0 output
for(;;)
{
ADC10CTL0 &= ~ENC;
ADC10SA = (unsigned int)a; // Data buffer start
while (ADC10CTL1 & ADC10BUSY); // Wait if ADC10 core is active
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

if (a[0] < 0x1FF)
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
if (a[1] < 0x1FF)
P1OUT &= ~BIT1; // Clear P1.1 LED off
else
P1OUT |= BIT1; // Set P1.1 LED on
if (a[2] < 0x1FF)
P1OUT &= ~BIT2; // Clear P1.2 LED off
else
P1OUT |= BIT2; // Set P1.2 LED on
}
}

// ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
#else
#error Compiler not supported!
#endif
{
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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