MSP430 DriverLib for MSP430FR2xx_4xx Devices  2.10.00.09
 All Data Structures Functions Variables Modules Pages
adc.h
1 //*****************************************************************************
2 //
3 // adc.h - Driver for the ADC Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_ADC_H__
8 #define __MSP430WARE_ADC_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_ADC__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 //*****************************************************************************
26 //
27 // The following are values that can be passed to the clockSourceSelect
28 // parameter for functions: ADC_init().
29 //
30 //*****************************************************************************
31 #define ADC_CLOCKSOURCE_ADCOSC (ADCSSEL_0)
32 #define ADC_CLOCKSOURCE_ACLK (ADCSSEL_1)
33 #define ADC_CLOCKSOURCE_SMCLK (ADCSSEL_2)
34 
35 //*****************************************************************************
36 //
37 // The following are values that can be passed to the clockSourceDivider
38 // parameter for functions: ADC_init().
39 //
40 //*****************************************************************************
41 #define ADC_CLOCKDIVIDER_1 (ADCDIV_0 + ADCPDIV_0)
42 #define ADC_CLOCKDIVIDER_2 (ADCDIV_1 + ADCPDIV_0)
43 #define ADC_CLOCKDIVIDER_3 (ADCDIV_2 + ADCPDIV_0)
44 #define ADC_CLOCKDIVIDER_4 (ADCDIV_3 + ADCPDIV_0)
45 #define ADC_CLOCKDIVIDER_5 (ADCDIV_4 + ADCPDIV_0)
46 #define ADC_CLOCKDIVIDER_6 (ADCDIV_5 + ADCPDIV_0)
47 #define ADC_CLOCKDIVIDER_7 (ADCDIV_6 + ADCPDIV_0)
48 #define ADC_CLOCKDIVIDER_8 (ADCDIV_7 + ADCPDIV_0)
49 #define ADC_CLOCKDIVIDER_12 (ADCDIV_2 + ADCPDIV_1)
50 #define ADC_CLOCKDIVIDER_16 (ADCDIV_3 + ADCPDIV_1)
51 #define ADC_CLOCKDIVIDER_20 (ADCDIV_4 + ADCPDIV_1)
52 #define ADC_CLOCKDIVIDER_24 (ADCDIV_5 + ADCPDIV_1)
53 #define ADC_CLOCKDIVIDER_28 (ADCDIV_6 + ADCPDIV_1)
54 #define ADC_CLOCKDIVIDER_32 (ADCDIV_7 + ADCPDIV_1)
55 #define ADC_CLOCKDIVIDER_64 (ADCDIV_0 + ADCPDIV_2)
56 #define ADC_CLOCKDIVIDER_128 (ADCDIV_1 + ADCPDIV_2)
57 #define ADC_CLOCKDIVIDER_192 (ADCDIV_2 + ADCPDIV_2)
58 #define ADC_CLOCKDIVIDER_256 (ADCDIV_3 + ADCPDIV_2)
59 #define ADC_CLOCKDIVIDER_320 (ADCDIV_4 + ADCPDIV_2)
60 #define ADC_CLOCKDIVIDER_384 (ADCDIV_5 + ADCPDIV_2)
61 #define ADC_CLOCKDIVIDER_448 (ADCDIV_6 + ADCPDIV_2)
62 #define ADC_CLOCKDIVIDER_512 (ADCDIV_7 + ADCPDIV_2)
63 
64 //*****************************************************************************
65 //
66 // The following are values that can be passed to the
67 // sampleHoldSignalSourceSelect parameter for functions: ADC_init().
68 //
69 //*****************************************************************************
70 #define ADC_SAMPLEHOLDSOURCE_SC (ADCSHS_0)
71 #define ADC_SAMPLEHOLDSOURCE_1 (ADCSHS_1)
72 #define ADC_SAMPLEHOLDSOURCE_2 (ADCSHS_2)
73 #define ADC_SAMPLEHOLDSOURCE_3 (ADCSHS_3)
74 
75 //*****************************************************************************
76 //
77 // The following are values that can be passed to the multipleSamplesEnabled
78 // parameter for functions: ADC_setupSamplingTimer().
79 //
80 //*****************************************************************************
81 #define ADC_MULTIPLESAMPLESDISABLE (!(ADCMSC))
82 #define ADC_MULTIPLESAMPLESENABLE (ADCMSC)
83 
84 //*****************************************************************************
85 //
86 // The following are values that can be passed to the clockCycleHoldCount
87 // parameter for functions: ADC_setupSamplingTimer().
88 //
89 //*****************************************************************************
90 #define ADC_CYCLEHOLD_4_CYCLES (ADCSHT_0)
91 #define ADC_CYCLEHOLD_8_CYCLES (ADCSHT_1)
92 #define ADC_CYCLEHOLD_16_CYCLES (ADCSHT_2)
93 #define ADC_CYCLEHOLD_32_CYCLES (ADCSHT_3)
94 #define ADC_CYCLEHOLD_64_CYCLES (ADCSHT_4)
95 #define ADC_CYCLEHOLD_96_CYCLES (ADCSHT_5)
96 #define ADC_CYCLEHOLD_128_CYCLES (ADCSHT_6)
97 #define ADC_CYCLEHOLD_192_CYCLES (ADCSHT_7)
98 #define ADC_CYCLEHOLD_256_CYCLES (ADCSHT_8)
99 #define ADC_CYCLEHOLD_384_CYCLES (ADCSHT_9)
100 #define ADC_CYCLEHOLD_512_CYCLES (ADCSHT_10)
101 #define ADC_CYCLEHOLD_768_CYCLES (ADCSHT_11)
102 #define ADC_CYCLEHOLD_1024_CYCLES (ADCSHT_12)
103 
104 //*****************************************************************************
105 //
106 // The following are values that can be passed to the inputSourceSelect
107 // parameter for functions: ADC_configureMemory().
108 //
109 //*****************************************************************************
110 #define ADC_INPUT_VEREF_N (ADCINCH_0)
111 #define ADC_INPUT_VEREF_P (ADCINCH_1)
112 #define ADC_INPUT_A2 (ADCINCH_2)
113 #define ADC_INPUT_A3 (ADCINCH_3)
114 #define ADC_INPUT_A4 (ADCINCH_4)
115 #define ADC_INPUT_A5 (ADCINCH_5)
116 #define ADC_INPUT_A6 (ADCINCH_6)
117 #define ADC_INPUT_A7 (ADCINCH_7)
118 #define ADC_INPUT_A8 (ADCINCH_8)
119 #define ADC_INPUT_A9 (ADCINCH_9)
120 #define ADC_INPUT_TEMPSENSOR (ADCINCH_12)
121 #define ADC_INPUT_REFVOLTAGE (ADCINCH_13)
122 #define ADC_INPUT_DVSS (ADCINCH_14)
123 #define ADC_INPUT_DVCC (ADCINCH_15)
124 
125 //*****************************************************************************
126 //
127 // The following are values that can be passed to the
128 // positiveRefVoltageSourceSelect parameter for functions:
129 // ADC_configureMemory().
130 //
131 //*****************************************************************************
132 #define ADC_VREFPOS_AVCC (!(ADCSREF0 + ADCSREF1))
133 #define ADC_VREFPOS_INT (ADCSREF0)
134 #define ADC_VREFPOS_EXT_BUF (ADCSREF1)
135 #define ADC_VREFPOS_EXT_NOBUF (ADCSREF1 + ADCSREF0)
136 
137 //*****************************************************************************
138 //
139 // The following are values that can be passed to the
140 // negativeRefVoltageSourceSelect parameter for functions:
141 // ADC_configureMemory().
142 //
143 //*****************************************************************************
144 #define ADC_VREFNEG_AVSS (!(ADCSREF2))
145 #define ADC_VREFNEG_EXT (ADCSREF2)
146 
147 //*****************************************************************************
148 //
149 // The following are values that can be passed to the interruptMask parameter
150 // for functions: ADC_enableInterrupt(), and ADC_disableInterrupt().
151 //
152 //*****************************************************************************
153 #define ADC_OVERFLOW_INTERRUPT (ADCOVIE)
154 #define ADC_TIMEOVERFLOW_INTERRUPT (ADCTOVIE)
155 #define ADC_ABOVETHRESHOLD_INTERRUPT (ADCHIIE)
156 #define ADC_BELOWTHRESHOLD_INTERRUPT (ADCLOIE)
157 #define ADC_INSIDEWINDOW_INTERRUPT (ADCINIE)
158 #define ADC_COMPLETED_INTERRUPT (ADCIE0)
159 
160 //*****************************************************************************
161 //
162 // The following are values that can be passed to the interruptFlagMask
163 // parameter for functions: ADC_clearInterrupt(), and ADC_getInterruptStatus().
164 //
165 //*****************************************************************************
166 #define ADC_OVERFLOW_INTERRUPT_FLAG (ADCOVIFG)
167 #define ADC_TIMEOVERFLOW_INTERRUPT_FLAG (ADCTOVIFG)
168 #define ADC_ABOVETHRESHOLD_INTERRUPT_FLAG (ADCHIIFG)
169 #define ADC_BELOWTHRESHOLD_INTERRUPT_FLAG (ADCLOIFG)
170 #define ADC_INSIDEWINDOW_INTERRUPT_FLAG (ADCINIFG)
171 #define ADC_COMPLETED_INTERRUPT_FLAG (ADCIFG0)
172 
173 //*****************************************************************************
174 //
175 // The following are values that can be passed to the
176 // conversionSequenceModeSelect parameter for functions: ADC_startConversion().
177 //
178 //*****************************************************************************
179 #define ADC_SINGLECHANNEL (ADCCONSEQ_0)
180 #define ADC_SEQOFCHANNELS (ADCCONSEQ_1)
181 #define ADC_REPEATED_SINGLECHANNEL (ADCCONSEQ_2)
182 #define ADC_REPEATED_SEQOFCHANNELS (ADCCONSEQ_3)
183 
184 //*****************************************************************************
185 //
186 // The following are values that can be passed to the preempt parameter for
187 // functions: ADC_disableConversions().
188 //
189 //*****************************************************************************
190 #define ADC_COMPLETECONVERSION false
191 #define ADC_PREEMPTCONVERSION true
192 
193 //*****************************************************************************
194 //
195 // The following are values that can be passed to the resolutionSelect
196 // parameter for functions: ADC_setResolution().
197 //
198 //*****************************************************************************
199 #define ADC_RESOLUTION_8BIT (!(ADCRES))
200 #define ADC_RESOLUTION_10BIT (ADCRES)
201 
202 //*****************************************************************************
203 //
204 // The following are values that can be passed to the invertedSignal parameter
205 // for functions: ADC_setSampleHoldSignalInversion().
206 //
207 //*****************************************************************************
208 #define ADC_NONINVERTEDSIGNAL (!(ADCISSH))
209 #define ADC_INVERTEDSIGNAL (ADCISSH)
210 
211 //*****************************************************************************
212 //
213 // The following are values that can be passed to the readBackFormat parameter
214 // for functions: ADC_setDataReadBackFormat().
215 //
216 //*****************************************************************************
217 #define ADC_UNSIGNED_BINARY (!(ADCDF))
218 #define ADC_SIGNED_2SCOMPLEMENT (ADCDF)
219 
220 //*****************************************************************************
221 //
222 // The following are values that can be passed to the samplingRateSelect
223 // parameter for functions: ADC_setReferenceBufferSamplingRate().
224 //
225 //*****************************************************************************
226 #define ADC_MAXSAMPLINGRATE_200KSPS (!(ADCSR))
227 #define ADC_MAXSAMPLINGRATE_50KSPS (ADCSR)
228 
229 //*****************************************************************************
230 //
231 // The following are values that can be passed toThe following are values that
232 // can be returned by the ADC_isBusy() function.
233 //
234 //*****************************************************************************
235 #define ADC_NOTBUSY (0x00)
236 #define ADC_BUSY (ADCBUSY)
237 
238 //*****************************************************************************
239 //
240 // Prototypes for the APIs.
241 //
242 //*****************************************************************************
243 
244 //*****************************************************************************
245 //
246 //! \brief Initializes the ADC Module.
247 //!
248 //! This function initializes the ADC module to allow for analog-to-digital
249 //! conversions. Specifically this function sets up the sample-and-hold signal
250 //! and clock sources for the ADC core to use for conversions. Upon successful
251 //! completion of the initialization all of the ADC control registers will be
252 //! reset, excluding the memory controls and reference module bits, the given
253 //! parameters will be set, and the ADC core will be turned on (Note, that the
254 //! ADC core only draws power during conversions and remains off when not
255 //! converting).Note that sample/hold signal sources are device dependent. Note
256 //! that if re-initializing the ADC after starting a conversion with the
257 //! startConversion() function, the disableConversion() must be called BEFORE
258 //! this function can be called.
259 //!
260 //! \param baseAddress is the base address of the ADC module.
261 //! \param sampleHoldSignalSourceSelect is the signal that will trigger a
262 //! sample-and-hold for an input signal to be converted. This parameter
263 //! is device specific and sources should be found in the device's
264 //! datasheet.
265 //! Valid values are:
266 //! - \b ADC_SAMPLEHOLDSOURCE_SC [Default]
267 //! - \b ADC_SAMPLEHOLDSOURCE_1
268 //! - \b ADC_SAMPLEHOLDSOURCE_2
269 //! - \b ADC_SAMPLEHOLDSOURCE_3
270 //! \n Modified bits are \b ADCSHSx of \b ADCCTL1 register.
271 //! \param clockSourceSelect selects the clock that will be used by the ADC
272 //! core and the sampling timer if a sampling pulse mode is enabled.
273 //! Valid values are:
274 //! - \b ADC_CLOCKSOURCE_ADCOSC [Default] - MODOSC 5 MHz oscillator from
275 //! the clock system
276 //! - \b ADC_CLOCKSOURCE_ACLK - The Auxilary Clock
277 //! - \b ADC_CLOCKSOURCE_SMCLK - The Sub-Master Clock
278 //! \n Modified bits are \b ADCSSELx of \b ADCCTL1 register.
279 //! \param clockSourceDivider selects the amount that the clock will be
280 //! divided.
281 //! Valid values are:
282 //! - \b ADC_CLOCKDIVIDER_1 [Default]
283 //! - \b ADC_CLOCKDIVIDER_2
284 //! - \b ADC_CLOCKDIVIDER_3
285 //! - \b ADC_CLOCKDIVIDER_4
286 //! - \b ADC_CLOCKDIVIDER_5
287 //! - \b ADC_CLOCKDIVIDER_6
288 //! - \b ADC_CLOCKDIVIDER_7
289 //! - \b ADC_CLOCKDIVIDER_8
290 //! - \b ADC_CLOCKDIVIDER_12
291 //! - \b ADC_CLOCKDIVIDER_16
292 //! - \b ADC_CLOCKDIVIDER_20
293 //! - \b ADC_CLOCKDIVIDER_24
294 //! - \b ADC_CLOCKDIVIDER_28
295 //! - \b ADC_CLOCKDIVIDER_32
296 //! - \b ADC_CLOCKDIVIDER_64
297 //! - \b ADC_CLOCKDIVIDER_128
298 //! - \b ADC_CLOCKDIVIDER_192
299 //! - \b ADC_CLOCKDIVIDER_256
300 //! - \b ADC_CLOCKDIVIDER_320
301 //! - \b ADC_CLOCKDIVIDER_384
302 //! - \b ADC_CLOCKDIVIDER_448
303 //! - \b ADC_CLOCKDIVIDER_512
304 //! \n Modified bits are \b ADCDIVx of \b ADCCTL1 register; bits \b
305 //! ADCPDIVx of \b ADCCTL2 register.
306 //!
307 //! \return None
308 //
309 //*****************************************************************************
310 extern void ADC_init(uint16_t baseAddress,
311  uint16_t sampleHoldSignalSourceSelect,
312  uint8_t clockSourceSelect,
313  uint16_t clockSourceDivider);
314 
315 //*****************************************************************************
316 //
317 //! \brief Enables the ADC block.
318 //!
319 //! This will enable operation of the ADC block.
320 //!
321 //! \param baseAddress is the base address of the ADC module.
322 //!
323 //! Modified bits are \b ADCON of \b ADCCTL0 register.
324 //!
325 //! \return None
326 //
327 //*****************************************************************************
328 extern void ADC_enable(uint16_t baseAddress);
329 
330 //*****************************************************************************
331 //
332 //! \brief Disables the ADC block.
333 //!
334 //! This will disable operation of the ADC block.
335 //!
336 //! \param baseAddress is the base address of the ADC module.
337 //!
338 //! Modified bits are \b ADCON of \b ADCCTL0 register.
339 //!
340 //! \return None
341 //
342 //*****************************************************************************
343 extern void ADC_disable(uint16_t baseAddress);
344 
345 //*****************************************************************************
346 //
347 //! \brief Sets up and enables the Sampling Timer Pulse Mode.
348 //!
349 //! This function sets up the sampling timer pulse mode which allows the
350 //! sample/hold signal to trigger a sampling timer to sample-and-hold an input
351 //! signal for a specified number of clock cycles without having to hold the
352 //! sample/hold signal for the entire period of sampling. Note that if a
353 //! conversion has been started with the startConversion() function, then a
354 //! call to disableConversions() is required before this function may be
355 //! called.
356 //!
357 //! \param baseAddress is the base address of the ADC module.
358 //! \param clockCycleHoldCount sets the amount of clock cycles to sample-and-
359 //! hold for the memory buffer.
360 //! Valid values are:
361 //! - \b ADC_CYCLEHOLD_4_CYCLES [Default]
362 //! - \b ADC_CYCLEHOLD_8_CYCLES
363 //! - \b ADC_CYCLEHOLD_16_CYCLES
364 //! - \b ADC_CYCLEHOLD_32_CYCLES
365 //! - \b ADC_CYCLEHOLD_64_CYCLES
366 //! - \b ADC_CYCLEHOLD_96_CYCLES
367 //! - \b ADC_CYCLEHOLD_128_CYCLES
368 //! - \b ADC_CYCLEHOLD_192_CYCLES
369 //! - \b ADC_CYCLEHOLD_256_CYCLES
370 //! - \b ADC_CYCLEHOLD_384_CYCLES
371 //! - \b ADC_CYCLEHOLD_512_CYCLES
372 //! - \b ADC_CYCLEHOLD_768_CYCLES
373 //! - \b ADC_CYCLEHOLD_1024_CYCLES
374 //! \n Modified bits are \b ADCSHTx of \b ADCCTL0 register.
375 //! \param multipleSamplesEnabled allows multiple conversions to start without
376 //! a trigger signal from the sample/hold signal
377 //! Valid values are:
378 //! - \b ADC_MULTIPLESAMPLESDISABLE - a timer trigger will be needed to
379 //! start every ADC conversion.
380 //! - \b ADC_MULTIPLESAMPLESENABLE - during a sequenced and/or repeated
381 //! conversion mode, after the first conversion, no sample/hold
382 //! signal is necessary to start subsequent samples.
383 //! \n Modified bits are \b ADCMSC of \b ADCCTL0 register.
384 //!
385 //! \return None
386 //
387 //*****************************************************************************
388 extern void ADC_setupSamplingTimer(uint16_t baseAddress,
389  uint16_t clockCycleHoldCount,
390  uint16_t multipleSamplesEnabled);
391 
392 //*****************************************************************************
393 //
394 //! \brief Disables Sampling Timer Pulse Mode.
395 //!
396 //! Disables the Sampling Timer Pulse Mode. Note that if a conversion has been
397 //! started with the startConversion() function, then a call to
398 //! disableConversions() is required before this function may be called.
399 //!
400 //! \param baseAddress is the base address of the ADC module.
401 //!
402 //! Modified bits are \b ADCSHP of \b ADCCTL1 register.
403 //!
404 //! \return None
405 //
406 //*****************************************************************************
407 extern void ADC_disableSamplingTimer(uint16_t baseAddress);
408 
409 //*****************************************************************************
410 //
411 //! \brief Configures the controls of the selected memory buffer.
412 //!
413 //! Maps an input signal conversion into the memory buffer, as well as the
414 //! positive and negative reference voltages for each conversion being stored
415 //! into the memory buffer. If the internal reference is used for the positive
416 //! reference voltage, the internal REF module has to control the voltage
417 //! level. Note that if a conversion has been started with the
418 //! startConversion() function, then a call to disableConversions() is required
419 //! before this function may be called.
420 //!
421 //! \param baseAddress is the base address of the ADC module.
422 //! \param inputSourceSelect is the input that will store the converted data
423 //! into the specified memory buffer.
424 //! Valid values are:
425 //! - \b ADC_INPUT_VEREF_N [Default]
426 //! - \b ADC_INPUT_VEREF_P
427 //! - \b ADC_INPUT_A2
428 //! - \b ADC_INPUT_A3
429 //! - \b ADC_INPUT_A4
430 //! - \b ADC_INPUT_A5
431 //! - \b ADC_INPUT_A6
432 //! - \b ADC_INPUT_A7
433 //! - \b ADC_INPUT_A8 - [Valid for FR4xx devices]
434 //! - \b ADC_INPUT_A9 - [Valid for FR4xx devices]
435 //! - \b ADC_INPUT_TEMPSENSOR
436 //! - \b ADC_INPUT_REFVOLTAGE
437 //! - \b ADC_INPUT_DVSS
438 //! - \b ADC_INPUT_DVCC
439 //! \n Modified bits are \b ADCINCHx of \b ADCMCTL0 register.
440 //! \param positiveRefVoltageSourceSelect is the reference voltage source to
441 //! set as the upper limit for the conversion that is to be stored in
442 //! the specified memory buffer.
443 //! Valid values are:
444 //! - \b ADC_VREFPOS_AVCC [Default]
445 //! - \b ADC_VREFPOS_INT
446 //! - \b ADC_VREFPOS_EXT_BUF
447 //! - \b ADC_VREFPOS_EXT_NOBUF
448 //! \n Modified bits are \b ADCSREF of \b ADCMCTL0 register.
449 //! \param negativeRefVoltageSourceSelect is the reference voltage source to
450 //! set as the lower limit for the conversion that is to be stored in
451 //! the specified memory buffer.
452 //! Valid values are:
453 //! - \b ADC_VREFNEG_AVSS [Default]
454 //! - \b ADC_VREFNEG_EXT
455 //! \n Modified bits are \b ADCSREF of \b ADCMCTL0 register.
456 //!
457 //! \return None
458 //
459 //*****************************************************************************
460 extern void ADC_configureMemory(uint16_t baseAddress,
461  uint8_t inputSourceSelect,
462  uint8_t positiveRefVoltageSourceSelect,
463  uint8_t negativeRefVoltageSourceSelect);
464 
465 //*****************************************************************************
466 //
467 //! \brief Enables selected ADC interrupt sources.
468 //!
469 //! Enables the indicated ADC interrupt sources. Only the sources that are
470 //! enabled can be reflected to the processor interrupt; disabled sources have
471 //! no effect on the processor. <b>Does not clear interrupt flags.
472 //!
473 //! \param baseAddress is the base address of the ADC module.
474 //! \param interruptMask is the bit mask of the memory buffer interrupt sources
475 //! to be enabled.
476 //! Mask value is the logical OR of any of the following:
477 //! - \b ADC_OVERFLOW_INTERRUPT - Interrupts when a new conversion is
478 //! about to overwrite the previous one
479 //! - \b ADC_TIMEOVERFLOW_INTERRUPT - Interrupts when a new conversion
480 //! is starting before the previous one has finished
481 //! - \b ADC_ABOVETHRESHOLD_INTERRUPT - Interrups when the input signal
482 //! has gone above the high threshold of the window comparator
483 //! - \b ADC_BELOWTHRESHOLD_INTERRUPT - Interrupts when the input signal
484 //! has gone below the low threshold of the low window comparator
485 //! - \b ADC_INSIDEWINDOW_INTERRUPT - Interrupts when the input signal
486 //! is in between the high and low thresholds of the window
487 //! comparator
488 //! - \b ADC_COMPLETED_INTERRUPT - Interrupt for new conversion data in
489 //! the memory buffer
490 //!
491 //! Modified bits of \b ADCIE register.
492 //!
493 //! \return None
494 //
495 //*****************************************************************************
496 extern void ADC_enableInterrupt(uint16_t baseAddress,
497  uint8_t interruptMask);
498 
499 //*****************************************************************************
500 //
501 //! \brief Disables selected ADC interrupt sources.
502 //!
503 //! Disables the indicated ADC interrupt sources. Only the sources that are
504 //! enabled can be reflected to the processor interrupt; disabled sources have
505 //! no effect on the processor.
506 //!
507 //! \param baseAddress is the base address of the ADC module.
508 //! \param interruptMask is the bit mask of the memory buffer interrupt sources
509 //! to be disabled.
510 //! Mask value is the logical OR of any of the following:
511 //! - \b ADC_OVERFLOW_INTERRUPT - Interrupts when a new conversion is
512 //! about to overwrite the previous one
513 //! - \b ADC_TIMEOVERFLOW_INTERRUPT - Interrupts when a new conversion
514 //! is starting before the previous one has finished
515 //! - \b ADC_ABOVETHRESHOLD_INTERRUPT - Interrups when the input signal
516 //! has gone above the high threshold of the window comparator
517 //! - \b ADC_BELOWTHRESHOLD_INTERRUPT - Interrupts when the input signal
518 //! has gone below the low threshold of the low window comparator
519 //! - \b ADC_INSIDEWINDOW_INTERRUPT - Interrupts when the input signal
520 //! is in between the high and low thresholds of the window
521 //! comparator
522 //! - \b ADC_COMPLETED_INTERRUPT - Interrupt for new conversion data in
523 //! the memory buffer
524 //!
525 //! Modified bits of \b ADCIE register.
526 //!
527 //! \return None
528 //
529 //*****************************************************************************
530 extern void ADC_disableInterrupt(uint16_t baseAddress,
531  uint8_t interruptMask);
532 
533 //*****************************************************************************
534 //
535 //! \brief Clears ADC10B selected interrupt flags.
536 //!
537 //! The selected ADC interrupt flags are cleared, so that it no longer asserts.
538 //! The memory buffer interrupt flags are only cleared when the memory buffer
539 //! is accessed.
540 //!
541 //! \param baseAddress is the base address of the ADC module.
542 //! \param interruptFlagMask is a bit mask of the interrupt flags to be
543 //! cleared.
544 //! Mask value is the logical OR of any of the following:
545 //! - \b ADC_OVERFLOW_INTERRUPT_FLAG - Interrupt flag for when a new
546 //! conversion is about to overwrite the previous one
547 //! - \b ADC_TIMEOVERFLOW_INTERRUPT_FLAG - Interrupt flag for when a new
548 //! conversion is starting before the previous one has finished
549 //! - \b ADC_ABOVETHRESHOLD_INTERRUPT_FLAG - Interrup flag for when the
550 //! input signal has gone above the high threshold of the window
551 //! comparator
552 //! - \b ADC_BELOWTHRESHOLD_INTERRUPT_FLAG - Interrupt flag for when the
553 //! input signal has gone below the low threshold of the window
554 //! comparator
555 //! - \b ADC_INSIDEWINDOW_INTERRUPT_FLAG - Interrupt flag for when the
556 //! input signal is in between the high and low thresholds of the
557 //! window comparator
558 //! - \b ADC_COMPLETED_INTERRUPT_FLAG - Interrupt flag for new
559 //! conversion data in the memory buffer
560 //!
561 //! Modified bits of \b ADCIFG register.
562 //!
563 //! \return None
564 //
565 //*****************************************************************************
566 extern void ADC_clearInterrupt(uint16_t baseAddress,
567  uint8_t interruptFlagMask);
568 
569 //*****************************************************************************
570 //
571 //! \brief Returns the status of the selected memory interrupt flags.
572 //!
573 //! Returns the status of the selected interrupt flags.
574 //!
575 //! \param baseAddress is the base address of the ADC module.
576 //! \param interruptFlagMask is a bit mask of the interrupt flags status to be
577 //! returned.
578 //! Mask value is the logical OR of any of the following:
579 //! - \b ADC_OVERFLOW_INTERRUPT_FLAG - Interrupt flag for when a new
580 //! conversion is about to overwrite the previous one
581 //! - \b ADC_TIMEOVERFLOW_INTERRUPT_FLAG - Interrupt flag for when a new
582 //! conversion is starting before the previous one has finished
583 //! - \b ADC_ABOVETHRESHOLD_INTERRUPT_FLAG - Interrup flag for when the
584 //! input signal has gone above the high threshold of the window
585 //! comparator
586 //! - \b ADC_BELOWTHRESHOLD_INTERRUPT_FLAG - Interrupt flag for when the
587 //! input signal has gone below the low threshold of the window
588 //! comparator
589 //! - \b ADC_INSIDEWINDOW_INTERRUPT_FLAG - Interrupt flag for when the
590 //! input signal is in between the high and low thresholds of the
591 //! window comparator
592 //! - \b ADC_COMPLETED_INTERRUPT_FLAG - Interrupt flag for new
593 //! conversion data in the memory buffer
594 //!
595 //! Modified bits of \b ADC10IFG register.
596 //!
597 //! \return The current interrupt flag status for the corresponding mask.
598 //
599 //*****************************************************************************
600 extern uint8_t ADC_getInterruptStatus(uint16_t baseAddress,
601  uint8_t interruptFlagMask);
602 
603 //*****************************************************************************
604 //
605 //! \brief Enables/Starts an Analog-to-Digital Conversion.
606 //!
607 //! This function enables/starts the conversion process of the ADC. If the
608 //! sample/hold signal source chosen during initialization was ADCOSC, then the
609 //! conversion is started immediately, otherwise the chosen sample/hold signal
610 //! source starts the conversion by a rising edge of the signal. Keep in mind
611 //! when selecting conversion modes, that for sequenced and/or
612 //! repeated modes, to keep the sample/hold-and-convert process continuing
613 //! without a trigger from the sample/hold signal source, the multiple samples
614 //! must be enabled using the ADC_setupSamplingTimer() function. Also note that
615 //! when a sequence conversion mode is selected, the first input channel is the
616 //! one mapped to the memory buffer, the next input channel selected for
617 //! conversion is one less than the input channel just converted (i.e. A1 comes
618 //! after A2), until A0 is reached, and if in repeating mode, then the next
619 //! input channel will again be the one mapped to the memory buffer. Note that
620 //! after this function is called, the ADC_stopConversions() has to be called
621 //! to re-initialize the ADC, reconfigure a memory buffer control,
622 //! enable/disable the sampling timer, or to change the internal reference
623 //! voltage.
624 //!
625 //! \param baseAddress is the base address of the ADC module.
626 //! \param conversionSequenceModeSelect determines the ADC operating mode.
627 //! Valid values are:
628 //! - \b ADC_SINGLECHANNEL [Default] - one-time conversion of a single
629 //! channel into a single memory buffer
630 //! - \b ADC_SEQOFCHANNELS - one time conversion of multiple channels
631 //! into the specified starting memory buffer and each subsequent
632 //! memory buffer up until the conversion is stored in a memory
633 //! buffer dedicated as the end-of-sequence by the memory's control
634 //! register
635 //! - \b ADC_REPEATED_SINGLECHANNEL - repeated conversions of one
636 //! channel into a single memory buffer
637 //! - \b ADC_REPEATED_SEQOFCHANNELS - repeated conversions of multiple
638 //! channels into the specified starting memory buffer and each
639 //! subsequent memory buffer up until the conversion is stored in a
640 //! memory buffer dedicated as the end-of-sequence by the memory's
641 //! control register
642 //! \n Modified bits are \b ADCCONSEQx of \b ADCCTL1 register.
643 //!
644 //! \return None
645 //
646 //*****************************************************************************
647 extern void ADC_startConversion(uint16_t baseAddress,
648  uint8_t conversionSequenceModeSelect);
649 
650 //*****************************************************************************
651 //
652 //! \brief Disables the ADC from converting any more signals.
653 //!
654 //! Disables the ADC from converting any more signals. If there is a conversion
655 //! in progress, this function can stop it immediatly if the preempt parameter
656 //! is set as ADC_PREEMPTCONVERSION, by changing the conversion mode to single-
657 //! channel, single-conversion and disabling conversions. If the conversion
658 //! mode is set as single-channel, single-conversion and this function is
659 //! called without preemption, then the ADC core conversion status is polled
660 //! until the conversion is complete before disabling conversions to prevent
661 //! unpredictable data. If the ADC_startConversion() has been called, then this
662 //! function has to be called to re-initialize the ADC, reconfigure a memory
663 //! buffer control, enable/disable the sampling pulse mode, or change the
664 //! internal reference voltage.
665 //!
666 //! \param baseAddress is the base address of the ADC module.
667 //! \param preempt specifies if the current conversion should be preemptly
668 //! stopped before the end of the conversion
669 //! Valid values are:
670 //! - \b ADC_COMPLETECONVERSION - Allows the ADC to end the current
671 //! conversion before disabling conversions.
672 //! - \b ADC_PREEMPTCONVERSION - Stops the ADC10B immediatly, with
673 //! unpredicatble results of the current conversion. Cannot be used
674 //! with repeated conversion.
675 //!
676 //! Modified bits of \b ADCCTL0 register and bits of \b ADCCTL1 register.
677 //!
678 //! \return None
679 //
680 //*****************************************************************************
681 extern void ADC_disableConversions(uint16_t baseAddress,
682  bool preempt);
683 
684 //*****************************************************************************
685 //
686 //! \brief Returns the raw contents of the specified memory buffer.
687 //!
688 //! Returns the raw contents of the specified memory buffer. The format of the
689 //! content depends on the read-back format of the data: if the data is in
690 //! signed 2's complement format then the contents in the memory buffer will be
691 //! left-justified with the least-siginificant bits as 0's, whereas if the data
692 //! is in unsigned format then the contents in the memory buffer will be right-
693 //! justified with the most-significant bits as 0's.
694 //!
695 //! \param baseAddress is the base address of the ADC module.
696 //!
697 //! \return A Signed Integer of the contents of the specified memory buffer.
698 //
699 //*****************************************************************************
700 extern int16_t ADC_getResults(uint16_t baseAddress);
701 
702 //*****************************************************************************
703 //
704 //! \brief Use to change the resolution of the converted data.
705 //!
706 //! This function can be used to change the resolution of the converted data
707 //! from the default of 12-bits.
708 //!
709 //! \param baseAddress is the base address of the ADC module.
710 //! \param resolutionSelect determines the resolution of the converted data.
711 //! Valid values are:
712 //! - \b ADC_RESOLUTION_8BIT
713 //! - \b ADC_RESOLUTION_10BIT [Default]
714 //! \n Modified bits are \b ADCRES of \b ADCCTL2 register.
715 //!
716 //! \return None
717 //
718 //*****************************************************************************
719 extern void ADC_setResolution(uint16_t baseAddress,
720  uint8_t resolutionSelect);
721 
722 //*****************************************************************************
723 //
724 //! \brief Use to invert or un-invert the sample/hold signal
725 //!
726 //! This function can be used to invert or un-invert the sample/hold signal.
727 //! Note that if a conversion has been started with the startConversion()
728 //! function, then a call to disableConversions() is required before this
729 //! function may be called.
730 //!
731 //! \param baseAddress is the base address of the ADC module.
732 //! \param invertedSignal set if the sample/hold signal should be inverted
733 //! Valid values are:
734 //! - \b ADC_NONINVERTEDSIGNAL [Default] - a sample-and-hold of an input
735 //! signal for conversion will be started on a rising edge of the
736 //! sample/hold signal.
737 //! - \b ADC_INVERTEDSIGNAL - a sample-and-hold of an input signal for
738 //! conversion will be started on a falling edge of the sample/hold
739 //! signal.
740 //! \n Modified bits are \b ADCISSH of \b ADCCTL1 register.
741 //!
742 //! \return None
743 //
744 //*****************************************************************************
745 extern void ADC_setSampleHoldSignalInversion(uint16_t baseAddress,
746  uint16_t invertedSignal);
747 
748 //*****************************************************************************
749 //
750 //! \brief Use to set the read-back format of the converted data
751 //!
752 //! Sets the format of the converted data: how it will be stored into the
753 //! memory buffer, and how it should be read back. The format can be set as
754 //! right-justified (default), which indicates that the number will be
755 //! unsigned, or left-justified, which indicates that the number will be signed
756 //! in 2's complement format. This change affects all memory buffers for
757 //! subsequent conversions.
758 //!
759 //! \param baseAddress is the base address of the ADC module.
760 //! \param readBackFormat is the specified format to store the conversions in
761 //! the memory buffer.
762 //! Valid values are:
763 //! - \b ADC_UNSIGNED_BINARY [Default]
764 //! - \b ADC_SIGNED_2SCOMPLEMENT
765 //! \n Modified bits are \b ADCDF of \b ADCCTL2 register.
766 //!
767 //! \return None
768 //
769 //*****************************************************************************
770 extern void ADC_setDataReadBackFormat(uint16_t baseAddress,
771  uint16_t readBackFormat);
772 
773 //*****************************************************************************
774 //
775 //! \brief Use to set the reference buffer's sampling rate.
776 //!
777 //! Sets the reference buffer's sampling rate to the selected sampling rate.
778 //! The default sampling rate is maximum of 200-ksps, and can be reduced to a
779 //! maximum of 50-ksps to conserve power.
780 //!
781 //! \param baseAddress is the base address of the ADC module.
782 //! \param samplingRateSelect is the specified maximum sampling rate.
783 //! Valid values are:
784 //! - \b ADC_MAXSAMPLINGRATE_200KSPS [Default]
785 //! - \b ADC_MAXSAMPLINGRATE_50KSPS
786 //! \n Modified bits are \b ADCSR of \b ADCCTL2 register.
787 //!
788 //! Modified bits of \b ADCCTL2 register.
789 //!
790 //! \return None
791 //
792 //*****************************************************************************
793 extern void ADC_setReferenceBufferSamplingRate(uint16_t baseAddress,
794  uint16_t samplingRateSelect);
795 
796 //*****************************************************************************
797 //
798 //! \brief Sets the high and low threshold for the window comparator feature.
799 //!
800 //! Sets the high and low threshold for the window comparator feature. Use the
801 //! ADCHIIE, ADCINIE, ADCLOIE interrupts to utilize this feature.
802 //!
803 //! \param baseAddress is the base address of the ADC module.
804 //! \param highThreshold is the upper bound that could trip an interrupt for
805 //! the window comparator.
806 //! \param lowThreshold is the lower bound that could trip on interrupt for the
807 //! window comparator.
808 //!
809 //! Modified bits of \b ADCLO register and bits of \b ADCHI register.
810 //!
811 //! \return None
812 //
813 //*****************************************************************************
814 extern void ADC_setWindowComp(uint16_t baseAddress,
815  uint16_t highThreshold,
816  uint16_t lowThreshold);
817 
818 //*****************************************************************************
819 //
820 //! \brief Returns the address of the memory buffer for the DMA module.
821 //!
822 //! \param baseAddress is the base address of the ADC module.
823 //!
824 //! \return the address of the memory buffer. This can be used in conjunction
825 //! with the DMA to store the converted data directly to memory.
826 //
827 //*****************************************************************************
828 extern uint32_t ADC_getMemoryAddressForDMA(uint16_t baseAddress);
829 
830 //*****************************************************************************
831 //
832 //! \brief Returns the busy status of the ADC core.
833 //!
834 //! Returns the status of the ADC core if there is a conversion currently
835 //! taking place.
836 //!
837 //! \param baseAddress is the base address of the ADC module.
838 //!
839 //! \return ADC_BUSY or ADC_NOTBUSY dependent if there is a conversion
840 //! currently taking place.
841 //! Return one of the following:
842 //! - \b ADC_NOTBUSY
843 //! - \b ADC_BUSY
844 //
845 //*****************************************************************************
846 extern uint8_t ADC_isBusy(uint16_t baseAddress);
847 
848 //*****************************************************************************
849 //
850 // Mark the end of the C bindings section for C++ compilers.
851 //
852 //*****************************************************************************
853 #ifdef __cplusplus
854 }
855 #endif
856 
857 #endif
858 #endif // __MSP430WARE_ADC_H__
void ADC_clearInterrupt(uint16_t baseAddress, uint8_t interruptFlagMask)
Clears ADC10B selected interrupt flags.
Definition: adc.c:182
void ADC_disableInterrupt(uint16_t baseAddress, uint8_t interruptMask)
Disables selected ADC interrupt sources.
Definition: adc.c:171
void ADC_setDataReadBackFormat(uint16_t baseAddress, uint16_t readBackFormat)
Use to set the read-back format of the converted data.
Definition: adc.c:263
void ADC_disable(uint16_t baseAddress)
Disables the ADC block.
Definition: adc.c:79
void ADC_setResolution(uint16_t baseAddress, uint8_t resolutionSelect)
Use to change the resolution of the converted data.
Definition: adc.c:240
void ADC_setReferenceBufferSamplingRate(uint16_t baseAddress, uint16_t samplingRateSelect)
Use to set the reference buffer's sampling rate.
Definition: adc.c:273
void ADC_startConversion(uint16_t baseAddress, uint8_t conversionSequenceModeSelect)
Enables/Starts an Analog-to-Digital Conversion.
Definition: adc.c:204
void ADC_setSampleHoldSignalInversion(uint16_t baseAddress, uint16_t invertedSignal)
Use to invert or un-invert the sample/hold signal.
Definition: adc.c:250
uint32_t ADC_getMemoryAddressForDMA(uint16_t baseAddress)
Returns the address of the memory buffer for the DMA module.
Definition: adc.c:291
void ADC_configureMemory(uint16_t baseAddress, uint8_t inputSourceSelect, uint8_t positiveRefVoltageSourceSelect, uint8_t negativeRefVoltageSourceSelect)
Configures the controls of the selected memory buffer.
Definition: adc.c:124
void ADC_setWindowComp(uint16_t baseAddress, uint16_t highThreshold, uint16_t lowThreshold)
Sets the high and low threshold for the window comparator feature.
Definition: adc.c:283
void ADC_setupSamplingTimer(uint16_t baseAddress, uint16_t clockCycleHoldCount, uint16_t multipleSamplesEnabled)
Sets up and enables the Sampling Timer Pulse Mode.
Definition: adc.c:85
void ADC_init(uint16_t baseAddress, uint16_t sampleHoldSignalSourceSelect, uint8_t clockSourceSelect, uint16_t clockSourceDivider)
Initializes the ADC Module.
Definition: adc.c:21
int16_t ADC_getResults(uint16_t baseAddress)
Returns the raw contents of the specified memory buffer.
Definition: adc.c:235
void ADC_enableInterrupt(uint16_t baseAddress, uint8_t interruptMask)
Enables selected ADC interrupt sources.
Definition: adc.c:160
uint8_t ADC_getInterruptStatus(uint16_t baseAddress, uint8_t interruptFlagMask)
Returns the status of the selected memory interrupt flags.
Definition: adc.c:193
void ADC_disableSamplingTimer(uint16_t baseAddress)
Disables Sampling Timer Pulse Mode.
Definition: adc.c:116
void ADC_disableConversions(uint16_t baseAddress, bool preempt)
Disables the ADC from converting any more signals.
Definition: adc.c:219
uint8_t ADC_isBusy(uint16_t baseAddress)
Returns the busy status of the ADC core.
Definition: adc.c:296
void ADC_enable(uint16_t baseAddress)
Enables the ADC block.
Definition: adc.c:73

Copyright 2015, Texas Instruments Incorporated