ad06a89aa9ea87bc6fe317cfaaa1de4a12ecb8bc
[goodfet] / firmware / include / adc.h
1 /*! \file adc.h
2
3         \author Scott Livingston
4
5         \brief Prototypes for ADC application.  Note that this code was
6                written only with the x2274 chip and GoodFET31 in mind;
7                specifically, pin 5 of the (JTAG) header is sampled.
8                Supporting x2618, x1611/12 and other GoodFET boards remains!
9                For timing considerations, see at least Section 20.2.5
10                "Sample and Conversion Timing" (on page 589?) of msp430x2xx
11                family manual.
12
13         \date September 2010
14 */
15
16
17 // Identical to that in command.h, but to avoid cyclic dependencies...
18 #define u8 unsigned char
19 #define u16 unsigned int
20 #define u32 unsigned long
21
22
23 //! Initialize ADC10 module (specific to 2xx chip family).
24 void init_adc10();
25
26 //! Uninit/stop ADC10 module (specific to 2xx chip family).
27 void uninit_adc10();
28
29 //! Return a single, instantaneous sample.
30 u16 sample_adc10();
31
32 //! Fill cmddata string; sampling repeatedly at a fixed rate.
33 u16 nsamples_adc10( u8 N_count, //! Number samples to obtain (bounded w.r.t. cmddata)
34                                                                                 u8 t_sample, /*! sample-and-hold time; this is
35                                                                                                                                      written directly to ADC10SHTx
36                                                                                                                                                  field of ADC10CTL0 register;
37                                                                                                                                                  possible values are
38                                                                                                                                                  00   4 ADC10CLK ticks,
39                                                                                                                                                  01   8 ADC10CLK ticks,
40                                                                                                                                                  10  16 ADC10CLK ticks,
41                                                                                                                                                  11  64 ADC10CLK ticks. */
42                                                                                 u8 clock_div ); /*! Value by which to divide SMCLK
43                                                                                                                                                           (which is assumed to be 16
44                                                                                                                                                           MHz), then giving
45                                                                                                                                                           ADC10CLK.
46                                                                                                                                                                 Possible values are 1..8
47                                                                                                                                                                 Cf. Fig. 20-1 (on page 585?)
48                                                                                                                                                           of the msp430x2xxx family
49                                                                                                                                                           manual. */
50
51
52 //! Command codes
53 #define ADC10_INIT    0x81 //! Initialize ADC10 module (i.e., get ready for sampling).
54 #define ADC10_UNINIT  0x82 //! Uninitialize (or "stop") ADC10.
55 #define ADC10_1SAMPLE 0x83 //! Capture a single sample.
56
57 /*! Capture a sequence of samples at a constant rate and write result
58     till requested number of samples is acquired or cmddata array is
59     filled, whichever is smaller. Hence, in the maximum length case,
60     (CMDDATALEN-4)/2 10-bit samples are obtained (128 total using
61     x2274 chip).
62
63     The command has several possible formats, switched according to
64     the length of received command data (from client). See above
65     comments about nsamples_adc10 function for meaning of ``t_samlpe''
66     and ``clock_div.''
67     
68     length 0  =>  max sample sequence length, t_sample = 3, clock_div = 8;
69            1  =>  user-specified sequence length, t_sample = 3, clock_div = 8;
70            3  =>  user-specified length, t_sample and clock_div. */
71 #define ADC10_NSAMPLE 0x84