Files @ 84e25f7efd5a
Branch filter:

Location: seniordesign-firmware/slave/slave/lib/geiger.c

ethanzonca@CL-ENS241-08.cedarville.edu
Fixed issue where get_latitudeTrimmed() and get_latitudeLSBs() and associated longitude function returned the same results due to buffer sharing and compiler optimization.
/*
 * 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[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;
	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_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
	PORTA |= (1 << PA1);	//ON
	
}

void geiger_refresh()
{
	// Turn the Flyback Transformer off
	PORTA &= ~(1 << PA1);	//OFF
	_delay_ms(1);

	// Turn the Flyback Transformer on
	PORTA |= (1 << PA1);	//ON
}