ADC1? #684
-
I see the init_ADC1(), and "The core does not provide an equivalent to analogRead() for ADC1 at this time." Anyone have an example of how to read ADC1? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Well, you would probably start with analogRead()....
calling init_ADC1() in setup, and changing every instance of ADC0 to ADC1, should get you there except for setting the reference. But that's as easy as VREF.CTRLC=reference;
/* where reference is one of these:
VREF_ADC1REFSEL_0V55_gc
VREF_ADC1REFSEL_1V1_gc
VREF_ADC1REFSEL_2V5_gc
VREF_ADC1REFSEL_4V34_gc
VREF_ADC1REFSEL_1V5_gc
*/ if using the DACREF for AC1, then you need to instead do something like
VREF.CTRLC = (VREF_DAC1REFSEL_gm & VREF.CTRLC) | VREF_ADC1REFSEL_2V5_gc
// the only complication is switching between external VREF, internal reference, and VDD being in a different register for no good reason:
ADC1.CTRLC = (ADC1.CTRLC & (~ADC_REFSEL_gm)) | source
/* where source is one of these
ADC_REFSEL_INTREF_gc
ADC_REFSEL_VDDREF_gc
ADC_REFSEL_VREFA_gc
*/ As for the matter of the pin number, I would just use the channel number - ADC_CH(num) simply OR's the value with 128, but it's a lot clearer to say analogRead(ADC_CH(5)) than it would be to say analogRead(0x80 | 5) or (worst of all) analogRead1(133) The table pins to inputs is in I/O Multiplexing Considerations chapter of the datasheet. |
Beta Was this translation helpful? Give feedback.
-
Yup, was using ATtiny1614, switched to 1616 due to chip availability at the time, and the lure of a smaller package. Then to make for an easy route, I picked pin_PC0. I'll fix it on the next rev and avoid ADC1. |
Beta Was this translation helpful? Give feedback.
-
So it appears the latest core supports ADC1 now? |
Beta Was this translation helpful? Give feedback.
Well, you would probably start with analogRead()....