1643 views|0 replies

1662

Posts

0

Resources
The OP
 

msp430fr2311 MCU ADC serial channel sampling [Copy link]

Use P1.2, P1.3, P1.4, and P1.5 as sampling channels, taking the demo's msp430fr231x_adc10_10.c file as an example.

1. Configure the above 4 pins to ADC mode:

P1SEL0 |= BIT2 + BIT3 + BIT4 + BIT5;

P1SEL1 |= BIT2 + BIT3 + BIT4 + BIT5;

2. According to the data, there are 4 adc sampling modes: single channel single, serial channel single, single channel multiple, serial channel multiple;

In this example, the serial channel is selected and the ADCCT register is set to L1ADCCONSEQ_1. When 430 reads the channel data, it starts from the highest channel until A0, so ADCMCTL0 is set to ADCINCH_5 (channel 5).

ADCMCTL0 |= ADCINCH_5; //The reference voltage is ADCC.

The adc sampling value is saved in the ADCMEM0 register, which is similar to the serial port receiving area. When configured as a serial channel, the value of ADCMEM is read cyclically, which is the sampled data.

Note: When reading sequential channels, you need to read from the highest channel to channel 0, for a total of 6 channels. Therefore, define the array u16 ADC_Result[6] and assign values in the ADC interrupt handler:

//Initialization function
void adc_init()
{
// Configure ADC A0~2 pins
P1SEL0 |= BIT2 + BIT3 + BIT4 + BIT5;
P1SEL1 |= BIT2 + BIT3 + BIT4 + BIT5;

// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;

// Configure ADC
ADCCTL0 |= ADCSHT_2 | ADCMSC | ADCON; // 16ADCclks, MSC, ADC ON
ADCCTL1 |= ADCSHP | ADCCONSEQ_1 | ADCSSEL_1; // ADC clock ACLK, sampling timer, s/w trig.,single sequence
ADCCTL2 = ADCRES; // 10-bit conversion results
ADCMCTL0 |= ADCINCH_5; // A5~2(EoS); Vref=avcc=3.3v
ADCIE |= ADCIE0; // Enable ADC conv complete interrupt

// Configure reference
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers
PMMCTL2 |= INTREFEN; // Enable internal reference
__delay_cycles(400); // Delay for reference settling
__no_operation();
}


// ADC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
{
case ADCIV_NONE:
break;
case ADCIV_ADCOVIFG:
break;
case ADCIV_ADCTOVIFG:
break;
case ADCIV_ADCHIIFG:
break;
case ADCIV_ADCLOIFG:
break;
case ADCIV_ADCINIFG:
break;
case ADCIV_ADCIFG:
ADC_Result = ADCMEM0;
if(i == 0)
{
__bic_SR_register_on_exit(LPM0_bits); // Exist LPM0
}
else
{
i--;
}
break;
default:
break;
}
}

此时,ADC_Result[0]为通道0,ADC_Result[1]为通道1,依次。

3. Conversion of sampling values

The ADC of 2311 is 10 bits and the reference voltage is 3.3V, so


ADC_Result[6] is defined as u16, not u8.

4. Notes

With the above settings, the ADC needs to exit low power consumption and restart after completing a single conversion. Start it in a timer or while(1) loop.

while(ADCCTL1 & ADCBUSY); // Wait if ADC core is active
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
i = 5; // Reassign array index

During debugging, I put i=5 before restarting, and found that the data of the channels in the array would be misplaced. For example, the data of channel 3 is in ADC_Result[2], which should be in ADC_Result[3]. It is better to put it here!

5 Follow-up
Because the selected chip frame is too small, the sampling data of the ADC is not averaged.
If averaging is required, configure the sampling mode to the serial multiple sampling channel, ADCCONSEQ_3.
The number of repetitions is limited by the size of the data. Define u16 ADC_Result[30], execute ADC_Result = ADCMEM0, when i=30, jump out of low power consumption.
The data stored in the array is [A5, A4, A3, A2, A1, A0, A5, A4, A3, A2, A1, A0,… ], and the reader can process the data by himself.

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