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

Copyright 2020, Texas Instruments Incorporated