Changeset - 1614c3d5e9cd
[Not reviewed]
default
0 5 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-01-10 14:45:18
kripperger@CL-SEC241-09.cedarville.edu
Optimizations and setting up loop timer
5 files changed with 8 insertions and 9 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/geiger.c
Show inline comments
 
@@ -35,15 +35,15 @@ ISR(PCINT0_vect)    // Interrupt on PA0
 
{
 
	// Interrupts when pulse received from Geiger tube
 
	counts++;	// Increment counter.
 
}
 
 
uint16_t geiger_getCpm()
 
{
 
	return cpm;
 
}
 
 
uint8_t geiger_getCount()	//DEBUG
 
{
 
	return seconds;
 
	return counts;
 
}
 
slave/slave/lib/loopTimer.c
Show inline comments
 
@@ -6,42 +6,41 @@
 
 */ 
 
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include <util/delay.h>
 
#include "loopTimer.h"
 
 
volatile uint32_t millis = 0; // Milliseconds since initialization
 

	
 

	
 

	
 
void time_setup()
 
{
 
	DDRA = 0xff;
 
	DDRA = 0xFF;
 
	
 
	// Generic microcontroller config options
 
	OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler
 
	
 
	TCCR0A |= (1 << WGM01) | (1 << WGM00); // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well)
 
	TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64
 
	TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts
 
	TIMSK0 |= (1 << TOIE0); // enable overflow interrupt
 
}
 

	
 

	
 
ISR(TIMER0_OVF_vect)
 
{
 
	millis = millis + 1;
 
	millis = millis + 1;		
 
}
 

	
 
uint32_t time_millis()
 
{
 
	return millis; // meh accuracy, but that's OK
 
}
 
 
 
 
 
 
slave/slave/lib/loopTimer.h
Show inline comments
 
/*
 
 * loopTimer.h
 
 *
 
 * Created: 11/29/2012 3:35:34 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef LOOPTIMER_H_
 
#define LOOPTIMER_H_
 
 

	
 
void time_setup();
 

	
 
void time_setup();
 
uint32_t time_millis();
 
 
 
 
#endif /* LOOPTIMER_H_ */
 
\ No newline at end of file
slave/slave/lib/sensors.c
Show inline comments
 
@@ -39,25 +39,25 @@ void sensors_readSpiTemp()
 
	//temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature;	// Sign extend
 
	
 
	temperature = (two & 0x01) ? 0x00DE : temperature;	// Error Condition. If error is detected output is set to 222 degrees (0x00DE)
 
	
 
	// Note: Temperature still needs to be scaled in order to be accurate (eg. boil water). Do this before implementing.
 
	spiTemp = temperature;
 
}
 

	
 
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 - 1;						// Linear offset
 
	boardTemp = boardTemp - 3;						// Linear offset
 
}
 

	
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
slave/slave/slave.c
Show inline comments
 
@@ -33,33 +33,35 @@
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	sei();	// Enable interrupts
 
	
 
}
 
 
 
int main(void)
 
{
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();
 
	led_configure();		// Configure ports and registers for LED operation
 
	io_configure();			// Configure IO ports and registers
 
	
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	uint8_t moduleID = io_getModuleId();	// Slave Module ID from rotary dip switch
 
	modules_setup(moduleID);				// Run setup functions for specific module
 
	
 
	uint32_t milliseconds;
 
	
 
	uint8_t test;	//Debug
 
	uint8_t test2;	//Debug	
 
	
 
 
	
 
	//PORTA &= ~(1 << PA1);	//DEBUG////////////////OFF///////////////////////////////////////////////////////////////
 
	//PORTA |= (1 << PA1);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
	
 
	
 
	// This is just a serial output example
 
	char buff[32];	//DEBUG///////////////////////////////////////////////////////////////////////////////////////
 
@@ -90,21 +92,21 @@ int main(void)
 
		x = geiger_getCpm();			//Data get
 
		x = sensors_getSpiTemp();		//Data get
 
		x = sensors_getBoardTemp();		//Data get
 
		
 
		sensors_readSpiTemp();			//Data Read
 
		sensors_readBoardTemp();		//Data Read
 
		
 
		
 
		**************************************************************/
 
		
 
		
 
		test2 = sensors_getBoardTemp();	//DEBUG///////////////////////////////////////////////////////////////////////////
 
 
		time_millis();
 
 
		sprintf(buff, "|ModuleID: %u |BoardTemp: %u |Seconds: %u\r\n",moduleID,test2,test); //DEBUG
 
		serial0_sendString(buff); //DEBUG
 
 
    }
 
	
 
	return 0;
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)