Troubleshooting Teensy 3.5 power consumption @ 16mhz

Status
Not open for further replies.

sj.schmidt

New member
Good morning,
I've put together a shipping data logger that writes temperature and shock data to an SD card. I'm measuring 38ma of current draw between the Teensy/LIS3DH/TMP36 and based off some initial frequency vs current consumption data I read before starting the project, was hoping to get closer to 20mA. It's not immediately clear to me what the culprit is, so before I start adding jumpers to measure individual devices I figured I would reach out to those more knowledgeable and get some feedback. I have included the code it's currently running as well as a simple block diagram of the components.

Logger.png

A couple additional points of clarification:
1. The 38 ma is after the boost converter so that does not include converter loss
2. I'm running the 3.3v from the boost converter straight to the 3.3v pins on the Teensy/LIS3DH/TMP36 however I have not removed the onboard Teensy regulator.
3. Fwiw, the code below results in about a 70hz logging frequency to the SD
4. These results are from compiling for 16mhz. At 24mhz, power consumption was about 44mA.

A couple photos of the project for those curious:
20190826_170816.jpg20190827_110552.jpg


Code:
// Shipping Data Logger for Shock and Temperature

#include <SparkFunLIS3DH.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <TimeLib.h>

LIS3DH myIMU(I2C_MODE, 0x19); 

// Teensy 3.5 & 3.6 on-board: BUILTIN_SDCARD
const int chipSelect = BUILTIN_SDCARD;
float sensor;

// String for assembling the csv data:
String dataString = "";
// Vars to handle TMP36 ADC averaging
int i =0;
int temp =0;
int tempAVG = 0;

void setup()
{
  // set the Time library to use Teensy 3.5's RTC
  setSyncProvider(getTeensy3Time);
  
 // Open serial communications and wait for port to open:
  Serial.begin(115200);
  delay(2000);
  Serial.print("Initializing SD card...");
  
  // See if the card is present and can be initialized:
  while (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
  }
  Serial.println("card initialized.");

  // Verify RTC functionality
  if (timeStatus()!= timeSet) {
    Serial.println("Unable to sync with the RTC");
  } else {
    Serial.println("RTC has set the system time");
  }

  // Update Time from PC
  if (Serial.available()) {
    time_t t = processSyncMessage();
    if (t != 0) {
      Teensy3Clock.set(t); // set the RTC
      setTime(t);
    }
  }

  Serial.end();
  
  // Configure ADC for Temp Sensor
  analogReadResolution(10);

  // Configure LIS3DH
  myIMU.settings.adcEnabled = 0;
  myIMU.settings.tempEnabled = 0;
  myIMU.settings.accelSampleRate = 100;  //Hz.  Can be: 0,1,10,25,50,100,200,400,1600,5000 Hz
  myIMU.settings.accelRange = 16;        //Max G force readable.  Can be: 2, 4, 8, 16
  myIMU.settings.xAccelEnabled = 1;
  myIMU.settings.yAccelEnabled = 1;
  myIMU.settings.zAccelEnabled = 1;
    
  // Start IMU
  myIMU.begin();
  
}

void loop()
{
  
  // Assemble string with 1 row of CSV data MM/DD/YYYY HH:MM,T,X,Y,Z
  stringassembly:
  
  dataString = String(day());
  dataString += "/";
  dataString += String(month());
  dataString += "/";
  dataString += String(year());
  dataString += " "; 
  dataString += String(hour());
  printDigits(minute());
  dataString += ",";
  //Average Noisy Temp Sensor
  temp += 100*(analogRead(A0)*3.25/1024)-55; // TMP36 temperature conversion
  i++;
  //Update Temperature Once for every 100 IMU Updates
  if( i == 99){
    tempAVG = temp/100;
    temp =0;
    i = 0;
  }
  dataString += String(tempAVG);
  dataString += ",";
  sensor = myIMU.readFloatAccelX();
  dataString += String(sensor);
  dataString += ",";
  sensor = myIMU.readFloatAccelY();
  dataString += String(sensor);
  dataString += ",";
  sensor = myIMU.readFloatAccelZ();
  dataString += String(sensor);


  // open the file
  File dataFile = SD.open("datalog.csv", FILE_WRITE);
  // check for card removed
  if (!dataFile) {
    delay(1000);
    SD.begin(chipSelect);
    goto stringassembly; 
  }
  
  // if the file is available, write to it:
    dataFile.println(dataString);
    dataFile.close();

   
}


time_t getTeensy3Time()
{
  return Teensy3Clock.get();
}

/*  code to process time sync messages from the serial port   */
#define TIME_HEADER  "T"   // Header tag for serial time sync message

unsigned long processSyncMessage() {
  unsigned long pctime = 0L;
  const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 

  if(Serial.find(TIME_HEADER)) {
     pctime = Serial.parseInt();
     return pctime;
     if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
       pctime = 0L; // return 0 to indicate that the time is not valid
     }
  }
  return pctime;
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  dataString += String(":");
  if(digits < 10)
    dataString += String('0');
  dataString += String(digits);
}
 
Status
Not open for further replies.
Back
Top