Changeset - 7021dff6a9f0
[Not reviewed]
default
0 7 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-04-29 17:17:13
kripperger@CL-SEC241-09.cedarville.edu
Added generic voltage reading function
7 files changed with 36 insertions and 3 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
/*
 
 * config.h
 
 *
 
 * Created: 10/25/2012 10:00:09 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #ifndef CONFIG_H_
 
 #define CONFIG_H_
 
 
 #define F_CPU 11059200				// Clock frequency (used in calculations)
 
 
//Serial
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 115200 
 
 
// 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
 
// 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
 
 
//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
 
 #define LIGHT_ADDR 0x94		// Read 0x95 - Write 0x94
 
 #define ACCEL_ADDR	0x38		// Read 0x39 - Write 0x38
 
 #define RTC_ADDR 0xB2			//DEBUG [Used for testing]      // Read 0xA3 - Write 0xA2
 
 
 
 
 #endif /* CONFIG_H_ */
 
\ No newline at end of file
slave/slave/lib/geiger.c
Show inline comments
 
/*
 
 * geiger.c
 
 *
 
 * Created: 11/19/2012 9:24:05 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "geiger.h"
 
#include "loopTimer.h"
 
#include "led.h"
 
#include "inputOutput.h"
 
 
volatile uint8_t seconds;		// Counts Seconds from Timer2 interrupt
 
volatile uint16_t counts;		// Counts the pulses
 
volatile uint16_t CPM;			// Counts per Minuite
 
volatile uint32_t countStart = 0;
 
volatile uint8_t CPS[60];		// Counts per Second
 
volatile uint8_t i;
 
 
ISR(TIMER2_OVF_vect)    // Timer 2 overflow interrupt handler
 
{
 
	// This executes every second.  Update real-time clocks.
 
	// Used only in Geiger module
 
	
 
	//	The following is a 60 second moving average of the CPS
 
	seconds++;
 
	if (seconds>=60)
 
	{
 
		seconds = 0;
 
	}
 
	
 
	CPS[seconds] = counts;
 
	counts = 0;
 
	
 
	CPM = 0;
slave/slave/lib/inputOutput.c
Show inline comments
 
/*
 
 * io.c
 
 *
 
 * Created: 11/7/2012 7:17:52 PM
 
 *  Author: kripperger
 
 */ 
 
 
#include <avr/io.h>
 
#include "../config.h"
 
#include "inputOutput.h"
 
#include "led.h"
 
#include "sensors.h"
 
#include "i2c.h"
 
 
int8_t	moduleID;	// Slave Module ID from rotary dip switch (or EEPROM)
 
 
 void io_configure()
 
 {
 
	// Configure ports/pins
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK (on SPI bus) to operate)
 
 
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip
 
	
 
	DDRA &= ~(1 << DDA7);		// Set PA7 to input for battery voltage divider
 
 
	//ADC register configurations for battery level detection on PA7
 
	ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);	// Set prescaler for ADC, 128 gives ADC freq of 125 KHz
 
	ADMUX |= (1 << REFS0);									// Set ADC reference voltage to AVCC
 
	//ADMUX |= (1 << ADLAR);								// Sets 10 bit ADC to 8 bit
 
	ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0);		// Select ADC7 as the conversion channel
 
	ADCSRA |= (1 << ADATE);									// Enables auto trigger, determined in ADCSRB bits ADTS
 
	//ADCSRA |= (1 << ADIF);								// 
 
	//ADCSRA |= (1 << ADIE);								// ADC interrupt enable set
 
	ADCSRB &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));// Set ADC auto trigger source to free running mode
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -46,58 +46,58 @@ void masterComm_types()
 
			break;
 
			
 
		case 1:
 
			// Sensors
 
			dataTypes = DATATYPES_SENSOR;
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			dataTypes = DATATYPES_GEIGER;
 
			break;
 
			
 
		case 3:
 
			// Camera
 
			dataTypes = DATATYPES_CAMERA;
 
			break;
 
			
 
		default:
 
			dataTypes = DATATYPES_GENERIC;
 
			break;
 
	}
 
}
 
 
 
void masterComm_packetSend_unsigned(uint8_t id, uint32_t data)
 
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);
 
	serial0_sendChar(']');
 
	serial0_sendChar(masterComm_checksum(buff2));
 
}
 
 
void masterComm_packetSend_signed(uint8_t id, int32_t data)
 
void masterComm_packetSend_signed(uint8_t id, int32_t data)	//Sends the data type and data to master for signed data
 
{
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"%u%ld",id,data);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');
 
	serial0_sendChar(masterComm_checksum(buff2));
 
}
 
 
 
 
void masterComm_modules()
 
{
 
	// Send Board Temperature (Common for all modules)
 
	masterComm_packetSend_signed(0,sensors_getBoardTemp());
 
 
	// Send Heater Status (Common for all modules)
 
	masterComm_packetSend_unsigned(1,io_heaterStatus());
 
	
 
	// Send Battery Level (Common for all modules)
 
	masterComm_packetSend_unsigned(2,sensors_getBatt());
 
	
 
	
 
	// Send module specific sensor readings
 
	switch(io_getModuleId())
slave/slave/lib/sensors.c
Show inline comments
 
@@ -9,48 +9,51 @@
 
#include <inttypes.h>
 
#include <math.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "spi.h"
 
#include "i2c.h"
 
 
int16_t	spiTemp;	// Thermocouple Temperature (from spi)
 
int8_t	boardTemp;	// Board Temperature (from i2c)
 
int32_t ut;			// Temperature from BMP085 (from i2c)
 
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 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;
 
 
int32_t x1;			// The following variables are needed to calculate the true pressure
 
int32_t x2;
 
int32_t x3;
 
int32_t b3;
 
uint32_t b4;
 
int32_t b5;
 
int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t pressure;
 
uint32_t altitude;
 
 
@@ -199,72 +202,96 @@ void sensors_readHumid()
 
 
//humid = i2c_humidRead();
 
 
	//calculations to relative humidity: humid = (humid/((2^14) - 1))*100%       >> is divide by power, << is multiply by power, 2^14-1 = 16383
 
	 //humid = (humid / 16383) * 100;
 
	 //humid = (humid / 2500) * 100;
 
}
 
 
void sensors_readLux()
 
{
 
	lightH = i2c_read(LIGHT_ADDR, 0x03);
 
	lightL = i2c_read(LIGHT_ADDR, 0x04);
 
	
 
	exponent = lightH;
 
	exponent = exponent >> 4;
 
	
 
	lightH = lightH << 4;
 
	mantissa = lightH | lightL;
 
 
	lux = (float)(pow(2,exponent) * mantissa) * 0.045;
 
}
 
 
void sensors_readBatt()
 
{
 
	ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0);		// Select ADC7 as the conversion channel
 
	battL = ADCL;					// Read low battery byte from ADC (all 8 bits)
 
	batt = ADCH;					// Read high battery byte from ADC (only two LSBs)
 
	batt = batt << 8;
 
	batt |= battL;
 
	vBatt = (batt * 10.0) / 67.4;
 
}
 
 
 
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)
 
	
 
	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 = analog << 8;
 
	analog |= analogL;
 
	analog = (analog * 10.0) / 67.4;
 
}
 
 
 
 
 
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
 
int32_t sensors_getPressure(void)	// Gets pressure from variable
 
{
 
	return pressure;
 
}
 
 
uint16_t sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
 
 
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
 
{
 
	return analog;
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
/*
 
 * sensors.h
 
 *
 
 * Created: 11/19/2012 9:24:50 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#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
 
 
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
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -125,48 +125,49 @@
 
 
 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	
 
	sensors_readPressure();			//Data Read
 
	//sensors_readHumid();			//Data Read
 
	sensors_readLux();				//Data Read
 
	 
 
 }
 
  
 
 void modules_geiger()
 
 {
 
	// No data gatering function needed for geiger daughter board
 
		// This is taken care of in interrupt (See geiger.c)
 
		
 
		
 
	//lastRefresh = time_millis();
 
	//if ((time_millis() - lastRefresh) > 1000000)
 
	//{
 
	//	geiger_refresh();	//Refreshes every 1000sec (16min)
 
	//}
 
		
 
	if ((time_millis() - geiger_getCountStart()) > 30)
 
	{
 
		led_off(1);
 
		io_piezoOn();
 
	}		
 
					
 
	  
 
 }
 
  
 
 void modules_cameras()
 
 {
 
	 
 
	// Gathers data and performs functions for cameras daughter board
 
		
 
		//cameras_readAccelXYZ();
 
		
 
		if ((time_millis() - lastPicture) > CAMERA_FREQ)
 
		{
0 comments (0 inline, 0 general)