Changeset - 82d01332900d
[Not reviewed]
default
0 5 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-04-03 21:31:54
mkroening@CL-ENS241-07.cedarville.edu
Sensor fixes
5 files changed with 69 insertions and 94 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -27,14 +27,14 @@
 
#define DATATYPES_GEIGER 4
 
#define DATATYPES_CAMERA 3
 
 
//Sensors and IO
 
#define SENSOR_LOOP 200				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 0			// Temperature threshold in Fahrenheit where heater is activated
 
#define CAMERA_FREQ 5000		// Camera pulse frequency (Should be 30000 for 30 Secs)
 
#define CAMERA_PULSE 2500			// Camera pulse duration
 
#define CAMERA_FREQ 30000		// Camera pulse frequency (Should be 30000 for 30 Secs)
 
#define CAMERA_PULSE 500 			// Camera pulse duration
 
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
 
 #define PRESSURE_ADDR 0xEE		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x27		// Read 0x28 - Write 0x27
slave/slave/lib/i2c.c
Show inline comments
 
@@ -43,13 +43,13 @@ unsigned char i2c_start(unsigned char ad
 
 
	// send START condition
 
	TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
 
 
	// wait until transmission completed
 
//	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	while(!(TWCR & (1<<TWINT)));
 
//	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
//			break;	// Timeout Reached!
 
//		}
 
//	}
 
@@ -61,13 +61,13 @@ unsigned char i2c_start(unsigned char ad
 
	// send device address
 
	TWDR = address;
 
	TWCR = (1<<TWINT) | (1<<TWEN);
 
 
	// wail until transmission completed and ACK/NACK has been received
 
//	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	while(!(TWCR & (1<<TWINT)));
 
//	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
//			break;	// Timeout Reached!
 
//		}
 
//	}
 
@@ -96,55 +96,55 @@ void i2c_start_wait(unsigned char addres
 
    while ( 1 )
 
    {
 
	    // send START condition
 
	    TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
 
    
 
    	// wait until transmission completed
 
		startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)))
 
		{
 
			if ((time_millis() - startTime) > 10)
 
			{
 
				break;	// Timeout Reached!
 
			}
 
		}
 
		//startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)));
 
		//{
 
			//if ((time_millis() - startTime) > 10)
 
			//{
 
				//break;	// Timeout Reached!
 
			//}
 
		//}
 
    
 
    	// check value of TWI Status Register. Mask prescaler bits.
 
    	twst = TW_STATUS & 0xF8;
 
    	if ( (twst != TW_START) && (twst != TW_REP_START)) continue;
 
    
 
    	// send device address
 
    	TWDR = address;
 
    	TWCR = (1<<TWINT) | (1<<TWEN);
 
    
 
    	// wail until transmission completed
 
		startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)))
 
		{
 
			if ((time_millis() - startTime) > 10)
 
			{
 
				break;	// Timeout Reached!
 
			}
 
		}
 
		//startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)));
 
		//{
 
			//if ((time_millis() - startTime) > 10)
 
			//{
 
				//break;	// Timeout Reached!
 
			//}
 
		//}
 
    
 
    	// check value of TWI Status Register. Mask prescaler bits.
 
    	twst = TW_STATUS & 0xF8;
 
    	if ( (twst == TW_MT_SLA_NACK )||(twst ==TW_MR_DATA_NACK) ) 
 
    	{    	    
 
    	    /* device busy, send stop condition to terminate write operation */
 
	        TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
 
	        
 
	        // wait until stop condition is executed and bus released
 
			startTime = time_millis();
 
	        while(TWCR & (1<<TWSTO))
 
			{
 
				if ((time_millis() - startTime) > 10)
 
				{
 
					break;	// Timeout Reached!
 
				}
 
			}
 
			//startTime = time_millis();
 
	        while(TWCR & (1<<TWSTO));
 
			//{
 
				//if ((time_millis() - startTime) > 10)
 
				//{
 
					//break;	// Timeout Reached!
 
				//}
 
			//}
 
	        
 
    	    continue;
 
    	}
 
    	//if( twst != TW_MT_SLA_ACK) return 1;
 
    	break;
 
     }
 
@@ -176,13 +176,13 @@ void i2c_stop(void)
 
{
 
    /* send stop condition */
 
	TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
 
	
 
	// wait until stop condition is executed and bus released
 
//	startTime = time_millis();
 
	while(TWCR & (1<<TWSTO))
 
	while(TWCR & (1<<TWSTO));
 
	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
//			break;	// Timeout Reached!
 
//		}
 
	}
 
@@ -204,20 +204,20 @@ unsigned char i2c_writeX( unsigned char 
 
    
 
	// send data to the previously addressed device
 
	TWDR = data;
 
	TWCR = (1<<TWINT) | (1<<TWEN);
 
 
	// wait until transmission completed
 
	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}
 
	//startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)));
 
	//{
 
		//if ((time_millis() - startTime) > 10)
 
		//{
 
			//break;	// Timeout Reached!
 
		//}
 
	//}
 
	
 
	
 
	// check value of TWI Status Register. Mask prescaler bits
 
	twst = TW_STATUS & 0xF8;
 
	if( twst != TW_MT_DATA_ACK) return 1;
 
	return 0;
 
@@ -232,20 +232,20 @@ unsigned char i2c_writeX( unsigned char 
 
 Return:  byte read from I2C device
 
*************************************************************************/
 
unsigned char i2c_readAck(void)
 
{
 
	TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
 
	
 
	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}  
 
	//startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)));
 
	//{
 
		//if ((time_millis() - startTime) > 10)
 
		//{
 
			//break;	// Timeout Reached!
 
		//}
 
	//}  
 
 
    return TWDR;
 
 
}/* i2c_readAck */
 
 
 
@@ -256,20 +256,20 @@ unsigned char i2c_readAck(void)
 
 Return:  byte read from I2C device
 
*************************************************************************/
 
unsigned char i2c_readNak(void)
 
{
 
	TWCR = (1<<TWINT) | (1<<TWEN);
 
	
 
	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}
 
	//startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)));
 
	//{
 
		//if ((time_millis() - startTime) > 10)
 
		//{
 
			//break;	// Timeout Reached!
 
		//}
 
	//}
 
	
 
    return TWDR;
 
 
}/* i2c_readNak */
 
 
slave/slave/lib/sensors.c
Show inline comments
 
@@ -183,14 +183,15 @@ void sensors_readPressure()
 
	}
 
	
 
	x1 = (pressure >> 8) * (pressure >> 8);
 
	x1 = (x1 * 3038) >> 16;
 
	x2 = (-7357 * pressure) >> 16;
 
	pressure += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
	pressure = pressure - 21000;	// Linear Offset (Debug?)
 
	
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));	// 101325
 
}
 
 
void sensors_readHumid()
 
{
 
	//i2c_write(HUMID_ADDR, 0x00, 0x00);		//Measurement Request
 
	//humid = i2c_read16(HUMID_ADDR);
slave/slave/modules.c
Show inline comments
 
@@ -15,13 +15,12 @@
 
 #include "lib/i2c.h"
 
 #include "lib/sensors.h"
 
 #include "lib/loopTimer.h"
 
 #include "lib/led.h"
 
 
 
 uint32_t lastPicture;
 
 uint8_t pulseOn;
 
 uint32_t lastRefresh;	// Time in ms when last geiger refresh occurred 
 
 
 
 void modules_setup(uint8_t id)
 
 {
 
	switch(id)
 
	{
 
@@ -110,14 +109,13 @@
 
 }
 
  
 
  
 
  
 
 void modules_cameras_setup()
 
 {
 
	 lastPicture = time_millis();
 
	 pulseOn = time_millis();	 
 
	 lastPicture = time_millis();	 
 
	 
 
	 DDRA |= (1 << DDA0);	// Set PA0 to Output for Camera
 
	 DDRA |= (1 << DDA1);	// Set PA1 to Output for Camera
 
	 DDRA |= (1 << DDA2);	// Set PA2 to Output for Camera
 
	 DDRA |= (1 << DDA3);	// Set PA3 to Output for Camera
 
 }
 
@@ -153,28 +151,25 @@
 
		}			
 
	  
 
 }
 
  
 
 void modules_cameras()
 
 {
 
	 
 
	// Gathers data and performs functions for cameras daughter board
 
		
 
		//cameras_readAccelXYZ();
 
		
 
		//if ((time_millis() - pulseOn) > CAMERA_PULSE)
 
		//{
 
		//	PORTA &= ~(1 << PA0);	// Pull pin on usb low
 
		//	PORTA &= ~(1 << PA1);	// Pull pin on usb low
 
		//	PORTA &= ~(1 << PA2);	// Pull pin on usb low
 
		//	PORTA &= ~(1 << PA3);	// Pull pin on usb low
 
			
 
		//	if ((time_millis() - lastPicture) > CAMERA_FREQ)	// Frequency of photos
 
		//	{
 
		//		cameras_sendPulse();
 
		//		lastPicture = time_millis();
 
		//	}
 
			
 
		//	pulseOn = time_millis();
 
		//}
 
		
 
		if ((time_millis() - lastPicture) > CAMERA_FREQ)
 
		{
 
			cameras_sendPulse();
 
			lastPicture = time_millis();
 
		}
 
		else if ((time_millis() - lastPicture) > CAMERA_PULSE)
 
		{
 
			PORTA &= ~(1 << PA0);	// Pull pin on usb low
 
			PORTA &= ~(1 << PA1);	// Pull pin on usb low
 
			PORTA &= ~(1 << PA2);	// Pull pin on usb low
 
			PORTA &= ~(1 << PA3);	// Pull pin on usb low
 
		}		
 
 } 
 
  
 
\ No newline at end of file
slave/slave/slave.c
Show inline comments
 
@@ -34,14 +34,12 @@
 
#include "lib/cameras.h"
 
#include "lib/loopTimer.h"
 
#include "lib/masterComm.h"
 
#include "lib/watchdog.h"
 

	
 
bool WDTreset = false;
 
 uint32_t lastPicture;
 
 uint8_t pulseOn;
 

	
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	WDTreset = ((MCUSR & 0b00001000) > 0);	// Check if WDT reset occured
 
	MCUSR = 0;		// Clear reset flags
 
@@ -104,31 +102,12 @@ int main(void)
 
			
 
// Writes ID to EEPROM, change for all modules and delete after programming
 
// 0 is for generic setup,	 1 is for sensors,	 2 is for Geiger,	3 is for cameras
 
//i2c_write(EEPROM_ADDR, 0x05, 0x02);			
 
			
 
		}	// IFloop
 
		
 
		//if (io_getModuleId() == 3)
 
		//{
 
		//	if ((time_millis() - pulseOn) > CAMERA_PULSE)
 
		//	{
 
		//		PORTA &= ~(1 << PA0);	// Pull pin on usb low
 
		//		PORTA &= ~(1 << PA1);	// Pull pin on usb low
 
		//		PORTA &= ~(1 << PA2);	// Pull pin on usb low
 
		//		PORTA &= ~(1 << PA3);	// Pull pin on usb low
 
				
 
		//		if ((time_millis() - lastPicture) > CAMERA_FREQ)	// Frequency of photos
 
		//		{
 
		//			cameras_sendPulse();
 
		//			lastPicture = time_millis();
 
		//		}
 
				
 
		//		pulseOn = time_millis();
 
		//	}
 
		//}
 

	
 
    }	// While(1)
 
	
 
	return 0;
 
}	// Main
 

	
0 comments (0 inline, 0 general)