# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-01-12 13:24:37 # Node ID f9a07af0c94681355dd82623f6515201e76f0450 # Parent 4e5c6467cd0199a032b08fe75a858b64aae1cb8a # Parent cd11bb83de3ada6a660f1d11a8ae8bed48a56fc3 Merge diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -9,13 +9,17 @@ #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 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 BOARDTEMP_ADDR 0x90 // Read 0x91 - Write 0x90 #define PRESSURE_ADDR 0xA1 //THIS VALUE IS WRONG #define HUMID_ADDR 0xA4 //THIS VALUE IS WRONG #define RTC_ADDR 0xA2 //DEBUG [Used for testing] // Read 0xA3 - Write 0xA2 diff --git a/slave/slave/lib/inputOutput.c b/slave/slave/lib/inputOutput.c --- a/slave/slave/lib/inputOutput.c +++ b/slave/slave/lib/inputOutput.c @@ -5,11 +5,12 @@ * Author: kripperger */ - #include +#include +#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; - } \ No newline at end of file + } + + 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 diff --git a/slave/slave/lib/inputOutput.h b/slave/slave/lib/inputOutput.h --- a/slave/slave/lib/inputOutput.h +++ b/slave/slave/lib/inputOutput.h @@ -6,11 +6,15 @@ */ - #ifndef IO_H_ - #define IO_H_ +#ifndef IO_H_ +#define IO_H_ + +void io_configure(); +uint8_t io_getModuleId(); // Get ID from rotary dip and return it. - 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 +#endif /* IO_H_ */ \ No newline at end of file diff --git a/slave/slave/lib/led.c b/slave/slave/lib/led.c --- a/slave/slave/lib/led.c +++ b/slave/slave/lib/led.c @@ -18,25 +18,94 @@ void led_configure() // Setup PWM //TODO - } + void led_on(uint8_t led) { - // Turn the specified LED on - + // 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 - + // 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) diff --git a/slave/slave/lib/led.h b/slave/slave/lib/led.h --- a/slave/slave/lib/led.h +++ b/slave/slave/lib/led.h @@ -6,19 +6,20 @@ */ - #ifndef LED_H_ - #define LED_H_ +#ifndef LED_H_ +#define LED_H_ - #define POWER 1 - #define ERROR 2 - #define STAT 3 - #define OK 4 +#define POWER 1 +#define ERROR 2 +#define STAT 3 +#define OK 4 + - void led_configure(); - void led_on(uint8_t led); - void led_off(uint8_t led); - void led_toggle(uint8_t led); - void led_output(uint8_t led); +void led_configure(); +void led_on(uint8_t led); +void led_off(uint8_t led); +void led_toggle(uint8_t led); +void led_output(uint8_t led); #endif /* LED_H_ */ diff --git a/slave/slave/lib/loopTimer.c b/slave/slave/lib/loopTimer.c --- a/slave/slave/lib/loopTimer.c +++ b/slave/slave/lib/loopTimer.c @@ -12,13 +12,11 @@ #include #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; + + millis = millis + 1; + } uint32_t time_millis() diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -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: diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -28,7 +28,7 @@ #include "lib/geiger.h" #include "lib/sensors.h" #include "lib/cameras.h" - +#include "lib/loopTimer.h" void micro_setup() { @@ -42,71 +42,70 @@ 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 - - - - //PORTA &= ~(1 << PA1); //DEBUG////////////////OFF/////////////////////////////////////////////////////////////// - //PORTA |= (1 << PA1); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// + //uint8_t test; //Debug + //uint8_t test2; //Debug - // 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) - { - 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) + { + 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) + + io_regulateTemp(); // Gets board temperature and enables heater if below threshold + + 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 + } + - - // This is just a serial output example - //sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4); + } + + return 0; +} - //i2c_write(RTC_ADDR, 0x05, 0x3A); //DEBUG: EXAMPLE////////////////////////////////////////////////////// - - _delay_ms(10); //DEBUG///////////// - - - test = geiger_getCount(); //Debug////////// - - led_output(test);//DEBUG////////// + + + + /********Examples of data reading and getting****************** + x = geiger_getCpm(); //Data get + x = sensors_getSpiTemp(); //Data get + x = sensors_getBoardTemp(); //Data get + sensors_readSpiTemp(); //Data Read + sensors_readBoardTemp(); //Data Read - /********Examples of data reading and getting****************** - x = geiger_getCpm(); //Data get - x = sensors_getSpiTemp(); //Data get - x = sensors_getBoardTemp(); //Data get + led_output(0xFF); //Output value to LED array + i2c_write(RTC_ADDR, 0x05, 0x3A); //i2c Write Example - sensors_readSpiTemp(); //Data Read - sensors_readBoardTemp(); //Data Read + 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 + + \ No newline at end of file