Changeset - a7b1f3353188
[Not reviewed]
default
0 3 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-03-15 16:31:12
ethanzonca@CL-ENS241-08.cedarville.edu
Calibrated battery voltage measurement for master
3 files changed with 8 insertions and 4 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
/*
 
 * Master Firmware: Configuration
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#ifndef CONFIG_H_
 
#define CONFIG_H_
 
 
#include <avr/pgmspace.h>
 
 
// --------------------------------------------------------------------------
 
// Hardware settings
 
// --------------------------------------------------------------------------
 
 
#define F_CPU 11059200
 
#define BOARDTEMP_ADDR 0x90
 
 
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
// Debug Output
 
//#define DEBUG_OUTPUT
 
 
// Blackout (turn off all but power LEDs)
 
#define BLACKOUT_ENABLE
 
#define BLACKOUT_TIMEOUT 300000 // Blackout after 5 minutes (hopefully after fix)
 
 
// Board heater setpoint
 
#define HEATER_THRESHOLD 60
 
#define HEATER_THRESHOLD 80
 
 
// Touchdown buzzer
 
#define BUZZER_RATE 3000
 
#define BUZZER_DURATION 1
 
#define BUZZER_FAILSAFE_DURATION 600000
 
#define BUZZER_TRIGGER_MINDURATION 1
 
#define BUZZER_TRIGGER_MAXALTITUDE 1
 
 
// --------------------------------------------------------------------------
 
// Error Codes config (logger.c)
 
// --------------------------------------------------------------------------
 
 
// SD Card
 
#define ERROR_SLAVETIMEOUT 0
 
#define ERROR_SD_INIT 1
 
#define ERROR_SD_PARTITION 2
 
#define ERROR_SD_FILE 3
 
#define ERROR_XBEETIMEOUT 4
 
#define ERROR_FATAL 5
 
#define ERROR_ATFAIL 6
 
#define ERROR_EXITAT 7
 
#define ERROR_INFOTEXT 8
 
// !!! Please specify/update detailed messages for these error codes in logger.c
 
 
// --------------------------------------------------------------------------
 
// Slave Sensors config (slavesensors.c)
 
// --------------------------------------------------------------------------
 
 
// Slave data structure size
 
#define MAX_NUM_SLAVES 5	// Maximum number of nodes in the system
 
#define MAX_NUM_SENSORS 10	// Maximum number of unique types of sensors in the system
 
 
// Node identifier of log destination xbee
 
#define XBEE_LOGDEST_NAME "HAB-LOGGER"
 
 
// Rate to request data from slaves. Must be greater than AT delay * number slaves
 
#define DATAREQUEST_RATE 3000
 
 
// Timeouts
 
#define TIMEOUT_SLAVEREQUEST 1000
 
#define TIMEOUT_NETWORKSCAN 7000
 
#define TIMEOUT_EXITAT 2000
 
#define TIMEOUT_XBEERESPONSE 2000
 
 
// Slave data request max retries (for retry upon corrupt data reception)
 
#define MAX_SLAVEREQUEST_RETRIES 2
 
 
master/master/lib/sensors.c
Show inline comments
 
/*
 
 * sensors.c
 
 *
 
 * Created: 11/19/2012 9:25:01 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "i2c.h"
 
 
void sensors_setup() 
 
{
 
	//ADC register configurations for battery level detection on PA0
 
	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 |= 0;											// Select ADC0 as the conversion channel (default)
 
	ADCSRA |= (1 << ADATE);									// Enables auto trigger, determined in ADCSRB bits ADTS
 
	ADCSRB &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));// Set ADC auto trigger source to free running mode
 
	ADCSRA |= (1 << ADEN);									// Enable ADC
 
	ADCSRA |= (1 << ADSC);									// Start ADC measurements.  ADC should now continuously run conversions, which are stored in ADCH 0x79	
 
}
 
 
int8_t	boardTemp = 255;	// Board Temperature (from i2c)
 

	
 
void sensors_readBoardTemp()
 
{
 
	boardTemp = i2c_read(BOARDTEMP_ADDR, 0x00);		// Read only the first byte of data (we don't need the resolution here)
 
	boardTemp = ((boardTemp*18)/10) + (32);			// Converting Celsius to Fahrenheit
 
	boardTemp = boardTemp - 3;						// Linear offset
 
}
 

	
 
int8_t sensors_getBoardTemp(void)
 
{
 
	return boardTemp;
 
}
 
 
uint16_t batt;		// Battery voltage (from ADC)
 
 
uint16_t vBatt;
 
void sensors_readBatt()
 
{
 
	uint8_t 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;
 
}
 
 
uint16_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
	return vBatt;
 
}
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -62,96 +62,100 @@ int main(void)
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	uint32_t lastDataReq = 0;
 
	uint32_t lastBuzz = 0;
 
	
 
	// Result of last parser run
 
	int parseResult = PARSERESULT_NODATA;
 
	
 
	// FIXME: Probably don't need this.
 
	serial1_ioff();
 
	
 
	while(1)
 
    {
 
		// Periodic: LED execution indicator
 
		if(time_millis() - lastLedCycle > LEDCYCLE_RATE) 
 
		{
 
			led_power_toggle();
 
			led_spin();
 
			
 
			// Enable GPS serial interrupts if we aren't doing AFSK
 
			if(!afsk_busy())
 
				serial1_ion();
 
				
 
			lastLedCycle = time_millis();	
 
		}
 
		
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			led_on(LED_CYCLE);
 
			
 
			heater_regulateTemp();
 
			
 
			// Turn on sideboard LED if we have a fix
 
			if(gps_hasfix()) 
 
			{
 
				led_on(LED_SIDEBOARD);
 
			}
 
			else 
 
			{
 
				led_off(LED_SIDEBOARD);
 
			}
 
			
 
			sensors_readBoardTemp();
 
			sensors_readBatt();
 
			
 
			//char buftmp[15];
 
			//snprintf(buftmp, 15, "vbatt: %u\r\n", sensors_getBatt());
 
			//serial0_sendString(buftmp);
 
		
 
			// Write CSV header and log data values
 
			sensordata_logvalues();			
 
			
 
			led_off(LED_CYCLE);
 
			lastLog = time_millis();
 
		}		
 
		
 
		// Periodic: Buzzer
 
		if(time_millis() - lastBuzz > BUZZER_RATE) {
 
			if(sensordata_isTouchdown())
 
			{
 
				led_on(LED_BUZZ);
 
				_delay_ms(BUZZER_DURATION);
 
				led_off(LED_BUZZ);
 
			}			
 
			lastBuzz = time_millis();
 
		}
 
		
 
		// Periodic: Data Request
 
		if(time_millis() - lastDataReq > DATAREQUEST_RATE)  
 
		{
 
			// Start getting values for next transmission
 
			if(slavesensors_isrequesting())
 
			{
 
				// TODO: something is terribly wrong. Timeout?
 
			}
 
			else
 
			{
 
				slavesensors_startprocess();
 
			}
 
			
 
			lastDataReq = time_millis();
 
		}
 
		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			// Check for touchdown
 
			sensordata_checkTouchdown();
 
			
 
			// Ensure we aren't already transmitting
 
			while(afsk_busy());
 
			
 
			// Turn off interrupts and transmit APRS sentence
 
			serial1_ioff();
 
			aprs_send(); // non-blocking
0 comments (0 inline, 0 general)