Changeset - 29db24a20666
[Not reviewed]
default
0 6 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-04-10 18:07:19
kripperger@CL-SEC241-09.cedarville.edu
Geiger CPM averaging
6 files changed with 54 insertions and 11 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/geiger.c
Show inline comments
 
@@ -9,53 +9,75 @@
 
#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 uint16_t CPM;			// Counts per Minuite
 
volatile uint32_t countStart = 0;
 
volatile uint8_t CPS[30];		// 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
 
	seconds++;
 
	if (seconds>=30)
 
	{
 
		cpm = (counts*2);
 
		CPM = 0;
 
		for (i=0;i<30;i++)
 
		{
 
			CPM = CPM + CPS[i];
 
		}
 
		CPM = CPM * 2;
 
		seconds = 0;
 
	}
 
	
 
	CPS[seconds] = counts;
 
		counts = 0;
 
	}
 
	
 
}
 
 
ISR(PCINT0_vect)    // Interrupt on PA0
 
{
 
	if(((PINA & 0b00000001))==1)
 
	{
 
		// Interrupts when pulse received from Geiger tube
 
		counts++;	// Increment counter.
 
		led_toggle(2);
 
		_delay_ms(5);
 
		countStart = time_millis();
 
		
 
		led_on(1);
 
		io_piezoOn();
 
		
 
		_delay_us(50);
 
	}
 
 
}
 
 
uint16_t geiger_getCpm()
 
{
 
	return cpm;
 
	return CPM;
 
}
 
 
uint8_t geiger_getCount()	//DEBUG
 
{
 
	return counts;
 
}
 
 
uint32_t geiger_getCountStart()
 
{
 
	return countStart;
 
}
 
 
void geiger_on()
 
{
 
	// Turn the Flyback Transformer on
 
	PORTA |= (1 << PA1);	//ON
 
	
 
}
slave/slave/lib/geiger.h
Show inline comments
 
@@ -7,11 +7,12 @@
 
 
 
#ifndef GEIGER_H_
 
#define GEIGER_H_
 
 
uint16_t geiger_getCpm();
 
uint8_t geiger_getCount();	//DEBUG
 
uint8_t geiger_getCount();
 
uint32_t geiger_getCountStart();
 
void geiger_on();
 
void geiger_refresh();
 
 
#endif /* GEIGER_H_ */
 
\ No newline at end of file
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -77,12 +77,22 @@ int8_t	moduleID;	// Slave Module ID from
 
 
 
 void io_heaterOff()
 
 {
 
	PORTB &= ~(1 << PB4);	//OFF
 
 }
 
 
 
 void io_piezoOn()
 
 {
 
	 PORTA |= (1 << PA2);	//ON
 
 }
 
  
 
 void io_piezoOff()
 
 {
 
	 PORTA &= ~(1 << PA2);	//OFF
 
 }
 
 
 
 uint8_t io_heaterStatus()
 
 {
 
	 uint8_t state;
 
	 state = 0;
 
	 
 
	 state = ((PORTB & 0b00010000) >> 4);
slave/slave/lib/inputOutput.h
Show inline comments
 
@@ -13,11 +13,13 @@ void io_configure();
 
 
void io_readModuleId();	// Reads ID from rotary dip (or EEPROM).
 
uint8_t io_getModuleId();	// Gets ID and returns it.
 
 
void io_heaterOn();
 
void io_heaterOff();
 
void io_piezoOn();
 
void io_piezoOff();
 
uint8_t io_heaterStatus();
 
 
void io_regulateTemp();		// Gets board temperature and enables heater if below threshold
 
 
#endif /* IO_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -87,14 +87,15 @@
 
	sensors_setupPressure();
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	// Pin setup
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	DDRA |= (1 << DDA1);	// PA1 is an output
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input for count interrupt
 
	DDRA |= (1 << DDA1);	// PA1 is an output for HV control
 
	DDRA |= (1 << DDA2);	// PA2 is an output for piezo
 
	
 
	geiger_on();	// Turn on HV supply
 
	
 
	// Setup for interrupt input on PA0 (PCINT0)
 
	PCMSK0 |= (1 << PCINT0);	// Enable interrupt for PA0
 
	PCICR |= (1 << PCIE0);		// Enable ioc section PCIF0
 
@@ -147,12 +148,19 @@
 
		//lastRefresh = time_millis();
 
		//if ((time_millis() - lastRefresh) > 1000000)
 
		//{
 
		//	geiger_refresh();	//Refreshes every 1000sec (16min)
 
		//}			
 
	  
 
	if ((time_millis() - geiger_getCountStart()) > 50)
 
	{
 
		led_off(1);
 
		io_piezoOff();
 
	}		
 
					
 
	  
 
 }
 
  
 
 void modules_cameras()
 
 {
 
	 
 
	// Gathers data and performs functions for cameras daughter board
slave/slave/slave.c
Show inline comments
 
@@ -91,13 +91,13 @@ int main(void)
 
			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 |Humidity: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt(),sensors_getSpiTemp(),sensors_getHumid()); //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_getCount()); //DEBUG
 
			serial1_sendString(buff); //DEBUG
 
			
 
			led_off(0);
 
			lastLoop = time_millis();
 
			
 
// Writes ID to EEPROM, change for all modules and delete after programming
0 comments (0 inline, 0 general)