Browse Source

Merge pull request #314 from mjs513/master

Final Correction to Tempmon Registes and Added analogreadaveraging
main
Paul Stoffregen 5 years ago
parent
commit
40a8afc124
No account linked to committer's email address
2 changed files with 27 additions and 6 deletions
  1. +21
    -0
      teensy4/analog.c
  2. +6
    -6
      teensy4/imxrt.h

+ 21
- 0
teensy4/analog.c View File

@@ -71,6 +71,27 @@ void analogReadRes(unsigned int bits)

void analogReadAveraging(unsigned int num)
{
uint32_t tmp32, mode, avg=0;
//disable averaging
tmp32 = ADC1_GC;
ADC1_GC &= ~0x20;

mode = ADC1_CFG & ~0xC000;
if (num >= 32) {
mode |= ADC_CFG_AVGS(3);
//Serial.println(ADC_CFG_AVGS(3), BIN);
} else if (num >= 16) {
mode |= ADC_CFG_AVGS(2);
} else if (num >= 8) {
mode |= ADC_CFG_AVGS(1);
} else {
mode |= ADC_CFG_AVGS(0);
}
ADC1_CFG = mode;
//enable averaging
ADC1_GC = tmp32;
}

#define MAX_ADC_CLOCK 20000000

+ 6
- 6
teensy4/imxrt.h View File

@@ -6730,18 +6730,18 @@ These register are used by the ROM code and should not be used by application so

// 53.3: page 2986
#define IMXRT_TEMPMON (*(IMXRT_REGISTER32_t *)0x400D8180)
#define TEMPMON_TEMPSENSE0 (IMXRT_TEMPMON.offset000)
#define TEMPMON_TEMPSENSE0 (IMXRT_TEMPMON.offset000)
#define TEMPMON_TEMPSENSE0_SET (IMXRT_TEMPMON.offset004)
#define TEMPMON_TEMPSENSE0_CLR (IMXRT_TEMPMON.offset008)
#define TEMPMON_TEMPSENSE0_TOG (IMXRT_TEMPMON.offset08c)
#define TEMPMON_TEMPSENSE1 (IMXRT_TEMPMON.offset090)
#define TEMPMON_TEMPSENSE1 (IMXRT_TEMPMON.offset090)
#define TEMPMON_TEMPSENSE1_SET (IMXRT_TEMPMON.offset094)
#define TEMPMON_TEMPSENSE1_CLR (IMXRT_TEMPMON.offset098)
#define TEMPMON_TEMPSENSE1_TOG (IMXRT_TEMPMON.offset09C)
#define TEMPMON_TEMPSENSE2 (IMXRT_TEMPMON.offset100)
#define TEMPMON_TEMPSENSE2_SET (IMXRT_TEMPMON.offset104)
#define TEMPMON_TEMPSENSE2_CLR (IMXRT_TEMPMON.offset108)
#define TEMPMON_TEMPSENSE2_TOG (IMXRT_TEMPMON.offset10C)
#define TEMPMON_TEMPSENSE2 (IMXRT_TEMPMON.offset110)
#define TEMPMON_TEMPSENSE2_SET (IMXRT_TEMPMON.offset114)
#define TEMPMON_TEMPSENSE2_CLR (IMXRT_TEMPMON.offset118)
#define TEMPMON_TEMPSENSE2_TOG (IMXRT_TEMPMON.offset11C)
#define TEMPMON_CTRL0_ALARM_VALUE(n) ((uint32_t)(((n) & 0x0fff) << 20))
#define TEMPMON_CTRL0_TEMP_CNT(n) ((uint32_t)(((n) & 0x0fff) << 8))
#define TEMPMON_CTRL0_FINISHED ((uint32_t)(1 << 2))

Loading…
Cancel
Save