Fix TemperatureDataLogger - sample tick timer wasn't being initialized in the correct...
[pub/USBasp.git] / Projects / TemperatureDataLogger / TempDataLogger.c
index 6cb1792..5872a08 100644 (file)
@@ -64,7 +64,7 @@ FATFS DiskFATState;
 /** FAT Fs structure to hold a FAT file handle for the log data write destination. */\r
 FIL TempLogFile;\r
 \r
 /** FAT Fs structure to hold a FAT file handle for the log data write destination. */\r
 FIL TempLogFile;\r
 \r
-/** Counter to count the number of 10 millisecond tick that has elapsed since the last sample */\r
+/** Counter to count the number of 10 millisecond ticks that has elapsed since the last sample */\r
 uint16_t CurrentLogTick;\r
 \r
 \r
 uint16_t CurrentLogTick;\r
 \r
 \r
@@ -73,6 +73,10 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
        if (CurrentLogTick++ != LOG_INTERVAL_10MS)\r
          return;\r
          \r
        if (CurrentLogTick++ != LOG_INTERVAL_10MS)\r
          return;\r
          \r
+       uint8_t LEDMask = LEDs_GetLEDs();\r
+\r
+       LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
+\r
        CurrentLogTick = 0;\r
 \r
        if (USB_DeviceState == DEVICE_STATE_Unattached)\r
        CurrentLogTick = 0;\r
 \r
        if (USB_DeviceState == DEVICE_STATE_Unattached)\r
@@ -80,6 +84,8 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK)
                f_printf(&TempLogFile, "%d Degrees\r\n", Temperature_GetTemperature());\r
                f_sync(&TempLogFile);\r
        }\r
                f_printf(&TempLogFile, "%d Degrees\r\n", Temperature_GetTemperature());\r
                f_sync(&TempLogFile);\r
        }\r
+       \r
+       LEDs_SetAllLEDs(LEDMask);\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -96,11 +102,12 @@ int main(void)
        f_mount(0, &DiskFATState);\r
        f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE);\r
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
        f_mount(0, &DiskFATState);\r
        f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE);\r
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
-\r
-       /* Write out the log seperator line */\r
        f_printf(&TempLogFile, "===========================\r\n");\r
        f_printf(&TempLogFile, "===========================\r\n");\r
-       Temperature_GetTemperature(); // Discard first temperature reading to ensure accuracy\r
-\r
+       \r
+       /* Discard the first sample from the temperature sensor, as it is generally incorrect */\r
+       uint8_t Dummy = Temperature_GetTemperature();\r
+       (void)Dummy;\r
+       \r
        for (;;)\r
        {\r
                MS_Device_USBTask(&Disk_MS_Interface);\r
        for (;;)\r
        {\r
                MS_Device_USBTask(&Disk_MS_Interface);\r
@@ -128,8 +135,7 @@ void SetupHardware(void)
        \r
        /* 10ms interval timer configuration */\r
        OCR1A   = (((F_CPU / 1024) / 100) - 1);\r
        \r
        /* 10ms interval timer configuration */\r
        OCR1A   = (((F_CPU / 1024) / 100) - 1);\r
-       TCCR1A  = (1 << WGM01);  // CTC mode\r
-       TCCR1B  = (1 << CS12) | (1 << CS10);   // Fcpu/1024 speed\r
+       TCCR1B  = (1 << WGM12) | (1 << CS12) | (1 << CS10);   // CTC mode, Fcpu/1024 speed\r
        TIMSK1  = (1 << OCIE1A);\r
 \r
        /* Clear Dataflash sector protections, if enabled */\r
        TIMSK1  = (1 << OCIE1A);\r
 \r
        /* Clear Dataflash sector protections, if enabled */\r
@@ -154,6 +160,7 @@ void EVENT_USB_Device_Disconnect(void)
        f_mount(0, &DiskFATState);\r
        f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE);\r
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
        f_mount(0, &DiskFATState);\r
        f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE);\r
        f_lseek(&TempLogFile, TempLogFile.fsize);\r
+       f_printf(&TempLogFile, "===========================\r\n");\r
 }\r
 \r
 /** Event handler for the library USB Configuration Changed event. */\r
 }\r
 \r
 /** Event handler for the library USB Configuration Changed event. */\r