Changeset - 381ec8b85cb2
[Not reviewed]
default
0 3 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-04-10 21:20:17
kripperger@CL-SEC241-09.cedarville.edu
Geiger moving avg filter improvements
3 files changed with 15 insertions and 13 deletions:
0 comments (0 inline, 0 general)
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"
 
 
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[30];		// Counts per Second
 
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 30 second moving average of the CPS
 
	//	The following is a 60 second moving average of the CPS
 
	seconds++;
 
	if (seconds>=30)
 
	if (seconds>=60)
 
	{
 
		CPM = 0;
 
		for (i=0;i<30;i++)
 
		{
 
			CPM = CPM + CPS[i];
 
		}
 
		CPM = CPM * 2;
 
		seconds = 0;
 
	}
 
	
 
	CPS[seconds] = counts;
 
	counts = 0;
 
	
 
	CPM = 0;
 
	for (i=0;i<60;i++)
 
	{
 
		CPM = CPM + CPS[i];
 
	}
 
	//CPM = CPM * 2;	// For a 30 second moving average
 
	
 
	
 
}
 
 
ISR(PCINT0_vect)    // Interrupt on PA0
 
{
 
	if(((PINA & 0b00000001))==1)
 
	{
 
		// Interrupts when pulse received from Geiger tube
 
		counts++;	// Increment counter.
 
		countStart = time_millis();
 
		
 
		led_on(1);
 
		io_piezoOn();
 
		io_piezoOff();
 
		
 
		_delay_us(50);
 
	}
 
 
}
 
 
uint16_t geiger_getCpm()
 
{
 
	return CPM;
 
}
 
 
uint8_t geiger_getCount()	//DEBUG
 
{
 
	return counts;
 
}
 
 
uint32_t geiger_getCountStart()
 
{
 
	return countStart;
 
}
 
 
void geiger_on()
 
{
 
	// Turn the Flyback Transformer on
slave/slave/modules.c
Show inline comments
 
@@ -130,52 +130,52 @@
 
 }
 
  
 
 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()) > 50)
 
	if ((time_millis() - geiger_getCountStart()) > 20)
 
	{
 
		led_off(1);
 
		io_piezoOff();
 
		io_piezoOn();
 
	}		
 
					
 
	  
 
 }
 
  
 
 void modules_cameras()
 
 {
 
	 
 
	// Gathers data and performs functions for cameras daughter board
 
		
 
		//cameras_readAccelXYZ();
 
		
 
		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
 
		}		
slave/slave/slave.c
Show inline comments
 
@@ -73,49 +73,49 @@ int main(void)
 
	uint32_t lastLoop = 0;	// Time in ms when last loop occurred 
 
	
 
	// Serial output //DEBUG
 
	char buff[128];						//Buffer for serial output //DEBUG
 
	serial1_sendString("Starting Slave\r\n");	//DEBUG
 
	
 
    while(1)
 
    {	
 
		wdt_reset();	// Resets WDT (to prevent restart)
 
		
 
		// Master communication
 
		masterComm_checkParser();	//Checks parser for data requests from master
 

	
 
		// Main slave operations
 
		if ((time_millis() - lastLoop) > SENSOR_LOOP)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			led_on(0);
 
			
 
			sensors_readBatt();				// Read Battery level
 
			sensors_readBoardTemp();		// Read board temperature sensor (Common on all slaves) (Data Read)
 
			modules_run(io_getModuleId());	// Runs specific module functions (like data reading)
 
			
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Press: %lu |Altitude: %lu |Batt: %u |spiTemp: %i |CPM: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt(),sensors_getSpiTemp(),geiger_getCount()); //DEBUG
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Press: %lu |Altitude: %lu |Batt: %u |spiTemp: %i |CPM: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt(),sensors_getSpiTemp(),geiger_getCpm()); //DEBUG
 
			serial1_sendString(buff); //DEBUG
 
			
 
			led_off(0);
 
			lastLoop = time_millis();
 
			
 
// 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
 

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

	
 

	
 

	
 

	
 

	
 
		/********Examples of data reading and getting******************
 
		x = geiger_getCpm();				//Data get
 
		x = sensors_getSpiTemp();			//Data get
 
		x = sensors_getBoardTemp();			//Data get
0 comments (0 inline, 0 general)