Changeset - f9a07af0c946
[Not reviewed]
Merge default
0 8 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-12 13:24:37
ethanzonca@CL-ENS241-08.cedarville.edu
Merge
8 files changed with 138 insertions and 37 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -9,11 +9,15 @@
 
 #ifndef CONFIG_H_
 
 #define CONFIG_H_
 
 
 #define F_CPU 11059200
 
 #define F_CPU 11059200				// Clock frequency (used in calculations)
 
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 115200
 
 
#define SENSOR_LOOP 100				// Frequency of sensor reads (in ms)
 
 
#define HEATER_THRESHOLD 70			// Temperature threshold in Fahrenheit where heater is activated
 
 
 //I2C Addresses
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
 
 #define PRESSURE_ADDR 0xA1		//THIS VALUE IS WRONG
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -6,10 +6,11 @@
 
 */ 
 
 
 #include <avr/io.h>
 
#include "../config.h"
 
#include "inputOutput.h"
 
 
 
 void io_configure()
 
 {
 
	 
 
	// Configure ports/pins
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
 
	
 
@@ -17,12 +18,11 @@
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
 
 }
 
	 
 
 }
 
 
 
 uint8_t io_getModuleId()
 
 {
 
	 
 
	// Get ID from rotary dip and return it. 
 
	uint8_t id;
 
	id = 0;
 
@@ -38,4 +38,30 @@
 
	id = (id & 0b0111);					//Mask bits
 
 
	return id;
 
 }
 
 
 
 void io_heaterOn()
 
 {		
 
	PORTB |= (1 << PB4);	//ON
 
 }
 
 
 
 void io_heaterOff()
 
 {
 
	PORTB &= ~(1 << PB4);	//OFF
 
 }
 
 
 
 
 
  void io_regulateTemp()
 
  {
 
	  // Gets board temperature and enables heater if below threshold
 
	  if (sensors_getBoardTemp() <= HEATER_THRESHOLD)
 
	  {
 
		  io_heaterOn();
 
		  led_on(1);
 
	  } 
 
	  else if (sensors_getBoardTemp() > (HEATER_THRESHOLD + 5))
 
	  {
 
		  io_heaterOff();
 
		  led_off(1);
 
	  }
 
 }
 
\ No newline at end of file
slave/slave/lib/inputOutput.h
Show inline comments
 
@@ -12,5 +12,9 @@
 
 void io_configure();
 
 uint8_t io_getModuleId();	// Get ID from rotary dip and return it.
 
 
void io_heaterOn();
 
void io_heaterOff();
 
 
void io_regulateTemp();		// Gets board temperature and enables heater if below threshold
 
 
 #endif /* IO_H_ */
 
\ No newline at end of file
slave/slave/lib/led.c
Show inline comments
 
@@ -18,25 +18,94 @@ void led_configure()
 
	
 
	// Setup PWM
 
		//TODO
 
}
 
	
 
}
 
 
void led_on(uint8_t led)
 
{
 
	// Turn the specified LED on
 
	switch(led)
 
	{
 
		case 0:
 
			PORTB |= (1 << PB0);	//ON
 
			break;
 
	 
 
		case 1:
 
			PORTB |= (1 << PB1);	//ON
 
			break;
 
			
 
		case 2:
 
			PORTB |= (1 << PB2);	//ON
 
			break;
 
			
 
		case 3:
 
			PORTB |= (1 << PB3);	//ON
 
			break;
 
			
 
		default:
 
			
 
			break;
 
}
 
}
 
 
 
void led_off(uint8_t led)
 
{
 
	// Turn the specified LED off
 
	switch(led)
 
	{
 
		case 0:
 
			PORTB &= ~(1 << PB0);	//OFF
 
			break;
 
	 
 
		case 1:
 
			PORTB &= ~(1 << PB1);	//OFF
 
			break;
 
		
 
		case 2:
 
			PORTB &= ~(1 << PB2);	//OFF
 
			break;
 
		
 
		case 3:
 
			PORTB &= ~(1 << PB3);	//OFF
 
			break;
 
		
 
		default:
 
			
 
			break;
 
}
 
}
 
 
 
void led_toggle(uint8_t led)
 
{
 
	// Toggle the specified LED
 
	switch(led)
 
	{
 
		case 0:
 
			if ((PORTB & 0b00000001) == 1)		PORTB &= ~(1 << PB0);	//OFF
 
			else								PORTB |= (1 << PB0);	//ON
 
			break;
 
	 
 
		case 1:
 
			if (((PORTB & 0b00000010)>>1) == 1)	PORTB &= ~(1 << PB1);	//OFF
 
			else								PORTB |= (1 << PB1);	//ON
 
			break;
 
		
 
		case 2:
 
			if (((PORTB & 0b00000100)>>2) == 1)	PORTB &= ~(1 << PB2);	//OFF
 
			else								PORTB |= (1 << PB2);	//ON
 
			break;
 
		
 
		case 3:
 
			if (((PORTB & 0b00001000)>>3) == 1)	PORTB &= ~(1 << PB3);	//OFF
 
			else								PORTB |= (1 << PB3);	//ON
 
			break;
 
		
 
		default:
 
		
 
			break;
 
	}
 
}
 
 
void led_output(uint8_t led)
slave/slave/lib/led.h
Show inline comments
 
@@ -14,6 +14,7 @@
 
 #define STAT 3
 
 #define OK 4
 
 
 
 void led_configure();
 
 void led_on(uint8_t led);
 
 void led_off(uint8_t led);
slave/slave/lib/loopTimer.c
Show inline comments
 
@@ -12,13 +12,11 @@
 
#include <util/delay.h>
 
#include "loopTimer.h"
 
 
volatile uint32_t millis = 0; // Milliseconds since initialization
 
volatile uint32_t millis; // Milliseconds since initialization
 

	
 

	
 
void time_setup()
 
{
 
	DDRA = 0xFF;
 
	
 
	// Generic microcontroller config options
 
	OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler
 
	
 
@@ -31,7 +29,9 @@ void time_setup()
 

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

	
 
uint32_t time_millis()
slave/slave/modules.c
Show inline comments
 
@@ -43,7 +43,6 @@
 
 
 
 void modules_run(uint8_t id)
 
 {
 
	sensors_readBoardTemp();		// Read board temperature sensor (Common on all slaves) (Data Read)
 
	switch(id)
 
	{
 
		case 0:
slave/slave/slave.c
Show inline comments
 
@@ -28,7 +28,7 @@
 
#include "lib/geiger.h"
 
#include "lib/sensors.h"
 
#include "lib/cameras.h"
 
 
#include "lib/loopTimer.h"
 
 
void micro_setup()
 
{
 
@@ -42,50 +42,49 @@ int main(void)
 
{
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	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	
 
	//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///////////////////////////////////////////////////////////////////////////////////////
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting\r\n");
 
	
 
	
 
    while(1)
 
    {			
 
		if ((time_millis() % SENSOR_LOOP) == 0)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			sensors_readBoardTemp();	// Read board temperature sensor (Common on all slaves) (Data Read)
 
		modules_run(moduleID);	// Runs specific module functions (like data reading)
 
								// Use program timer to run every so often. Time interval defined in config.h (TODO)
 
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 
 
		// This is just a serial output example
 
		//sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
			snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu\r\n",moduleID,sensors_getBoardTemp(),time_millis()); //DEBUG
 
			serial0_sendString(buff); //DEBUG
 
			
 
			led_toggle(0);		// Toggle LED0(Blue) to show loop running	
 
		}
 
 
 
        //i2c_write(RTC_ADDR, 0x05, 0x3A);	//DEBUG: EXAMPLE//////////////////////////////////////////////////////
 
    }
 
		
 
        _delay_ms(10);	//DEBUG/////////////
 
	return 0;
 
}
 
		
 
		
 
		test = geiger_getCount();	//Debug//////////
 
		
 
		led_output(test);//DEBUG//////////
 
		
 
		
 
		/********Examples of data reading and getting******************
 
@@ -96,17 +95,16 @@ int main(void)
 
		sensors_readSpiTemp();			//Data Read
 
		sensors_readBoardTemp();		//Data Read
 
		
 
		led_output(0xFF);					//Output value to LED array
 
		i2c_write(RTC_ADDR, 0x05, 0x3A);	//i2c Write Example
 
		
 
		PORTA &= ~(1 << PA1);	//OFF
 
		PORTA |= (1 << PA1);	//ON
 
		
 
		sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		serial0_sendString(buff);
 
		
 
		**************************************************************/
 
		
 
		
 
		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)