1 | int main(void)
|
2 | {
|
3 | volatile unsigned int i; // volatile to prevent optimization
|
4 | volatile unsigned int conversion_result;
|
5 | WDTCTL = WDTPW + WDTHOLD; // Stop Watch Dog Timer
|
6 |
|
7 | ADC12CTL0 = REFON | REF2_5V | SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12
|
8 | //SHT1x (Sample-and-hold time) = 0000b -> N/A
|
9 | //SHT0x (Sample-and-hold time) = 0010b -> 64 ADC12CLK
|
10 | //MSC (Multiple sample and conversion) = 0b -> N/A
|
11 | //REF2_5V (Reference generator voltage) = 1b -> 2.5 V
|
12 | //REFON (Reference generator on) = 1b -> Reference on
|
13 | //ADC12ON (ADC12 on) = 1b -> ADC12 on
|
14 | //ADC12OVIE (overflow-int. enable) = 0b -> disabled
|
15 | //ADC12TOVIE (conversion-time-overflow int enable) = 0b -> disabled
|
16 | //ENC (Enable conversion) = 0b -> enable configuration
|
17 | //ADC12SC (Start conversion) = 1b -> Start conversion
|
18 | ADC12CTL1 = SHP;
|
19 | //CSTARTADDx (Conv. start address.) = 0000b
|
20 | // -> ADC12MEM0
|
21 | //SHSx (Sample-and-hold source) = 00b -> ADC12SC bit
|
22 | //SHP (Sample-and-hold pulse-mode select) = 0b
|
23 | // -> SAMPCON signal is sourced from the sample-input
|
24 | // signal.
|
25 | //ISSH (Invert signal S-H) = 0b -> not inverted.
|
26 | //ADC12DIVx (ADC12 clock divider) = 000b -> /1
|
27 | //ADC12SSELx (ADC12 clock source) = 00b -> ADC12OSC
|
28 | //CONSEQx (Conversion sequence mode) = 00b -> Single-
|
29 | // channel, single-conversion
|
30 | //ADC12BUSY (ADC12 busy) = xb -> read only
|
31 | ADC12MCTL0 = SREF_1 | INCH_0;
|
32 | //EOS (End of sequence) = 0b -> Not Used
|
33 | //SREFx (Select ref.) = 001b -> VR+=VREF+/VR-=AVSS
|
34 | //INCHx (Input channel select) = 0001b -> A1
|
35 |
|
36 | OA0CTL0 = OAP_0 | OAPM_1 | OAADC0;
|
37 | //OANx (Inverting input) = XXb -> not important
|
38 | //OAPx (Non-inverting input) = 10b -> DAC0 internal
|
39 | //OAPMx (Slew rate select) = 11b -> Fast
|
40 | //OAADC1 (OA output) = 1b -> output connected to A1
|
41 | //OAADC0 (OA output) = 0b -> output _not_ connected A1
|
42 | OA0CTL1 = OAFBR_3 | OAFC_4 | OARRIP;
|
43 | //OAFBRx (feedback resistor) = 0x60 -> x2.7 gain
|
44 | //OAFCx (OAx function) = 100b -> Non-inverting PGA
|
45 | //OARRIP = 1b -> OAx input range is limited
|
46 |
|
47 | /*
|
48 | OAFBR_0 => x1 gain
|
49 | OAFBR_1 => x1.3 gain
|
50 | OAFBR_2 => x2 gain
|
51 | OAFBR_3 => x2.7 gain
|
52 | OAFBR_4 => x4 gain
|
53 | OAFBR_5 => x5.3 gain
|
54 | OAFBR_6 => x8 gain
|
55 | OAFBR_7 => x16 gain
|
56 | */
|
57 |
|
58 | // P6SEL |= 0x01; // P6.0 ADC option select
|
59 | // Configure UCA0 for RS232
|
60 | uart_configure();
|
61 |
|
62 | ADC12CTL0 |= ENC; // Conversion enabled
|
63 |
|
64 | while (1)
|
65 | {
|
66 | ADC12CTL0 |= ADC12SC; // Start conversions
|
67 | while (!(ADC12IFG & 0x0001))
|
68 | ; // Conversion done?
|
69 | conversion_result = ADC12MEM0; // Access result, resets ADC12IFG0
|
70 | //rs232_printf("conversion_result = %d\n", conversion_result);
|
71 | conversion_result = (conversion_result * 0.610); //(2,5/4096*100=0.610)
|
72 | rs232_printf("res = %d\n", conversion_result);
|
73 | // rs232_printf("OA0CTL0 = %d\n", OA0CTL0);
|
74 | // rs232_printf("OA0CTL1 = %d\n", OA0CTL1);
|
75 |
|
76 | i = 1000; // SW Delay
|
77 | do
|
78 | i--;
|
79 | while (i != 0);
|
80 | // i = 65535; // SW Delay
|
81 | // do
|
82 | // i--;
|
83 | // while (i != 0);
|
84 | }
|
85 |
|
86 | return 0;
|
87 | }
|