//***************************************************************************** // File Name : datalogger.c // // Title : Windlogger // Revision : 0.2 22-10-2006 // Revision History: // When Who Description of change // ----------- ----------- ----------------------- // 20-Oct-2002 pstang Created the program // Oct - 2006 RifRaf changes stuff //***************************************************************************** //----- Include Files --------------------------------------------------------- #include // include I/O definitions (port names, pin names, etc) #include // include "signal" names (interrupt names) #include // include interrupt support #include "global.h" // include our global settings #include "uart.h" // include uart function library #include "rprintf.h" // include printf function library #include "timer.h" // include timer function library (timing, PWM, etc) #include "a2d.h" // include A/D converter function library #include "vt100.h" // include VT100 terminal support #include "lcd.h" // include Character LCD support //#include "i2ceeprom.h" // include I2C EEPROM support //#include "i2c.h" // include I2C support #include "extint.h" // include external interrupt library #include "spi.h" // include SPI interface functions #include "mmc.h" // include MMC card access functions #include "debug.h" #define SetBit(BIT, PORT) PORT |= (1< 620) { mode = 0; SwitchToLoad(); } if (volts < 580) { mode = 1; SwitchToCharging(); } Int0Count = 0; // reset interrupt counters Int1Count = 0; // reset interrupt counters timerPause(3000); // wait 3 seconds rpm = Int0Count; // get counter values windpulse = Int1Count; // get counter values checkDirection(); rprintfInit(uartSendByte); vt100SetCursorPos(1,1); rprintf("[%d%d%d%d%d%d%d%d%d%d]\r\n",volts,shuntvolts,rpm,windpulse,mode,direction,recttemp,outtemp,insidetemp,barometer); mmcWriteBuffer(); SetMinMax(); //Update LCD rprintfInit(lcdDataWrite); // direct printf output to LCD lcdClear(); lcdGotoXY(0,0); //goto line 1 , pos 1 rprintf("V%d.%d A%d.%d W%d.%d",battvolts/10,battvolts%10,windamp/10,windamp%10,windWatts/10,windWatts%10); lcdGotoXY(0,1); //goto line 2 , pos 1 rprintf("%dRPM %dKph %d %d",wmrpm,speed, outtempOut, insidetempOut); } } void checkDirection(void) { if (0) { } else if ( !(PINC & (1< maxwmrpm) { maxwmrpm = wmrpm; } if (wmrpm <= minwmrpm) { minwmrpm = wmrpm; } speed = windpulse/WSDivider; if (speed > maxspeed) { maxspeed = speed; } if (speed <= minspeed) { minspeed = speed; } battvolts = volts/VOLTDivider*10; if (battvolts > maxvolts) { maxvolts = battvolts; } if (battvolts <= minvolts) { minvolts = battvolts; } windamp = (shuntvolts - WindVoltOffset) / WindAmpDivider*10; if (windamp > maxshuntvolts) { maxshuntvolts = windamp; } if (windamp <= minshuntvolts) { minshuntvolts = windamp; } windWatts = (battvolts/10) * (windamp/10)*10; solaramp = (solarvolts - SolarVoltOffset) / SolarAmpDivider*10; if (solaramp > maxsolarvolts) { maxsolarvolts = solaramp; } if (solaramp <= minsolarvolts) { minsolarvolts = solaramp; } outamp = (outvolts - OutputVoltOffset) / OutputAmpDivider*10; if (outamp > maxoutvolts) { maxoutvolts = outamp; } if (outamp <= minoutvolts) { minoutvolts = outamp; } recttempOut = recttemp*0.254; if (recttempOut > maxrecttemp) { maxrecttemp = recttempOut; } if (recttempOut <= minrecttemp) { minrecttemp = recttempOut; } outtempOut = outtemp*0.254; if (outtempOut > maxouttemp) { maxouttemp = outtempOut; } if (outtempOut <= minouttemp) { minouttemp = outtempOut; } insidetempOut = insidetemp*0.254; if (insidetempOut > maxinsidetemp) { maxinsidetemp = insidetempOut; } if (insidetempOut <= mininsidetemp) { mininsidetemp = insidetempOut; } barometerOut = barometer*0.254; if (barometerOut > maxbarometer) { maxbarometer = barometerOut; } if (barometerOut <= minbarometer) { minbarometer = barometerOut; } } void rpmSetup(void) { extintInit(); extintConfigure(EXTINT0, EXTINT_EDGE_RISING); extintConfigure(EXTINT1, EXTINT_EDGE_RISING); extintAttach(EXTINT0, myInt0Handler); extintAttach(EXTINT1, myInt1Handler); sbi(GIMSK, INT0); sbi(GIMSK, INT1); } void myInt0Handler(void) { Int0Count++; } void myInt1Handler(void) { Int1Count++; } void SwitchToCharging(void) { ClearBit(4, PORTB) ; return; } void SwitchToLoad(void) { SetBit(4, PORTB) ; return; } void mmcStart(void) { //Code added to fill buffer with something int i; u08 mystring[20] = "01234567890123456789"; c = 0; for (i=0;i<=512;i++) { buffer[i] = mystring[c]; c++; if (c > 19) { c = 0; } } //Code added to fill buffer with something // initialize card rprintf("\r\nResetting MMC/SD Card\r\n"); mmcReset(); } void mmcWriteBuffer(void) { // write current sector with data from buffer vt100SetCursorPos(4,10); rprintf("\r\nWrite Sector %d\r\n", sector); mmcWrite(sector, buffer); sector+=512; }