2284 views|1 replies

1668

Posts

0

Resources
The OP
 

MSP430:AD10 [Copy link]

The MSP430G2553 used is AD10, which normally has 8 outputs, P1.0-P1.7 is A0-A7

There are seven registers,

The reference voltage can be VCC or the internal reference voltage 1.5V or 2.5V

The reference clock can be the internal ADC10OSC

Maximum conversion rate up to 200ksps

There are four conversion modes: single channel single time, sequence channel single time, single channel multiple times, sequence channel multiple times. When multiple conversions are performed, the DTC function will be used to prevent the data from being overwritten before it is retrieved.

In the single-channel example program, channel 5 is enabled, which is P1.5.


1 void AD_Channel5_Config(void)
2 {
3 /* Configure ADC Channel */
4 ADC10CTL1 = INCH_5 + ADC10DIV_0 ; // Channel 5, ADC10CLK
5
6
7 ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
8 //SREF_1+REFON +REF2_5V means using internal reference voltage 2.5v
9 ADC10AE0 |= BIT5; //P1.5 ADC option
10
11 }
Single channel single
Each time you start a conversion, you need to set the register, so I wrote a small function


1 void AD_Start(void)
2 {
3 ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion
4 }
Start conversion
Process the converted data


1 #pragma vector=ADC10_VECTOR
2 __interrupt void ADC10_ISR (void)
3 {
4 int data;
5 float shuju,c;
6 char a[4];
7 data = ADC10MEM;
8 shuju = ((double)data/1024)*2.5 ;
9 c =shuju;
10 a[0]= ((int)c%10+0x30);
11 a[1]= 0x2e;
12 a[2]= ((int)(c*10)%10+0x30 );
13 a[3]= ((int)(c*100)%10+0x30);
14
15 uart_send_str(a);
16 __delay_cycles(5);
17 uart_send_huiche();
18 // uart_send_ch((char)(ADC10MEM*25/1024));
19 }
Interrupt processing data

The multi-channel is also adjusted, a few points to explain

First, start the MSC bit in ADC10CTL0

Then ADC10CTL1 = CONSEQ_3 + INCH_7; CONSEQ selects the conversion mode, which is multi-channel multiple times. The INCH bit behind is the highest channel bit. Because I use four channels 4-7, the highest INCH_7

Data transfer control register 0 ADC10DTC0 is set to the default mode: single transfer block mode, stop after single block transfer. No operation is required here

ADC10DTC1 = 0x04; Set the number of conversions. Here I only convert once and then stop. Because there are four channels, the number is 4. The number of conversions = number of channels * number of conversions per channel

ADC10AE0 |= BIT7+BIT6+BIT5+BIT4; Enable these four channels

ADC10SA =(unsigned int) adc_result; //Data transfer start address register Set the start address of DTC Data buffer start

It is worth noting here that the array's first address needs to be passed in. The ADC10SA adc_result; I wrote before did not compile, but it was OK after adding the preceding (unsigned int). I don't understand this.

Because my definition unsigned int adc_result[];

Anyway, the program will be OK after the changes here.

The code is given below


1 void AD_MultiChannel_4_Config(unsigned int adc_result[])
2 {
3 ADC10CTL1 = CONSEQ_3 + INCH_7; // Multi-channel multiple conversion, the maximum conversion channel is A1
4
5
6 ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE + REF2_5V+ REFON + SREF_1; // ADC10ON, interrupt enabl
7
8 // Sample hold time is 16 x ADC10CLKs, ADC core is on, interrupt enabled MSC multiple conversion selection is on
9
10 // If MSC is set, the trigger source needs to be triggered once when the conversion starts for the first time, and subsequent conversions will be automatically performed Interrupt enable
11
12 // When using DTC, an interrupt is generated when a block transfer ends
13
14
15 // Data transfer control register 0 ADC10DTC0 is set to the default mode: single transfer block mode, stop after a single block transfer
16
17 ADC10DTC1 = 0x04; //Data transfer control register 1 4 conversions defines the number of transfers in each block. A total of 4 samples are sampled, so a single block is transferred 4 times
18
19 //Then the transfer is stopped. Because it is two channels, each channel samples and transfers data twice
20
21
22 ADC10AE0 |= BIT7+BIT6+BIT5+BIT4; // P1.0 P1.1 ADC option select Enable analog input pins A0 A1
23
24 //For some reason, when P10 P11 are both floating, the sampled values are different, and the floating voltages measured by the voltmeter are different, but when both are connected to the sampling source,
25
26 //The sampling is the same
27
28
29 while (ADC10CTL1 & BUSY);
30 ADC10SA =(unsigned int) adc_result; //Data transfer start address register Set the start address of DTC Data buffer start
31
32 //Set the address of data transfer start to the first address of array adc_sample[], because register ADC10SA and conversion result are both 16 bits, so
33
34 //Address must be converted to 16-bit int or unsigned int
35
36 //It should also be possible to use pointers to directly access the storage area of DTC, but I haven't tried it yet
37
38
39
40 }
Multi-channel setting
Start AD code is the same as before


1 #pragma vector=ADC10_VECTOR
2 __interrupt void ADC10_ISR (void)
3 {
4 int data;
5 float shuju,c;
6 char a[4];
7 /* data = ADC10MEM;
8 shuju = ((double)data/1024) *2.5;
9 c =shuju;
10 a[0]= ((int)c%10+0x30);
11 a[1]= 0x2e;
12 a[2]= ((int)(c*10)%10 +0x30);
13 a[3]= ((int)(c*100)%10+0x30);
14
15 uart_send_str(a);
16 __delay_cycles(5);
17 uart_send_huiche();
18 */
19 for(data=0;data<8;data++)
20 {
21
22
23 shuju = ((double)adc_result[data]/1024)*2.5;
24 c =shuju;
25 a[0]= ((int)c% 10+0x30);
26 a[1]= 0x2e;
27 a[2]= ((int)(c*10)%10+0x30);
28 a[3]= ((int)(c*100)% 10+0x30);
29
30 uart_send_ch((char)data+0x30);
31 uart_send_ch(' ');
32 uart_send_str(a);
33 __delay_cycles(5);
34 uart_send_huiche();
35 __delay_cycles(5);
36
37 }
Interrupt data processing
Here unsigned int adc_result[8];

The test is basically OK, but more tests are needed. Currently, the resources on hand are limited.

This post is from Microcontroller MCU

Latest reply

Thanks for sharing, I'll learn from it.   Details Published on 2020-12-10 21:41
 

2618

Posts

0

Resources
2
 

Thanks for sharing, I'll learn from it.

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