Browse Source

Merge pull request #317 from mjs513/master

AnalogReadResolution Added to Analog.c
main
Paul Stoffregen 5 years ago
parent
commit
d3f5573910
No account linked to committer's email address
1 changed files with 17 additions and 0 deletions
  1. +17
    -0
      teensy4/analog.c

+ 17
- 0
teensy4/analog.c View File



void analogReadRes(unsigned int bits) void analogReadRes(unsigned int bits)
{ {
uint32_t tmp32, mode;

if (bits == 8) {
// 8 bit conversion (17 clocks) plus 8 clocks for input settling
mode = ADC_CFG_MODE(0) | ADC_CFG_ADSTS(3);
} else if (bits == 10) {
// 10 bit conversion (17 clocks) plus 20 clocks for input settling
mode = ADC_CFG_MODE(1) | ADC_CFG_ADSTS(2) | ADC_CFG_ADLSMP;
} else {
// 12 bit conversion (25 clocks) plus 24 clocks for input settling
mode = ADC_CFG_MODE(2) | ADC_CFG_ADSTS(3) | ADC_CFG_ADLSMP;
}
tmp32 = (ADC1_CFG & ((1u << 22)-1) << 10);
tmp32 |= (ADC1_CFG & ((1u << 2)-1) << 0); // ADICLK
tmp32 |= ADC1_CFG & (((1u << 3)-1) << 5); // ADIV & ADLPC
tmp32 |= mode;
ADC1_CFG = tmp32;


} }



Loading…
Cancel
Save