Changeset - e159e0fa6e70
[Not reviewed]
default
0 6 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-04-29 19:40:00
kripperger@CL-SEC241-09.cedarville.edu
Added generic cases for daughterboard expansion
6 files changed with 123 insertions and 14 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -17,24 +17,27 @@
 
 
// Circular serial buffer size. Must be at least MAX_CMD_LEN + 5
 
#define BUFFER_SIZE 32
 
 
// Maximum payload size of command
 
#define MAX_PAYLOAD_LEN 16
 
 
// Number of datatypes to transmit per module type. This should match what is being sent in masterComm.c
 
#define DATATYPES_GENERIC 3
 
#define DATATYPES_SENSOR 8
 
#define DATATYPES_GEIGER 4
 
#define DATATYPES_CAMERA 3
 
#define DATATYPES_CUSTOM1 3		// Modules already automatically send 3 values (temp, batt, and heater status.)
 
#define DATATYPES_CUSTOM2 3		//    Additional sensor readings should be added onto the 3
 
#define DATATYPES_CUSTOM3 3		//    For example a daughterboard with two sensors would be 3+2=5
 
 
//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 30000		// Camera pulse frequency (Should be 30000 for 30 Secs)
 
#define CAMERA_PULSE 400 			// 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/masterComm.c
Show inline comments
 
@@ -51,24 +51,39 @@ void masterComm_types()
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			dataTypes = DATATYPES_GEIGER;
 
			break;
 
			
 
		case 3:
 
			// Camera
 
			dataTypes = DATATYPES_CAMERA;
 
			break;
 
			
 
		case 4:
 
			// Custom Daughterboard 1
 
			dataTypes = DATATYPES_CUSTOM1;
 
			break;
 
			
 
		case 5:
 
			// Custom Daughterboard 2
 
			dataTypes = DATATYPES_CUSTOM2;
 
			break;
 
		
 
		case 6:
 
			// Custom Daughterboard 3
 
			dataTypes = DATATYPES_CUSTOM3;
 
			break;
 
			
 
		default:
 
			dataTypes = DATATYPES_GENERIC;
 
			break;
 
	}
 
}
 
 
 
void masterComm_packetSend_unsigned(uint8_t id, uint32_t data)	//Sends the data type and data to master for unsigned data
 
{
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"%u%lu",id,data);
 
	serial0_sendString(buff2);
 
@@ -127,26 +142,41 @@ void masterComm_modules()
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			
 
			// Send CPM (radiation)
 
			masterComm_packetSend_unsigned(8,geiger_getCpm());
 
			break;
 
		
 
		case 3:
 
			// Camera
 
			
 
			break;
 
 
		case 4:
 
			// Custom Daughterboard 1
 
			
 
			break;
 
			break;			
 
 
		case 5:
 
			// Custom Daughterboard 2
 
			
 
			break;	
 
			
 
		case 6:
 
			// Custom Daughterboard 3
 
			
 
			break;	
 
		
 
		
 
		default:
 
			
 
			break;
 
	}
 
}
 
 
 
void masterComm_send()
 
{
 
	masterComm_types();		// Calculates how many data types to send
 
	
slave/slave/lib/sensors.c
Show inline comments
 
@@ -22,25 +22,27 @@ int32_t ut;			// Temperature from BMP085
 
int32_t up;			// Pressure from BMP085 (from i2c)
 
uint16_t humid;		// Humidity (from i2c)
 
uint8_t lightH;		// Higher byte from light sensor (from i2c)
 
uint8_t lightL;		// Lower byte from light sensor
 
uint8_t exponent;	// Exponent for Lux
 
uint8_t mantissa;	// Mantissa for Lux
 
uint32_t lux;		// Calculated Lux value
 
uint8_t battL;		// Low byte of ADC
 
uint16_t batt;		// Read battery voltage from ADC
 
uint16_t vBatt;		// battery voltage
 
 
int8_t analogL;		// Low byte of ADC
 
int16_t analog;		// Read analog voltage from ADC
 
int16_t analog[8];		// Read analog voltage from ADC
 
 
uint8_t digital;	// Byte that contains the digital inputs from PORTA
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
int16_t ac2;
 
int16_t ac3;
 
uint16_t ac4;
 
uint16_t ac5;
 
uint16_t ac6;
 
int16_t b1;
 
int16_t b2;
 
int16_t mb;
 
int16_t mc;
 
int16_t md;
 
@@ -233,36 +235,39 @@ void sensors_readBatt()
 
 
 
void sensors_readAnalog(uint8_t pin)
 
{
 
	// Reads analog input on PORTA on the pin (0-7) specified.
 
	
 
	DDRA &= ~(1 << pin);		// Set pin to input
 
	
 
	ADMUX &= 0xF8;
 
	ADMUX |= pin;
 
	
 
	analogL = ADCL;				// Read low battery byte from ADC (all 8 bits)
 
	analog = ADCH;				// Read high battery byte from ADC (only two LSBs)
 
	analog[pin] = ADCH;				// Read high battery byte from ADC (only two LSBs)
 
	
 
	analogL = ADCL;				// Second Read low battery byte from ADC (all 8 bits)
 
	analog = ADCH;				// Second Read high battery byte from ADC (only two LSBs)
 
	analog[pin] = ADCH;				// Second Read high battery byte from ADC (only two LSBs)
 
	
 
	analog = analog << 8;
 
	analog |= analogL;
 
	analog = (analog * 10.0) / 67.4;
 
	analog[pin] = analog[pin] << 8;
 
	analog[pin] |= analogL;
 
	analog[pin] = (analog[pin] * 10.0) / 67.4;
 
}
 
 
 
 
void sensors_readDigital(uint8_t pin)
 
{
 
	DDRA &= ~(1 << pin);		// Set pin to input
 
	digital = PINA;
 
}
 
 
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
 
@@ -277,21 +282,26 @@ uint16_t sensors_getHumid(void)			// Get
 
}
 
 
uint32_t sensors_getLux(void)		// Gets light from variable
 
{
 
	return lux;
 
}
 
 
uint16_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return vBatt;
 
}
 
 
int16_t sensors_getAnalog(void)		// Gets battery voltage from variable
 
int16_t sensors_getAnalog(uint8_t pin)		// Gets battery voltage from variable
 
{
 
	return analog;
 
	return analog[pin];
 
}
 
 
uint8_t sensors_getDigital(uint8_t pin)		// Gets battery voltage from variable
 
{
 
	return ((digital >> pin) & 1);
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
@@ -9,23 +9,25 @@
 
#ifndef SENSORS_H_
 
#define SENSORS_H_
 
 
 
void sensors_setupPressure(void);	// Reads pressure calibration values
 
void sensors_readSpiTemp(void);		// Reads spi temperature
 
void sensors_readBoardTemp(void);	// Reads board temperature
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLux(void);			// Reads lux
 
void sensors_readBatt(void);		// Reads battery voltage from ADC
 
void sensors_readAnalog(uint8_t pin);	// Reads generic analog voltage from ADC
 
void sensors_readDigital(uint8_t pin);	// Reads generic analog voltage from ADC
 
 
int16_t sensors_getSpiTemp(void);	// Gets spi temperature from variable
 
int8_t sensors_getBoardTemp(void);	// Gets board temperature from variable
 
int32_t sensors_getPressure(void);	// Gets pressure from variable
 
uint16_t sensors_getHumid(void);	// Gets humidity from variable
 
uint32_t sensors_getLux(void);		// Gets lux from variable
 
uint16_t sensors_getBatt(void);		// Gets battery voltage from variable
 
int16_t sensors_getAnalog(void);		// Gets battery voltage from variable
 
uint32_t sensors_getAltitude(void);	// Gets altitude from variable
 
int16_t sensors_getAnalog(uint8_t pin);		// Gets battery voltage from variable
 
uint8_t sensors_getDigital(uint8_t pin);		// Gets battery voltage from variable
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -32,24 +32,36 @@
 
		case 1:
 
			modules_sensors_setup();
 
			break;
 
			
 
		case 2:
 
			modules_geiger_setup();
 
			break;
 
			
 
		case 3:
 
			modules_cameras_setup();
 
			break;
 
			
 
		case 4:
 
			modules_custom1_setup();
 
			break;
 
		
 
		case 5:
 
			modules_custom2_setup();
 
			break;
 
			
 
		case 6:
 
			modules_custom3_setup();
 
			break;
 
			
 
		default:
 
			modules_generic_setup();
 
			break;
 
	}
 
	  
 
 }
 
 
 
 void modules_run(uint8_t id)
 
 {
 
	switch(id)
 
	{
 
		case 0:
 
@@ -58,25 +70,37 @@
 
		  
 
		case 1:
 
			modules_sensors();
 
			break;
 
		  
 
		case 2:
 
			modules_geiger();
 
			break;
 
		  
 
		case 3:
 
			modules_cameras();
 
			break;
 
		  
 
			
 
		case 4:
 
			modules_custom1();
 
			break;
 
		
 
		case 5:
 
			modules_custom2();
 
			break;
 
		
 
		case 6:
 
			modules_custom3();
 
			break;
 
			  
 
		default:
 
			modules_generic();
 
			break;
 
	}
 
	  
 
 }
 
 
 
 
 
 void modules_generic_setup()
 
 {
 
	  
 
 }
 
@@ -114,24 +138,44 @@
 
  
 
 void modules_cameras_setup()
 
 {
 
	 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
 
 }
 
  
 
 
 void modules_custom1_setup()
 
 {
 
	 
 
 }
 
 
 void modules_custom2_setup()
 
 {
 
	 
 
 }
 
 
 void modules_custom3_setup()
 
 {
 
	 
 
 }
 
 
 
 
 
 
 
 void modules_generic()
 
 {
 
	// Gathers data and performs functions for generic daughter board
 
	
 
	
 
 }
 
  
 
 void modules_sensors()
 
 {
 
	// Gathers data and performs functions for sensor daughter board
 
	sensors_readBoardTemp();		//Data Read
 
	sensors_readSpiTemp();			//Data Read	
 
@@ -173,13 +217,27 @@
 
		{
 
			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
 
  
 
  void modules_custom1()
 
  {
 
	   
 
  }
 
 
  void modules_custom2()
 
  {
 
   
 
  }
 
 
  void modules_custom3()
 
  {
 
   
 
  }
 
\ No newline at end of file
slave/slave/modules.h
Show inline comments
 
@@ -8,21 +8,27 @@
 
 
#ifndef MODULES_H_
 
#define MODULES_H_
 
 
 void modules_setup(uint8_t id);
 
 void modules_run(uint8_t id);
 
 
 
 // Setup functions for microcontroller configuration per specific daughter board
 
 void modules_generic_setup();
 
 void modules_sensors_setup();
 
 void modules_geiger_setup();
 
 void modules_cameras_setup();
 
 void modules_custom1_setup();
 
 void modules_custom2_setup();
 
 void modules_custom3_setup();
 
 
 // Data acquisition for specific daughter board
 
 void modules_generic();
 
 void modules_sensors();
 
 void modules_geiger();
 
 void modules_cameras();
 
 void modules_custom1();
 
 void modules_custom2();
 
 void modules_custom3();
 
 
 
#endif /* MODULES_H_ */
 
\ No newline at end of file
0 comments (0 inline, 0 general)