MSP430:AD10

Publisher:温柔花香Latest update time:2017-11-03 Source: eefocusKeywords:MSP430  AD10 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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 the internal reference voltage 2.5v

 9 ADC10AE0 |= BIT5; //P1.5 ADC option

10 

11 }


Each time a conversion starts, the register needs to be set. A small function is written



1 void AD_Start(void)

2 {

3 ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion

4 }

Data processing after conversion




 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 }


 


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; //Multiple channels and multiple conversions, 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 is 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 is completed

13 

14 

15 //Data transfer control register 0 ADC10DTC0 is set to the default mode: single transfer block mode, stop after single block transfer

16 

17 ADC10DTC1 = 0x04; //Data transfer control register 1 4 conversions defines the number of transfers per block. A total of 4 samples are taken, so a single block is transferred 4 times

18 

19 //Then the transmission stops. Because it is a two-channel system, each channel samples and transmits data twice.

20 

twenty one 

22 ADC10AE0 |= BIT7+BIT6+BIT5+BIT4; // P1.0 P1.1 ADC option select Enable analog input pins A0 A1

twenty three 

24 // I don't know why, when P10 and P11 are both suspended, the sampling values ​​are different, and the suspended voltages measured with a 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 where data starts to be transmitted to the first address of the array adc_sample[]. Because the register ADC10SA and the conversion result are both 16 bits,

33 

34 //Address is forced to be converted to 16-bit int or unsigned int

35 

36 //It should also be possible to use a pointer to directly access the DTC storage area, but I haven't tried it yet

37 

38 

39 

40 }


The startup 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 {

twenty one 

twenty two 

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 }


Here unsigned int adc_result[8];


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


Keywords:MSP430  AD10 Reference address:MSP430:AD10

Previous article:MSP430 G2553 Timer Interrupt Summary
Next article:MSP430: Input Capture

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号