Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: teensy 3.1 bug and vref

  1. #1
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,532

    teensy 3.1 bug and vref

    I posted this on the 3.1/r17 announcement, but I'll repost here... and in the intervening time I think I have found the problem.

    The following little sketch worked on teensy 3.0 and reported the voltage level of Vcc using the internal reference voltage, so you can check your battery level. Similar ADC trick works on UNO and maple, but this no longer worked on teensy 3.1. On 3.1 the sketch reported varying values from 6000 to 8000 ???

    Code:
    void setup() {
      analogReference(DEFAULT);
      analogReadResolution(12);
      analogReadAveraging(32);
    }
    
    void loop() {
      int mv;
      mv = 1200 * 4096 /analogRead(39);
      Serial.println(mv);
      delay(2000);
    }
    Looking at analog.c and the 3.0 and 3.1 ARM reference manual, the VREF channel for ADC0 is 22, but for ADC1 (teensy 3.1) the VREF channel is 18. (the temperature channel sensor channel is 26 on both ADC0 and ADC1 so my chiptemp sketch worked on both 3.0 and 3.1). I hacked analog.c and changed channel2sc1a[] for __MK20DX256__, changing 22 to 128+18 and that seemed to fix the 3.1 problem.

    the sketch now reports 3343 mv

    Now to figure out why DMA memory-to-memory is twice as slow on 3.1 vs 3.0 ...
    Last edited by manitou; 02-21-2015 at 01:21 AM.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,106
    Yeah, on Teensy 3.1 some of the analog inputs connect differently.

    I also found at least one bug in the chip, where A13 only connects to ADC1. The manual says it also connects to ADC0, but clearly it does not.

    Now to figure out why DMA memory-to-memory is twice as slow on 3.1 vs 3.0 ...
    I have a service request in to Freescale regarding this issue.

  3. #3
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,532
    Bump. Paul I still don't see a patch in analog.c in your github tree for this analog pin fix? It may be low priority, but I was curious if you were unable to vet it, or ?

    I hacked analog.c and changed channel2sc1a[] for __MK20DX256__, changing 22 to 128+18 and that seemed to fix the 3.1 problem.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,106
    Thanks! I've committed this fix. It will be in the upcoming 1.18 release.

    https://github.com/PaulStoffregen/co...d4d005eb574268

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •