瀏覽代碼

Merge pull request #317 from mjs513/master

AnalogReadResolution Added to Analog.c
main
Paul Stoffregen 5 年之前
父節點
當前提交
d3f5573910
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 17 行新增0 行删除
  1. +17
    -0
      teensy4/analog.c

+ 17
- 0
teensy4/analog.c 查看文件

@@ -66,6 +66,23 @@ void analogReference(uint8_t type)

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…
取消
儲存