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.
Previous article:MSP430 G2553 Timer Interrupt Summary
Next article:MSP430: Input Capture
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- K210 face recognition environment construction process
- Charge up! The latest generation of ACF UCC28782 ultra-small fast charging adapter!
- Proteus simulation experiment of single chip microcomputer communication
- 【TI recommended course】#Power system design tools#
- Question about username
- NeoPixel simulates fluid physics motion
- BMP library management based on FPGA.pdf
- Making some preparations for the flag I set up on the forum this year (first time shopping at the ghost market)
- Open source scientific calculator based on STC32G
- FPGA---DDS Sine Wave Generator