MCPcopy Create free account
hub / github.com/IRMP-org/IRMP / readADCChannelWithReference

Function readADCChannelWithReference

examples/AllProtocols/ADCUtils.hpp:101–116  ·  view source on GitHub ↗

* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. */

Source from the content-addressed store, hash-verified

99 * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.
100 */
101uint16_t readADCChannelWithReference(uint8_t aADCChannelNumber, uint8_t aReference) {
102 WordUnionForADCUtils tUValue;
103 ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE);
104
105 // ADCSRB = 0; // Only active if ADATE is set to 1.
106 // ADSC-StartConversion ADIF-Reset Interrupt Flag - NOT free running mode
107 ADCSRA = (_BV(ADEN) | _BV(ADSC) | _BV(ADIF) | ADC_PRESCALE);
108
109 // wait for single conversion to finish
110 loop_until_bit_is_clear(ADCSRA, ADSC);
111
112 // Get value
113 tUValue.UByte.LowByte = ADCL;
114 tUValue.UByte.HighByte = ADCH;
115 return tUValue.UWord;
116}
117
118/*
119 * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.

Calls

no outgoing calls

Tested by

no test coverage detected