 
     pinMode(RED_LED_PIN, OUTPUT);
     pinMode(GREEN_LED_PIN, OUTPUT);
+
+    //Using an external voltage reference for increased accuracy
+    analogReference(EXTERNAL);
+    analogRead(0); //To help settle the ADC before taking readings
+
+    // WDT setup
+    cli(); //disable interrupts
+    wdt_reset();
+    // Enter 'Config mode'
+    WDTCSR |= (1<<WDCE) | (1<<WDE);
+
+    // Set interupts, reset on timeout, last 4 do time (1001 is 8sec)
+    WDTCSR = (1<<WDIE) | (0<<WDE) | (1<<WDP3) | (0<<WDP2) | (0<<WDP1) | (1<<WDP0);
+
+    sei(); //enable interupts
+  
 
 #if !(TEST)
     // initialize the SD card

void loop() {
    // TO DO
    test();
}


void newFile(){

    // File format should be: UNIXTIME_yyyy-mm-ddThhmmss
    // For example: 1506907892_2017-10-02T193101.csv
    // which is: 2017/Oct/02 7:39:01pm
    /*
    int unix   = now.unixtime();
    int year   = now.year();
    int month  = now.month();
    int day    = now.day();
    int hour   = now.hour();
    int minute = now.minute();
    int second = now.second();
    */
    unsigned long unix   = 1506907891;
    int year   = 2017;
    int month  = 10;
    int day    = 2;
    int hour   = 19;
    int minute = 31;
    int second = 4;

    char buff[580];
    char *header = buff;
    sprintf(header,
        "#Thanksgiving Cabin Power System\n"
        "#Time is in UNIX Time which is the number of seconds since 1970-Jan-01\n"
        "#To convert the date in cell 'A7' to an excel date serial number "
        "in Vancover time use:\n"
        "#=(A7/86400)+25569+(-7/24)\n"
        "or Google it\n"
        "Created: %04d-%02d-%02d at %02d:%02d:%02d or %010lu in UNIX time"
        "#Timestamp,Battery Voltage,Solar Voltage,Hydro Voltage,Load Voltage,"
        "Battery Amps, Solar Amps,Hydro Amps,Load Amps,Battery Energy State,"
        "Outside Temp,Cabin Temp,Battery Temp\n", year, month, day, hour, minute, second, unix);

    sprintf(filename, "%010lu_%04d-%02d-%02dT%02d%02d%02d.csv", unix, year, month, day, hour, minute, second);

    //readTime(temp);
    //strcat(temp, ".csv");
    //memcpy(filename, temp, sizeof(char)*NAME_LENGTH);
#if TEST
    return;
#endif
