From 9518263d0a46979b01af4b5359d8f7f20469ae77 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Thu, 28 Aug 2014 22:15:07 -0700 Subject: [PATCH 01/23] Setting Up Input Capture hah! setting up input capture on PIC, going to test it with signal generator. --- EccoPro_Run1.c | 328 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 EccoPro_Run1.c diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c new file mode 100644 index 0000000..b9d4c25 --- /dev/null +++ b/EccoPro_Run1.c @@ -0,0 +1,328 @@ +/************************ + +This is a module to program the PIC16LF1827 get data from +the ECCO Pro sensor and output a moisture reading. + +First going to get input caputure working with inputs +from a signal generator. + +author: Osagie Igbeare + +adapted from code by Jim Lindblom, who adapted code from Nathan Seidle and +"mish-mashed" with code from the ColorLCDSheild + +8/7/2014 + +*************************/ + +/******************* Pin Configuration ************* + + Nokia 5110 LCD ----- < > ----- PIC16LF1827 + 1-Vcc --------------- 3.3V + 2-GND --------------- GND + 3-SCE --------------- RB5 + 4-RST --------------- RA0 + 5-D/C --------------- RB3 + 6-DN(MOSI) --------------- RB2 + 7-SCLK --------------- RB4 + 8-LED - 330 ohm res - 3.3V + + ***************************************************/ + +/**************** Header Files *********************/ + +#include "BitDefs.h" +//#include // for HI Tech C compiler +#include +#include "pic.h" +#include "chip_select.h" + + + +/***************** Configuration Macros ***************/ + +//__CONFIG(FCMEN_OFF & IESO_OFF & FOSC_LP & WDTE_OFF & MCLRE_ON & PWRTE_OFF & BOREN_OFF +// & LVP_ON & WRT_OFF & CPD_OFF & CP_OFF); + +// #pragma config statements should precede project file includes. +// Use project enums instead of #define for ON and OFF. + +// CONFIG1 +#pragma config FOSC = LP // Oscillator Selection (LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins) +#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) +#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) +#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) +#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) +#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) +#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) +#pragma config CLKOUTEN = ON // Clock Out Enable (CLKOUT function is enabled on the CLKOUT pin) +#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled) +#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) + +// CONFIG2 +#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) +#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled) +#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) +#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) +#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled) + + +/***************** # Defines *****************/ +#define lcd_data BIT3HI +#define lcd_command BIT3LO +#define hangTime 1000 + +#define LCD_Width 84 //x coordinates go wide +#define LCD_Height 31 //y coordinates go high +#define WHITE 0 // for drawing individual pixels, 0 draws white +#define BLACK 1 // see above, 1 draws black + +/*************** module level variables ************/ + +static char counter; +int x; +int i = 0; +static char LCD_Init[6]; + +static unsigned int uPeriod; + + +/********* Function Prototypes ***************/ + +void InitPorts(void); +void InitTimers(void); +void InitInterrupts(void); +void InitComm(void); +void NokiaInit(void); +void Delay(int waitTime); +void SightPin_B0(void); +void sendByte(char type, char byte); + + +/******* Acutal Functions ****************/ + +void InitPorts() +{ + + ANSELA = 0x00; // Port A pins are digital + ANSELB = 0x00; // Port B pins are digital + + TRISA = 0b00000000; // 1 - input, 0 - output, RA2, RA0 are outputs + TRISB = 0b00000011; // 1 - input, 0 - output, RB0 is an input, it's the input capture pin + + PORTA = 0b11111110; //RA0 - low + PORTB = 0b11111111; + + APFCON0 = 0x00; + //OSCCON = 0x00; + +} + +void InitTimers() +{ + T1CON = 0b00110011; /******************************************** + bits <7:6>(TMR1CS) = 00; TMR1 clk source is instruction clk + bits <5:4>(T1CKPS) = 11; divide by 8 prescale + bit 3 (T1OSCEN)= 0; TMR1 oscillator disabled + bit 2 (T1SYNC) = 0; synchronize external clk with + sys clock + bit 1 = unimplemented + bit 0 (TMR1ON)= 1; TMR1 on + *******************************************/ + + T1GCON = 0b10000100; /******************************************** + bit 7(TMR1GE) = 1; TMR1 contolled by gate function + bit 6(T1GPOL) = 0; TMR1 gate active low + bit 5(T1GTM) = 0; gate toggle is disabled + bit 4(T1GRPM) = 0; single pulse mode disabled + bit 3(T1GGO) = 0; clear when bit 4 is clear + bit 2(T1GVAL) = read only + bit <1:0>(T1GSS) = 00; + + *******************************************/ + + CCP1CON = 0b1110100; //capture mode: every falling edge + + + T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz + PR2 = 1; +} + +void InitInterrupts() +{ + + PIE1 = 0b00000110; // Enable TMR2IE, interrupt when Timer 2 matches PR2 + // Enable CCP1 interrupt + + INTCON = 0b11000000; // Enable GIE, Enable PEIE + +} + + +void InitComm() +{ + // setup SPI-1 (aka SSP) to communicate with Nokia LCD screen + + SSP1ADD = 2; // Baud Rate = Fosc / ((SSP1ADD + 1)(4)) + // since Fosc = 4 MHz, Baud Rate = 1 MHz + // since SSP1ADD = 0 is not supported same timing is achieved + // by setting bits <3:0> of SSPM all to 0's (see below) + + SSP1STATbits.SMP = 0; // data on rising edge, data @ middle + SSP1CON1bits.WCOL = 0; // no collision + SSP1CON1bits.SSPOV = 0; // no overflow + SSP1CON1bits.SSPEN = 1; // SSP Enable + + SSP1CON1bits.CKP = 1; // idle high + SSP1STATbits.CKE = 0; // sample ? edges + + SSP1CON1bits.SSPM3 = 0; // Set LF1827 as Master, clock rate Fosc / 4 + SSP1CON1bits.SSPM2 = 0; + SSP1CON1bits.SSPM1 = 0; + SSP1CON1bits.SSPM0 = 0; + + +} + + +void interrupt ISR() +{ + counter++; + if (TMR2IF) + { + if ((counter % 2) != 0) + { + PORTA |= BIT2HI; + + } + else + { + PORTA &= BIT2LO; + counter = 0; + } + + TMR2IF = 0; // clears the TIMR2IF (timer 2 interrupt flag) + + } + + if (CCP1IF) + { + static unsigned int uLastEdge; + char highByte; + char lowByte; + int CCPR1_Snapshot; + + highByte = CCPR1H; + lowByte = CCPR1L; + CCPR1_Snapshot = (highByte<<8) | lowByte; + + uPeriod = CCPR1_Snapshot - uLastEdge; + uLastEdge = CCPR1_Snapshot; + + CCP1IF = 0; + + + } + +} + +void NokiaInit() +{ + + //i = 0; + // LCD_Init array populated with initialization sequence + + LCD_Init[0] = 0x21; // tell LCD extended commands to + LCD_Init[1] = 0xE0; // set LCD Vop (contrast) ** parameter to mess with if screen doesn't display **** + LCD_Init[2] = 0x04; // set temp coefficient + LCD_Init[3] = 0x13; // LCD Bias mode 1:48 (if not working, try 0x13) + LCD_Init[4] = 0x20; // back to regular commands + LCD_Init[5] = 0x0C; // enable normal display (dark on light), horiz addressing + + + // initialization sequence for the PCD8544 driver on the Nokia LCD + // starting off with RESET + + PORTA &= BIT0LO; + Delay(hangTime); + PORTA |= BIT0HI; + + // the rest of the initialization sequence + + //PORTB &= lcd_command; // tell LCD commands are coming + + PORTB &= BIT5LO; // lower SCE line to begin transmission + + for (i=0; i<6; i++) // sending 6 commands to the LCD screen + { + sendByte(lcd_command, LCD_Init[i]); + } + + PORTB |= BIT5HI; // raising SCE line at the end of transmission0 +} + +void Delay(int waitTime) +{ + x = 0; + while(x < waitTime) + { + x += 1; + } +} + +void sendByte (char type, char byte) +{ + PORTB &= type; // tell the LCD commands are coming + + PIR1bits.SSP1IF = 0; + + SSP1BUF = byte; + + while (!SSP1STATbits.BF); + + +} + +/***********************************************************/ +/******************** Debugging Library ********************/ + +void SightPin_B0(void) +{ + // toggles pin B0 for debugging purposes + if ((PORTB & BIT0HI) == BIT0HI) + { + PORTB &= BIT0LO; + + } + else + { + PORTB |= BIT0HI; + } + +} + + +/********************************************************/ +/******** Main - which actually runs the code ***********/ +/********************************************************/ + +void main () +{ + + // Initializing PIC16LF1827 + InitPorts(); + InitTimers(); + InitInterrupts(); + InitComm(); + //NokiaInit(); + while(1) + { + + NokiaInit(); + } + + + +} + + From f3db229ffc451c02d118bb30d613fbc29eeaac78 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Thu, 28 Aug 2014 23:29:40 -0700 Subject: [PATCH 02/23] Added moisture calc function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit didn’t put it main though, just wanted to keep a step ahead --- EccoPro_Run1.c | 60 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c index b9d4c25..bda5453 100644 --- a/EccoPro_Run1.c +++ b/EccoPro_Run1.c @@ -8,9 +8,6 @@ from a signal generator. author: Osagie Igbeare -adapted from code by Jim Lindblom, who adapted code from Nathan Seidle and -"mish-mashed" with code from the ColorLCDSheild - 8/7/2014 *************************/ @@ -32,7 +29,6 @@ adapted from code by Jim Lindblom, who adapted code from Nathan Seidle and /**************** Header Files *********************/ #include "BitDefs.h" -//#include // for HI Tech C compiler #include #include "pic.h" #include "chip_select.h" @@ -72,10 +68,6 @@ adapted from code by Jim Lindblom, who adapted code from Nathan Seidle and #define lcd_command BIT3LO #define hangTime 1000 -#define LCD_Width 84 //x coordinates go wide -#define LCD_Height 31 //y coordinates go high -#define WHITE 0 // for drawing individual pixels, 0 draws white -#define BLACK 1 // see above, 1 draws black /*************** module level variables ************/ @@ -86,6 +78,11 @@ static char LCD_Init[6]; static unsigned int uPeriod; +int waterCal = 19667; +int twentyPer = 19235; +int airCal = 18587; +int moisture; + /********* Function Prototypes ***************/ @@ -97,6 +94,7 @@ void NokiaInit(void); void Delay(int waitTime); void SightPin_B0(void); void sendByte(char type, char byte); +void MoistureCalc(void); /******* Acutal Functions ****************/ @@ -137,11 +135,10 @@ void InitTimers() bit 4(T1GRPM) = 0; single pulse mode disabled bit 3(T1GGO) = 0; clear when bit 4 is clear bit 2(T1GVAL) = read only - bit <1:0>(T1GSS) = 00; - + bit <1:0>(T1GSS) = 00; TMR1 gate pin *******************************************/ - CCP1CON = 0b1110100; //capture mode: every falling edge + CCP1CON = 0b0110100; //capture mode: every falling edge T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz @@ -154,7 +151,7 @@ void InitInterrupts() PIE1 = 0b00000110; // Enable TMR2IE, interrupt when Timer 2 matches PR2 // Enable CCP1 interrupt - INTCON = 0b11000000; // Enable GIE, Enable PEIE + INTCON = 0b11000000; // Enable GIE, Enable PEIE } @@ -281,6 +278,45 @@ void sendByte (char type, char byte) while (!SSP1STATbits.BF); +} + +void MoistureCalc(void) +{ + int x; + + if (uPeriod < airCal) + { + x = airCal; + + moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); + + } + + if (uPeriod <= twentyPer) + { + x = ((uPeriod - airCal)*100)/(twentyPer - airCal); + + moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); + } + + + if (uPeriod > twentyPer) + { + x = ((uPeriod - twentyPer)*50)/((waterCal-twentyPer)+100); + + moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + + } + + if (uPeriod > waterCal) + { + x = waterCal; + + moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + + } + + } /***********************************************************/ From 0e80d0fe90d276e65509b144a2232e40b38c4dca Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Fri, 29 Aug 2014 14:32:06 -0700 Subject: [PATCH 03/23] Working Input Capture! incapt pin - B3 and if TMR1 clk source is instruct clk, then T1OSCEN has to be enabled if TMR1 clk source is Fosc, then T1OSCEN can be disabled --- EccoPro_Run1.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c index bda5453..4903c0e 100644 --- a/EccoPro_Run1.c +++ b/EccoPro_Run1.c @@ -92,7 +92,8 @@ void InitInterrupts(void); void InitComm(void); void NokiaInit(void); void Delay(int waitTime); -void SightPin_B0(void); +void SightPin_A2(void); +void SightPin_A3(void); void sendByte(char type, char byte); void MoistureCalc(void); @@ -105,23 +106,23 @@ void InitPorts() ANSELA = 0x00; // Port A pins are digital ANSELB = 0x00; // Port B pins are digital - TRISA = 0b00000000; // 1 - input, 0 - output, RA2, RA0 are outputs + TRISA = 0b00000000; // 1 - input, 0 - output, all A pins are outputs TRISB = 0b00000011; // 1 - input, 0 - output, RB0 is an input, it's the input capture pin - PORTA = 0b11111110; //RA0 - low - PORTB = 0b11111111; + PORTA = 0b11110110; //RA0 - low + //PORTB = 0b11111111; APFCON0 = 0x00; - //OSCCON = 0x00; + //OSCCON = 0b10000010; } void InitTimers() { - T1CON = 0b00110011; /******************************************** + T1CON = 0b01000011; /******************************************** bits <7:6>(TMR1CS) = 00; TMR1 clk source is instruction clk - bits <5:4>(T1CKPS) = 11; divide by 8 prescale - bit 3 (T1OSCEN)= 0; TMR1 oscillator disabled + bits <5:4>(T1CKPS) = 00; divide by 1 prescale + bit 3 (T1OSCEN)= 1; TMR1 oscillator disabled bit 2 (T1SYNC) = 0; synchronize external clk with sys clock bit 1 = unimplemented @@ -138,7 +139,7 @@ void InitTimers() bit <1:0>(T1GSS) = 00; TMR1 gate pin *******************************************/ - CCP1CON = 0b0110100; //capture mode: every falling edge + CCP1CON = 0b00110100; //capture mode: every falling edge T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz @@ -150,6 +151,7 @@ void InitInterrupts() PIE1 = 0b00000110; // Enable TMR2IE, interrupt when Timer 2 matches PR2 // Enable CCP1 interrupt + CCP1IF = 0; INTCON = 0b11000000; // Enable GIE, Enable PEIE @@ -209,6 +211,8 @@ void interrupt ISR() char lowByte; int CCPR1_Snapshot; + SightPin_A3(); + highByte = CCPR1H; lowByte = CCPR1L; CCPR1_Snapshot = (highByte<<8) | lowByte; @@ -322,17 +326,32 @@ void MoistureCalc(void) /***********************************************************/ /******************** Debugging Library ********************/ -void SightPin_B0(void) +void SightPin_A4(void) +{ + // toggles pin A2 for debugging purposes + if ((PORTA & BIT4HI) == BIT4HI) + { + PORTA &= BIT4LO; + + } + else + { + PORTA |= BIT4HI; + } + +} + +void SightPin_A3(void) { - // toggles pin B0 for debugging purposes - if ((PORTB & BIT0HI) == BIT0HI) + // toggles pin A3 for debugging purposes + if ((PORTA & BIT3HI) == BIT3HI) { - PORTB &= BIT0LO; + PORTA &= BIT3LO; } else { - PORTB |= BIT0HI; + PORTA |= BIT3HI; } } @@ -354,7 +373,7 @@ void main () while(1) { - NokiaInit(); + //NokiaInit(); } From 1ddfbcc96f9c1dd9f0f337b7a8d6fd06653015d5 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Fri, 29 Aug 2014 22:29:11 -0700 Subject: [PATCH 04/23] Checking uPeriod value turns out global variable must be used in some type of logic statement for it to be available in Watches in MPLAB X --- EccoPro_Run1.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c index 4903c0e..1a3fe5a 100644 --- a/EccoPro_Run1.c +++ b/EccoPro_Run1.c @@ -44,7 +44,7 @@ author: Osagie Igbeare // Use project enums instead of #define for ON and OFF. // CONFIG1 -#pragma config FOSC = LP // Oscillator Selection (LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins) +#pragma config FOSC = XT // Oscillator Selection (LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) @@ -81,7 +81,8 @@ static unsigned int uPeriod; int waterCal = 19667; int twentyPer = 19235; int airCal = 18587; -int moisture; +int moisture; + /********* Function Prototypes ***************/ @@ -119,10 +120,10 @@ void InitPorts() void InitTimers() { - T1CON = 0b01000011; /******************************************** - bits <7:6>(TMR1CS) = 00; TMR1 clk source is instruction clk + T1CON = 0b01110011; /******************************************** + bits <7:6>(TMR1CS) = 01; TMR1 clk source is Fosc bits <5:4>(T1CKPS) = 00; divide by 1 prescale - bit 3 (T1OSCEN)= 1; TMR1 oscillator disabled + bit 3 (T1OSCEN)= 0; TMR1 oscillator disabled bit 2 (T1SYNC) = 0; synchronize external clk with sys clock bit 1 = unimplemented @@ -143,7 +144,7 @@ void InitTimers() T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz - PR2 = 1; + PR2 = 250; } void InitInterrupts() @@ -220,6 +221,15 @@ void interrupt ISR() uPeriod = CCPR1_Snapshot - uLastEdge; uLastEdge = CCPR1_Snapshot; + //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? + + if (uPeriod == 0) + { + + uPeriod = 23; + } + //twentyPer = uPeriod; + CCP1IF = 0; @@ -320,6 +330,11 @@ void MoistureCalc(void) } + if (uPeriod == 0) + { + uPeriod = 0; + } + } From 7aec6d49eb1f8126fd5270a278e105b1e5f8bc37 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Wed, 3 Sep 2014 17:27:19 -0700 Subject: [PATCH 05/23] Sleep Working! Josh got Sleep functionality to work. PIC can go to and come out of Sleep mode now. --- EccoPro_Run1.c | 155 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 110 insertions(+), 45 deletions(-) diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c index 1a3fe5a..37f9e2c 100644 --- a/EccoPro_Run1.c +++ b/EccoPro_Run1.c @@ -7,9 +7,11 @@ First going to get input caputure working with inputs from a signal generator. author: Osagie Igbeare - 8/7/2014 +Modified by: joshuafrancis80@gmail.com +Date: 9/1/2014 + *************************/ /******************* Pin Configuration ************* @@ -44,8 +46,8 @@ author: Osagie Igbeare // Use project enums instead of #define for ON and OFF. // CONFIG1 -#pragma config FOSC = XT // Oscillator Selection (LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins) -#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) +#pragma config FOSC = XT // Oscillator Selection (XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins) +#pragma config WDTE = ON // Watchdog Timer Enable (WDT controlled by the SWDTEN bit in the WDTCON register) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) @@ -74,7 +76,7 @@ author: Osagie Igbeare static char counter; int x; int i = 0; -static char LCD_Init[6]; +//static char LCD_Init[6]; static unsigned int uPeriod; @@ -90,12 +92,13 @@ int moisture; void InitPorts(void); void InitTimers(void); void InitInterrupts(void); -void InitComm(void); -void NokiaInit(void); -void Delay(int waitTime); +void WatchDogTimer(void); +//void InitComm(void); +//void NokiaInit(void); +//void Delay(int waitTime); void SightPin_A2(void); void SightPin_A3(void); -void sendByte(char type, char byte); +//void sendByte(char type, char byte); void MoistureCalc(void); @@ -110,10 +113,10 @@ void InitPorts() TRISA = 0b00000000; // 1 - input, 0 - output, all A pins are outputs TRISB = 0b00000011; // 1 - input, 0 - output, RB0 is an input, it's the input capture pin - PORTA = 0b11110110; //RA0 - low - //PORTB = 0b11111111; + PORTA = 0b11100110; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) + PORTB = 0b00000000; - APFCON0 = 0x00; + APFCON0 = 0x00; // Alternative pin function control register //OSCCON = 0b10000010; } @@ -122,43 +125,99 @@ void InitTimers() { T1CON = 0b01110011; /******************************************** bits <7:6>(TMR1CS) = 01; TMR1 clk source is Fosc - bits <5:4>(T1CKPS) = 00; divide by 1 prescale + bits <5:4>(T1CKPS) = 11; divide by 8 prescale bit 3 (T1OSCEN)= 0; TMR1 oscillator disabled bit 2 (T1SYNC) = 0; synchronize external clk with - sys clock + sys clock (Fosc) bit 1 = unimplemented bit 0 (TMR1ON)= 1; TMR1 on *******************************************/ T1GCON = 0b10000100; /******************************************** bit 7(TMR1GE) = 1; TMR1 contolled by gate function - bit 6(T1GPOL) = 0; TMR1 gate active low + bit 6(T1GPOL) = 0; TMR1 counts when gate is low bit 5(T1GTM) = 0; gate toggle is disabled bit 4(T1GRPM) = 0; single pulse mode disabled bit 3(T1GGO) = 0; clear when bit 4 is clear - bit 2(T1GVAL) = read only + bit 2(T1GVAL) = 1; current state of TMR1 gate bit <1:0>(T1GSS) = 00; TMR1 gate pin *******************************************/ CCP1CON = 0b00110100; //capture mode: every falling edge - + //CCP1CON = 0b00000100; //least 4 bits sets capture mode T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz - PR2 = 250; + /******************************************** + bit 7 unimplemented + bit <6:3>(TxOUTPS) = 1111; 1:16 postscaler + bit 2(TMR2ON) = 1; Timer2 is on + bit <1:0>(T1GSS) = 10; prescaler is 16 + *******************************************/ + + PR2 = 250; //Period Register; each clock cycle if TMR2 == PR2 then match signal to output and TMR2 = 00h } +void WatchDogTimer() { + + //00010101 about 1 second + WDTCON = 0b00010101; //00100101 prescale 1:2^23 which is about 4.3 minutes + /***************************** + bit 7-6 Unimplemented + bit 5-1 WDTPS<4:0>: Watchdog Timer Period Select bits + bit 0 SWDTEN: Software Enable/Disable for Watchdog Timer bit + *****************************/ + +} + +/* To enable interrupts the following bits of INTCON must be set: GIE and PEIE. And, the interrupt enable bits for + the specific interrupt events. The following happens when an interrupt event happens and GIE is set: current + prefetched instruction is flushed, GIE is cleared, PC pushed onto stack, critical registers saved to shadow + registers, PC is loaded with interrupt vector 0004h. + */ void InitInterrupts() { + //Peripheral Interrupt Enable Register + PIE1 = 0b00000110; + /******************************************** + bit 7(TMR1GIE) Timer1 Gate Interrupt Enable bit + bit 6(ADIE) A/D Converter (ADC) Interrupt Enable bit + bit 5(RCIE) USART Receive Interrupt Enable bit + bit 4(TXIE) USART Transmit Interrupt Enable bit + bit 3(SSP1IE) Synchronous Serial Port 1 (MSSP1) + bit 2(CCP1IE) CCP1 Interrupt Enable bit + bit 1(TMR2IE) TMR2 to PR2 Match Interrupt Enable bit + bit 0(TMR1IE) Timer1 Overflow Interrupt Enable bit + *******************************************/ - PIE1 = 0b00000110; // Enable TMR2IE, interrupt when Timer 2 matches PR2 - // Enable CCP1 interrupt - CCP1IF = 0; + CCP1IF = 0; // Interrupt request flag bit of the PIR1 register, this is set on capture + + INTCON = 0b11000000; + /******************************************** + bit 7(GIE) = 1; Global Interrupt Enable bit + bit 6(PEIE) = 1; Peripheral Interrupt Enable bit + bit 5(TMR0IE) = 0; Timer0 Overflow Interrupt Enable bit + bit 4(INTE) = 0; INT External Interrupt Enable bit + bit 3(IOCIE) = 0; Interrupt-on-Change Enable bit + bit 2(TMR0IF) = 0; Timer0 Overflow Interrupt FLag bit + bit 1(INTF) = 0; INT External Interrupt Flag bit + bit 0(IOCIF) = 0; Interrupt-on-Change Interrupt Flag bit + *******************************************/ - INTCON = 0b11000000; // Enable GIE, Enable PEIE - + //Peripheral Interrupt Request Register 1 + //PIR1 = 0b00000000; + /******************************************** + bit 7 TMR1GIF: Timer1 Gate Interrupt Flag bit + bit 6 ADIF: A/D Converter Interrupt Flag bit + bit 5 RCIF: USART Receive Interrupt Flag bit + bit 4 TXIF: USART Transmit Interrupt Flag bit + bit 3 SSP1IF: Synchronous Serial Port 1 (MSSP1) Interrupt Flag bit + bit 2 CCP1IF: CCP1 Interrupt Flag bit + bit 1 TMR2IF: Timer2 to PR2 Interrupt Flag bit + bit 0 TMR1IF: Timer1 Overflow Interrupt Flag bit + *******************************************/ } - +/* void InitComm() { // setup SPI-1 (aka SSP) to communicate with Nokia LCD screen @@ -180,24 +239,23 @@ void InitComm() SSP1CON1bits.SSPM2 = 0; SSP1CON1bits.SSPM1 = 0; SSP1CON1bits.SSPM0 = 0; - - } +*/ - +/* First need to poll the interrupt flag bits to determine source of interrupt.*/ void interrupt ISR() { counter++; - if (TMR2IF) + if (TMR2IF) // PIR1<1> { if ((counter % 2) != 0) { - PORTA |= BIT2HI; + PORTA |= BIT2HI; // 0b00000100 } else { - PORTA &= BIT2LO; + PORTA &= BIT2LO; // 0b11111011 counter = 0; } @@ -205,21 +263,21 @@ void interrupt ISR() } - if (CCP1IF) + if (CCP1IF) // PIR1<2> { static unsigned int uLastEdge; char highByte; char lowByte; int CCPR1_Snapshot; - SightPin_A3(); + SightPin_A3(); // debugging - highByte = CCPR1H; - lowByte = CCPR1L; - CCPR1_Snapshot = (highByte<<8) | lowByte; + highByte = CCPR1H; // CCPR1H captures value from TMR1H register + lowByte = CCPR1L; // CCPR1L captures value from TMR1L register + CCPR1_Snapshot = (highByte<<8) | lowByte; // combine into 16 bit int uPeriod = CCPR1_Snapshot - uLastEdge; - uLastEdge = CCPR1_Snapshot; + uLastEdge = CCPR1_Snapshot; // this variable should not be in scope next ISR //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? @@ -230,16 +288,16 @@ void interrupt ISR() } //twentyPer = uPeriod; - CCP1IF = 0; + CCP1IF = 0; // clear the flag } -} +} //pop previous address from the stack, restore registers, set GIE bit +/* void NokiaInit() { - //i = 0; // LCD_Init array populated with initialization sequence @@ -271,8 +329,9 @@ void NokiaInit() PORTB |= BIT5HI; // raising SCE line at the end of transmission0 } + */ -void Delay(int waitTime) + void Delay(int waitTime) { x = 0; while(x < waitTime) @@ -281,7 +340,8 @@ void Delay(int waitTime) } } -void sendByte (char type, char byte) + /* + void sendByte (char type, char byte) { PORTB &= type; // tell the LCD commands are coming @@ -290,9 +350,8 @@ void sendByte (char type, char byte) SSP1BUF = byte; while (!SSP1STATbits.BF); - - } +*/ void MoistureCalc(void) { @@ -383,12 +442,18 @@ void main () InitPorts(); InitTimers(); InitInterrupts(); - InitComm(); - //NokiaInit(); + while(1) { - //NokiaInit(); + PORTB &= BIT4LO; //makes LED on RB4 bright + for (x=0;x<3;x++) {SLEEP();} // will sleep x number of times + PORTB |= BIT4HI; //makes LED on RB4 dim + SLEEP(); + + + + } From 296b823493e686f251736aba467cd38806622b21 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Fri, 5 Sep 2014 18:39:38 -0700 Subject: [PATCH 06/23] Ecco Integration - powers ECCO Pro, gets uPeriod after second pulse in the set (shout out to Josh F. for seeing that bug), sleeps for 8 seconds. Still need to store data in array (velocity and acceleration arrays) and come up with algorithm to compare rates such that lights can turn on accordingly. --- EccoPro_Run1.c | 241 ++++++++++++++++++++++--------------------------- 1 file changed, 108 insertions(+), 133 deletions(-) diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c index 37f9e2c..1581ecf 100644 --- a/EccoPro_Run1.c +++ b/EccoPro_Run1.c @@ -14,19 +14,6 @@ Date: 9/1/2014 *************************/ -/******************* Pin Configuration ************* - - Nokia 5110 LCD ----- < > ----- PIC16LF1827 - 1-Vcc --------------- 3.3V - 2-GND --------------- GND - 3-SCE --------------- RB5 - 4-RST --------------- RA0 - 5-D/C --------------- RB3 - 6-DN(MOSI) --------------- RB2 - 7-SCLK --------------- RB4 - 8-LED - 330 ohm res - 3.3V - - ***************************************************/ /**************** Header Files *********************/ @@ -36,7 +23,6 @@ Date: 9/1/2014 #include "chip_select.h" - /***************** Configuration Macros ***************/ //__CONFIG(FCMEN_OFF & IESO_OFF & FOSC_LP & WDTE_OFF & MCLRE_ON & PWRTE_OFF & BOREN_OFF @@ -69,37 +55,40 @@ Date: 9/1/2014 #define lcd_data BIT3HI #define lcd_command BIT3LO #define hangTime 1000 - +#define total_values 24 //this is the total number of values that will be saved in the array /*************** module level variables ************/ static char counter; -int x; -int i = 0; -//static char LCD_Init[6]; +int x, y; +int i = 0; +int captureTracker = 0; + +//int total_values = 24; //set the total number of values to capture +int moistureValues[total_values]; //array for moisture values +int moistureChangeRate[total_values]; //array for change in moisture values static unsigned int uPeriod; +static unsigned int rawInterval; int waterCal = 19667; int twentyPer = 19235; int airCal = 18587; -int moisture; +int moisture = 0; +int previous_moisture = 0; +int saturation = 20; - /********* Function Prototypes ***************/ void InitPorts(void); void InitTimers(void); void InitInterrupts(void); void WatchDogTimer(void); -//void InitComm(void); -//void NokiaInit(void); -//void Delay(int waitTime); void SightPin_A2(void); void SightPin_A3(void); -//void sendByte(char type, char byte); void MoistureCalc(void); +void SetLEDsForWatering(void); /******* Acutal Functions ****************/ @@ -111,7 +100,7 @@ void InitPorts() ANSELB = 0x00; // Port B pins are digital TRISA = 0b00000000; // 1 - input, 0 - output, all A pins are outputs - TRISB = 0b00000011; // 1 - input, 0 - output, RB0 is an input, it's the input capture pin + TRISB = 0b00001011; // 1 - input, 0 - output, RB0 is an input, it's the input capture pin PORTA = 0b11100110; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) PORTB = 0b00000000; @@ -217,33 +206,12 @@ void InitInterrupts() *******************************************/ } -/* -void InitComm() -{ - // setup SPI-1 (aka SSP) to communicate with Nokia LCD screen - - SSP1ADD = 2; // Baud Rate = Fosc / ((SSP1ADD + 1)(4)) - // since Fosc = 4 MHz, Baud Rate = 1 MHz - // since SSP1ADD = 0 is not supported same timing is achieved - // by setting bits <3:0> of SSPM all to 0's (see below) - - SSP1STATbits.SMP = 0; // data on rising edge, data @ middle - SSP1CON1bits.WCOL = 0; // no collision - SSP1CON1bits.SSPOV = 0; // no overflow - SSP1CON1bits.SSPEN = 1; // SSP Enable - - SSP1CON1bits.CKP = 1; // idle high - SSP1STATbits.CKE = 0; // sample ? edges - - SSP1CON1bits.SSPM3 = 0; // Set LF1827 as Master, clock rate Fosc / 4 - SSP1CON1bits.SSPM2 = 0; - SSP1CON1bits.SSPM1 = 0; - SSP1CON1bits.SSPM0 = 0; -} -*/ - -/* First need to poll the interrupt flag bits to determine source of interrupt.*/ -void interrupt ISR() +/* First need to poll the interrupt flag bits to determine source of interrupt. + * The two pulses we are looking for are separated by 100 to 200 miliseconds (ms), + * so we need the ISR to finish its work in probably less than 100 ms. The program + * will then return to the main function to wait out the rest of the delay and the + * ISR should be called again before it goes into sleep mode. */ +void interrupt ISR() // function needs to execute in <100ms { counter++; if (TMR2IF) // PIR1<1> @@ -263,23 +231,42 @@ void interrupt ISR() } - if (CCP1IF) // PIR1<2> + if (CCP1IF) // flag is in register PIR1<2> { - static unsigned int uLastEdge; + + + static unsigned int uLastEdge; char highByte; char lowByte; int CCPR1_Snapshot; - SightPin_A3(); // debugging + captureTracker ++; //keeps track of how many captures have been done + + //SightPin_A3(); // debugging highByte = CCPR1H; // CCPR1H captures value from TMR1H register lowByte = CCPR1L; // CCPR1L captures value from TMR1L register + + //this is the time when the pulse from the sensor arrived CCPR1_Snapshot = (highByte<<8) | lowByte; // combine into 16 bit int uPeriod = CCPR1_Snapshot - uLastEdge; uLastEdge = CCPR1_Snapshot; // this variable should not be in scope next ISR - //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? + + /* + if ((captureTracker % 2) != 0) + { + uPeriod = uPeriod; + + } + else + { + rawInterval = uPeriod; + //captureTracker = 0; + } + */ + if (uPeriod == 0) { @@ -288,115 +275,75 @@ void interrupt ISR() } //twentyPer = uPeriod; - CCP1IF = 0; // clear the flag - + //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? + TMR1H = 0; + TMR1L = 0; + CCP1IF = 0; // clear the flag } } //pop previous address from the stack, restore registers, set GIE bit -/* -void NokiaInit() -{ - //i = 0; - // LCD_Init array populated with initialization sequence - - LCD_Init[0] = 0x21; // tell LCD extended commands to - LCD_Init[1] = 0xE0; // set LCD Vop (contrast) ** parameter to mess with if screen doesn't display **** - LCD_Init[2] = 0x04; // set temp coefficient - LCD_Init[3] = 0x13; // LCD Bias mode 1:48 (if not working, try 0x13) - LCD_Init[4] = 0x20; // back to regular commands - LCD_Init[5] = 0x0C; // enable normal display (dark on light), horiz addressing - - - // initialization sequence for the PCD8544 driver on the Nokia LCD - // starting off with RESET - - PORTA &= BIT0LO; - Delay(hangTime); - PORTA |= BIT0HI; - - // the rest of the initialization sequence - - //PORTB &= lcd_command; // tell LCD commands are coming - - PORTB &= BIT5LO; // lower SCE line to begin transmission - - for (i=0; i<6; i++) // sending 6 commands to the LCD screen - { - sendByte(lcd_command, LCD_Init[i]); - } - - PORTB |= BIT5HI; // raising SCE line at the end of transmission0 -} - */ - - void Delay(int waitTime) -{ - x = 0; - while(x < waitTime) - { - x += 1; - } -} - - /* - void sendByte (char type, char byte) -{ - PORTB &= type; // tell the LCD commands are coming - - PIR1bits.SSP1IF = 0; - - SSP1BUF = byte; - - while (!SSP1STATbits.BF); -} -*/ void MoistureCalc(void) { + //this gives the next index for the arrays + //int next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" + + moisture = 25; //arbitrarily set value + + /* int x; - if (uPeriod < airCal) + if (rawInterval < airCal) { x = airCal; - moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); + moisture = ((rawInterval - airCal)*x )/((twentyPer - airCal)*100); } - if (uPeriod <= twentyPer) + if (rawInterval <= twentyPer) { - x = ((uPeriod - airCal)*100)/(twentyPer - airCal); + x = ((rawInterval - airCal)*100)/(twentyPer - airCal); - moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); + moisture = ((rawInterval - airCal)*x )/((twentyPer - airCal)*100); } - if (uPeriod > twentyPer) + if (rawInterval > twentyPer) { - x = ((uPeriod - twentyPer)*50)/((waterCal-twentyPer)+100); + x = ((rawInterval - twentyPer)*50)/((waterCal-twentyPer)+100); - moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + moisture = ((rawInterval - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); } - if (uPeriod > waterCal) + if (rawInterval > waterCal) { x = waterCal; - moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + moisture = ((rawInterval - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); } + */ - if (uPeriod == 0) - { - uPeriod = 0; - } + //add the value of capTrack - 2 to the base pointer of the array and dereference + //moistureValues[next_index] = moisture; + //moistureChangeRate[next_index] = moisture - previous_moisture; + + previous_moisture = moisture; +} +void SetLEDsForWatering(void) +{ + if (moisture > saturation) {PORTB &= BIT5LO;} //RB5 port LED bright + else {PORTB |= BIT5HI;} //RB5 port LED dim + } + /***********************************************************/ /******************** Debugging Library ********************/ @@ -446,13 +393,41 @@ void main () while(1) { - PORTB &= BIT4LO; //makes LED on RB4 bright - for (x=0;x<3;x++) {SLEEP();} // will sleep x number of times - PORTB |= BIT4HI; //makes LED on RB4 dim - SLEEP(); + //turn sensor on + //PORTB &= BIT4LO; + PORTB |= BIT4HI; + + //PC stuck in loop until first capture (capTrack is an even number) + while (captureTracker % 2 == 0){PORTA |= BIT3HI;}//RA3 dim // even and 0 % 2 = 0 + + //PC stuck in another loop until second capture (capTrack is an odd number) + while (captureTracker % 2 == 1){PORTA &= BIT3LO;}//RA4 dim //odd % 2 = 1 + + //turn off sensor + //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle + PORTB &= BIT4LO; + //do calculation + MoistureCalc(); + //turn on LEDs if need to water + SetLEDsForWatering(); + //Put device to sleep and wait for the next time to take a measurment + //the sleep time is set by the postscaler of the WDT + for (y=0;y<4;y++) {SLEEP();} // will sleep x number of times + + //start the count over when the array's are full + //capture tracker will be an even number at this point + //if (captureTracker == (2*total_values)) {captureTracker = 0;} + + + /* this code works to strobe an LED + PORTB &= BIT4LO; //makes LED on RB4 bright -- currenly 2.2V (Sensor Power) + for (y=0;y<2;y++) {SLEEP();} // will sleep x number of times + PORTB |= BIT4HI; //makes LED on RB4 dim + for (y=0;y<2;y++) {SLEEP();} // sleep x number of times + */ } From 440af0e040214d9a3bf3db2dac88ae9c58630c33 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Tue, 9 Sep 2014 15:13:10 -0700 Subject: [PATCH 07/23] Ready to Store Data Last version this is ready to store data from the sensor, has the algorithm for looking at the 2nd order derivative, last version before migration to 1825. --- EccoPro_Run1.c | 71 ++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/EccoPro_Run1.c b/EccoPro_Run1.c index 1581ecf..a6710f7 100644 --- a/EccoPro_Run1.c +++ b/EccoPro_Run1.c @@ -55,7 +55,7 @@ Date: 9/1/2014 #define lcd_data BIT3HI #define lcd_command BIT3LO #define hangTime 1000 -#define total_values 24 //this is the total number of values that will be saved in the array +#define total_values 100 //this is the total number of values that will be saved in the array /*************** module level variables ************/ @@ -71,12 +71,12 @@ int moistureChangeRate[total_values]; //array for change in moisture values static unsigned int uPeriod; static unsigned int rawInterval; -int waterCal = 19667; -int twentyPer = 19235; -int airCal = 18587; -int moisture = 0; -int previous_moisture = 0; -int saturation = 20; +int waterCal = 19667; //where does this number come from? +int twentyPer = 19235; //where does this number come from? +int airCal = 18587; //where does this number come from? +int moisture = 0; //initialized to zero, maybe this should be unsigned +int previous_moisture = 0; //initialized to zero +int target_value = 20; //I set this arbitrarily to test the code /********* Function Prototypes ***************/ @@ -268,77 +268,80 @@ void interrupt ISR() // function needs to execute in <100ms */ - if (uPeriod == 0) - { - - uPeriod = 23; - } + if (uPeriod == 0) { uPeriod = 23; } //twentyPer = uPeriod; //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? + //the datasheet says to stop the timer before writing to below registers TMR1H = 0; TMR1L = 0; CCP1IF = 0; // clear the flag } -} //pop previous address from the stack, restore registers, set GIE bit +} //pops previous address from the stack, restores registers, and sets GIE bit void MoistureCalc(void) { - //this gives the next index for the arrays - //int next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" + + /* The following moisture calculation section is commented out until we + * can understand how this calculation yields the percentage of water in + * the soil. - moisture = 25; //arbitrarily set value - - /* int x; - if (rawInterval < airCal) + if (uPeriod < airCal) { x = airCal; - moisture = ((rawInterval - airCal)*x )/((twentyPer - airCal)*100); + moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); } - if (rawInterval <= twentyPer) + if (uPeriod <= twentyPer) { - x = ((rawInterval - airCal)*100)/(twentyPer - airCal); + x = ((uPeriod - airCal)*100)/(twentyPer - airCal); - moisture = ((rawInterval - airCal)*x )/((twentyPer - airCal)*100); + moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); } - if (rawInterval > twentyPer) + if (uPeriod > twentyPer) { - x = ((rawInterval - twentyPer)*50)/((waterCal-twentyPer)+100); + x = ((uPeriod - twentyPer)*50)/((waterCal-twentyPer)+100); - moisture = ((rawInterval - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); } - if (rawInterval > waterCal) + if (uPeriod > waterCal) { x = waterCal; - moisture = ((rawInterval - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); } */ - //add the value of capTrack - 2 to the base pointer of the array and dereference - //moistureValues[next_index] = moisture; - //moistureChangeRate[next_index] = moisture - previous_moisture; + //set the value of the moisture, should be a number from 0 to 100 + moisture = 25; //this will be a formula based on the characterization curve + + //this gives the next index for the arrays + int next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide + + //add the next moisture value and rate change to the arrays + moistureValues[next_index] = moisture; + moistureChangeRate[next_index] = moisture - previous_moisture; + //save the current moisture reading to calculate the rate change previous_moisture = moisture; } -void SetLEDsForWatering(void) +void SetLEDsForWatering(void) // must account for rate of watering. { - if (moisture > saturation) {PORTB &= BIT5LO;} //RB5 port LED bright + if (moisture < target_value) {PORTB &= BIT5LO;} //RB5 port LED bright else {PORTB |= BIT5HI;} //RB5 port LED dim } @@ -422,7 +425,7 @@ void main () //if (captureTracker == (2*total_values)) {captureTracker = 0;} - /* this code works to strobe an LED + /* this code works to strobe an LED connected to RB4 PORTB &= BIT4LO; //makes LED on RB4 bright -- currenly 2.2V (Sensor Power) for (y=0;y<2;y++) {SLEEP();} // will sleep x number of times PORTB |= BIT4HI; //makes LED on RB4 dim From 23a75010f28049269e300320b0336920438d6d43 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Tue, 9 Sep 2014 18:15:35 -0700 Subject: [PATCH 08/23] LF1825 Migration migrated code from PIC16L1827 to blah-blah-1825. 1825 has 1 KB of memory but also has less pins :-p --- 1825_EccoPro_Run1.c | 432 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 432 insertions(+) create mode 100644 1825_EccoPro_Run1.c diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c new file mode 100644 index 0000000..878b57a --- /dev/null +++ b/1825_EccoPro_Run1.c @@ -0,0 +1,432 @@ +/************************ + +This is a module to program the PIC16LF1827 get data from +the ECCO Pro sensor and output a moisture reading. + +First going to get input caputure working with inputs +from a signal generator. + +author: Osagie Igbeare +8/7/2014 + +Modified by: joshuafrancis80@gmail.com +Date: 9/1/2014 + +*************************/ + + +/**************** Header Files *********************/ + +#include "BitDefs.h" +#include +#include "pic.h" +#include "chip_select.h" + + +/***************** Configuration Macros ***************/ + +//__CONFIG(FCMEN_OFF & IESO_OFF & FOSC_LP & WDTE_OFF & MCLRE_ON & PWRTE_OFF & BOREN_OFF +// & LVP_ON & WRT_OFF & CPD_OFF & CP_OFF); + +// #pragma config statements should precede project file includes. +// Use project enums instead of #define for ON and OFF. + +// CONFIG1 +#pragma config FOSC = XT // Oscillator Selection (XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins) +#pragma config WDTE = ON // Watchdog Timer Enable (WDT controlled by the SWDTEN bit in the WDTCON register) +#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) +#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) +#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) +#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) +#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) +#pragma config CLKOUTEN = ON // Clock Out Enable (CLKOUT function is enabled on the CLKOUT pin) +#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled) +#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) + +// CONFIG2 +#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) +#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled) +#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) +#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) +#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled) + + +/***************** # Defines *****************/ +#define lcd_data BIT3HI +#define lcd_command BIT3LO +#define hangTime 1000 +#define total_values 100 //this is the total number of values that will be saved in the array + +/*************** module level variables ************/ + +static char counter; +int x, y; +int i = 0; +int captureTracker = 0; + +//int total_values = 24; //set the total number of values to capture +int moistureValues[total_values]; //array for moisture values +int moistureChangeRate[total_values]; //array for change in moisture values + +static unsigned int uPeriod; +static unsigned int rawInterval; + +int waterCal = 19667; //where does this number come from? +int twentyPer = 19235; //where does this number come from? +int airCal = 18587; //where does this number come from? +int moisture = 0; //initialized to zero, maybe this should be unsigned +int previous_moisture = 0; //initialized to zero +int target_value = 20; //I set this arbitrarily to test the code + + +/********* Function Prototypes ***************/ + +void InitPorts(void); +void InitTimers(void); +void InitInterrupts(void); +void WatchDogTimer(void); +void SightPin_C2(void); +void SightPin_C1(void); +void MoistureCalc(void); +void SetLEDsForWatering(void); + + +/******* Acutal Functions ****************/ + +void InitPorts() +{ + + ANSELA = 0x00; // Port A pins are digital + ANSELC = 0x00; // Port B pins are digital + + + TRISA = 0b00000000; // 1 - input, 0 - output, all A pins are outputs + TRISC = 0b00100000; // 1 - input, 0 - output, RC5 is an input, it's the input capture pin + + + + PORTA = 0b11100010; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) + PORTC = 0b00000000; + + APFCON0 = 0x00; // Alternative pin function control register + //OSCCON = 0b10000010; + +} + +void InitTimers() +{ + T1CON = 0b01110011; /******************************************** + bits <7:6>(TMR1CS) = 01; TMR1 clk source is Fosc + bits <5:4>(T1CKPS) = 11; divide by 8 prescale + bit 3 (T1OSCEN)= 0; TMR1 oscillator disabled + bit 2 (T1SYNC) = 0; synchronize external clk with + sys clock (Fosc) + bit 1 = unimplemented + bit 0 (TMR1ON)= 1; TMR1 on + *******************************************/ + + T1GCON = 0b10000100; /******************************************** + bit 7(TMR1GE) = 1; TMR1 contolled by gate function + bit 6(T1GPOL) = 0; TMR1 counts when gate is low + bit 5(T1GTM) = 0; gate toggle is disabled + bit 4(T1GSPM) = 0; single pulse mode disabled + bit 3(T1GGO) = 0; clear when bit 4 is clear + bit 2(T1GVAL) = 1; current state of TMR1 gate + bit <1:0>(T1GSS) = 00; TMR1 gate pin + *******************************************/ + + CCP1CON = 0b00110100; //capture mode: every falling edge + //CCP1CON = 0b00000100; //least 4 bits sets capture mode + + T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz + /******************************************** + bit 7 unimplemented + bit <6:3>(TxOUTPS) = 1111; 1:16 postscaler + bit 2(TMR2ON) = 1; Timer2 is on + bit <1:0>(T1GSS) = 10; prescaler is 16 + *******************************************/ + + PR2 = 250 + ; //Period Register; each clock cycle if TMR2 == PR2 then match signal to output and TMR2 = 00h +} + +void WatchDogTimer() { + + //00010101 about 1 second + WDTCON = 0b00010101; //00100101 prescale 1:2^23 which is about 4.3 minutes + /***************************** + bit 7-6 Unimplemented + bit 5-1 WDTPS<4:0>: Watchdog Timer Period Select bits + bit 0 SWDTEN: Software Enable/Disable for Watchdog Timer bit + *****************************/ + +} + +/* To enable interrupts the following bits of INTCON must be set: GIE and PEIE. And, the interrupt enable bits for + the specific interrupt events. The following happens when an interrupt event happens and GIE is set: current + prefetched instruction is flushed, GIE is cleared, PC pushed onto stack, critical registers saved to shadow + registers, PC is loaded with interrupt vector 0004h. + */ +void InitInterrupts() +{ + //Peripheral Interrupt Enable Register + PIE1 = 0b00000110; + /******************************************** + bit 7(TMR1GIE) Timer1 Gate Interrupt Enable bit + bit 6(ADIE) A/D Converter (ADC) Interrupt Enable bit + bit 5(RCIE) USART Receive Interrupt Enable bit + bit 4(TXIE) USART Transmit Interrupt Enable bit + bit 3(SSP1IE) Synchronous Serial Port 1 (MSSP1) + bit 2(CCP1IE) CCP1 Interrupt Enable bit + bit 1(TMR2IE) TMR2 to PR2 Match Interrupt Enable bit + bit 0(TMR1IE) Timer1 Overflow Interrupt Enable bit + *******************************************/ + + CCP1IF = 0; // Interrupt request flag bit of the PIR1 register, this is set on capture + + INTCON = 0b11000000; + /******************************************** + bit 7(GIE) = 1; Global Interrupt Enable bit + bit 6(PEIE) = 1; Peripheral Interrupt Enable bit + bit 5(TMR0IE) = 0; Timer0 Overflow Interrupt Enable bit + bit 4(INTE) = 0; INT External Interrupt Enable bit + bit 3(IOCIE) = 0; Interrupt-on-Change Enable bit + bit 2(TMR0IF) = 0; Timer0 Overflow Interrupt FLag bit + bit 1(INTF) = 0; INT External Interrupt Flag bit + bit 0(IOCIF) = 0; Interrupt-on-Change Interrupt Flag bit + *******************************************/ + + //Peripheral Interrupt Request Register 1 + //PIR1 = 0b00000000; + /******************************************** + bit 7 TMR1GIF: Timer1 Gate Interrupt Flag bit + bit 6 ADIF: A/D Converter Interrupt Flag bit + bit 5 RCIF: USART Receive Interrupt Flag bit + bit 4 TXIF: USART Transmit Interrupt Flag bit + bit 3 SSP1IF: Synchronous Serial Port 1 (MSSP1) Interrupt Flag bit + bit 2 CCP1IF: CCP1 Interrupt Flag bit + bit 1 TMR2IF: Timer2 to PR2 Interrupt Flag bit + bit 0 TMR1IF: Timer1 Overflow Interrupt Flag bit + *******************************************/ +} + +/* First need to poll the interrupt flag bits to determine source of interrupt. + * The two pulses we are looking for are separated by 100 to 200 miliseconds (ms), + * so we need the ISR to finish its work in probably less than 100 ms. The program + * will then return to the main function to wait out the rest of the delay and the + * ISR should be called again before it goes into sleep mode. */ +void interrupt ISR() // function needs to execute in <100ms +{ + counter++; + if (TMR2IF) // PIR1<1> + { + if ((counter % 2) != 0) + { + PORTA |= BIT2HI; // 0b00000100 + + } + else + { + PORTA &= BIT2LO; // 0b11111011 + counter = 0; + } + + TMR2IF = 0; // clears the TIMR2IF (timer 2 interrupt flag) + + } + + if (CCP1IF) // flag is in register PIR1<2> + { + + + static unsigned int uLastEdge; + char highByte; + char lowByte; + int CCPR1_Snapshot; + + captureTracker ++; //keeps track of how many captures have been done + + SightPin_C2(); // debugging + + highByte = CCPR1H; // CCPR1H captures value from TMR1H register + lowByte = CCPR1L; // CCPR1L captures value from TMR1L register + + //this is the time when the pulse from the sensor arrived + CCPR1_Snapshot = (highByte<<8) | lowByte; // combine into 16 bit int + + uPeriod = CCPR1_Snapshot - uLastEdge; + uLastEdge = CCPR1_Snapshot; // this variable should not be in scope next ISR + + + if (uPeriod == 0) { uPeriod = 23; } + //twentyPer = uPeriod; + + //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? + //the datasheet says to stop the timer before writing to below registers + TMR1H = 0; + TMR1L = 0; + + CCP1IF = 0; // clear the flag + } + + +} //pops previous address from the stack, restores registers, and sets GIE bit + + +void MoistureCalc(void) +{ + + /* The following moisture calculation section is commented out until we + * can understand how this calculation yields the percentage of water in + * the soil. + + int x; + + if (uPeriod < airCal) + { + x = airCal; + + moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); + + } + + if (uPeriod <= twentyPer) + { + x = ((uPeriod - airCal)*100)/(twentyPer - airCal); + + moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); + } + + + if (uPeriod > twentyPer) + { + x = ((uPeriod - twentyPer)*50)/((waterCal-twentyPer)+100); + + moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + + } + + if (uPeriod > waterCal) + { + x = waterCal; + + moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); + + } + */ + + //set the value of the moisture, should be a number from 0 to 100 + moisture = 25; //this will be a formula based on the characterization curve + + //this gives the next index for the arrays + int next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide + + //add the next moisture value and rate change to the arrays + moistureValues[next_index] = moisture; + moistureChangeRate[next_index] = moisture - previous_moisture; + + //save the current moisture reading to calculate the rate change + previous_moisture = moisture; + +} + +void SetLEDsForWatering(void) // must account for rate of watering. +{ + if (moisture < target_value) {PORTC &= BIT1LO;} //RB5 port LED bright + else {PORTC |= BIT1HI;} //RB5 port LED dim + +} + + +/***********************************************************/ +/******************** Debugging Library ********************/ + +void SightPin_C1(void) +{ + // toggles pin A2 for debugging purposes + if ((PORTC & BIT1HI) == BIT1HI) + { + PORTC &= BIT1LO; + + } + else + { + PORTC |= BIT1HI; + } + +} + +void SightPin_C2(void) +{ + // toggles pin A3 for debugging purposes + if ((PORTC & BIT2HI) == BIT2HI) + { + PORTC &= BIT2LO; + + } + else + { + PORTC |= BIT2HI; + } + +} + + +/********************************************************/ +/******** Main - which actually runs the code ***********/ +/********************************************************/ + +void main () +{ + + // Initializing PIC16LF1827 + InitPorts(); + InitTimers(); + InitInterrupts(); + + + + while(1) + { + //turn sensor on + //PORTB &= BIT4LO; + PORTC |= BIT4HI; + + //PC stuck in loop until first capture (capTrack is an even number) + while (captureTracker % 2 == 0){PORTC |= BIT0HI;}//RA3 dim // even and 0 % 2 = 0 + + //PC stuck in another loop until second capture (capTrack is an odd number) + while (captureTracker % 2 == 1){PORTC &= BIT0LO;}//RA4 dim //odd % 2 = 1 + + //turn off sensor + //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle + PORTC &= BIT4LO; + + //do calculation + MoistureCalc(); + + //turn on LEDs if need to water + SetLEDsForWatering(); + + //Put device to sleep and wait for the next time to take a measurment + //the sleep time is set by the postscaler of the WDT + for (y=0;y<4;y++) {SLEEP();} // will sleep x number of times + + //start the count over when the array's are full + //capture tracker will be an even number at this point + //if (captureTracker == (2*total_values)) {captureTracker = 0;} + + + /* this code works to strobe an LED connected to RB4 + PORTB &= BIT4LO; //makes LED on RB4 bright -- currenly 2.2V (Sensor Power) + for (y=0;y<2;y++) {SLEEP();} // will sleep x number of times + PORTB |= BIT4HI; //makes LED on RB4 dim + for (y=0;y<2;y++) {SLEEP();} // sleep x number of times + */ + } + + + +} + + From 9a315cb10bdcd35a1d37981b83b7b5769f843e37 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Tue, 9 Sep 2014 18:21:37 -0700 Subject: [PATCH 09/23] Comment Clean removed some comments --- 1825_EccoPro_Run1.c | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 878b57a..1486b9f 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -1,10 +1,10 @@ /************************ -This is a module to program the PIC16LF1827 get data from +This is a module to program the PIC16LF1825 get data from the ECCO Pro sensor and output a moisture reading. First going to get input caputure working with inputs -from a signal generator. +from a signal generator. Josh has since gotten this to corr author: Osagie Igbeare 8/7/2014 @@ -146,8 +146,7 @@ void InitTimers() bit <1:0>(T1GSS) = 10; prescaler is 16 *******************************************/ - PR2 = 250 - ; //Period Register; each clock cycle if TMR2 == PR2 then match signal to output and TMR2 = 00h + PR2 = 250; } void WatchDogTimer() { @@ -162,11 +161,7 @@ void WatchDogTimer() { } -/* To enable interrupts the following bits of INTCON must be set: GIE and PEIE. And, the interrupt enable bits for - the specific interrupt events. The following happens when an interrupt event happens and GIE is set: current - prefetched instruction is flushed, GIE is cleared, PC pushed onto stack, critical registers saved to shadow - registers, PC is loaded with interrupt vector 0004h. - */ + void InitInterrupts() { //Peripheral Interrupt Enable Register @@ -196,29 +191,12 @@ void InitInterrupts() bit 0(IOCIF) = 0; Interrupt-on-Change Interrupt Flag bit *******************************************/ - //Peripheral Interrupt Request Register 1 - //PIR1 = 0b00000000; - /******************************************** - bit 7 TMR1GIF: Timer1 Gate Interrupt Flag bit - bit 6 ADIF: A/D Converter Interrupt Flag bit - bit 5 RCIF: USART Receive Interrupt Flag bit - bit 4 TXIF: USART Transmit Interrupt Flag bit - bit 3 SSP1IF: Synchronous Serial Port 1 (MSSP1) Interrupt Flag bit - bit 2 CCP1IF: CCP1 Interrupt Flag bit - bit 1 TMR2IF: Timer2 to PR2 Interrupt Flag bit - bit 0 TMR1IF: Timer1 Overflow Interrupt Flag bit - *******************************************/ } -/* First need to poll the interrupt flag bits to determine source of interrupt. - * The two pulses we are looking for are separated by 100 to 200 miliseconds (ms), - * so we need the ISR to finish its work in probably less than 100 ms. The program - * will then return to the main function to wait out the rest of the delay and the - * ISR should be called again before it goes into sleep mode. */ void interrupt ISR() // function needs to execute in <100ms { counter++; - if (TMR2IF) // PIR1<1> + if (TMR2IF) { if ((counter % 2) != 0) { From d4fbfcaeb1c77cb930b65ced585614e13e633a0c Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Thu, 11 Sep 2014 18:43:42 -0700 Subject: [PATCH 10/23] EUSART set up and starting IOC implementing things needed for full bluetooth functionality --- 1825_EccoPro_Run1.c | 83 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 1486b9f..b89e9ea 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -4,7 +4,8 @@ This is a module to program the PIC16LF1825 get data from the ECCO Pro sensor and output a moisture reading. First going to get input caputure working with inputs -from a signal generator. Josh has since gotten this to corr +from a signal generator. Josh has since gotten this to correctly receieve +data from Ecco Pro sensor author: Osagie Igbeare 8/7/2014 @@ -63,6 +64,7 @@ static char counter; int x, y; int i = 0; int captureTracker = 0; +int tick = 0; //int total_values = 24; //set the total number of values to capture int moistureValues[total_values]; //array for moisture values @@ -84,6 +86,7 @@ int target_value = 20; //I set this arbitrarily to test the code void InitPorts(void); void InitTimers(void); void InitInterrupts(void); +void InitComm(void); void WatchDogTimer(void); void SightPin_C2(void); void SightPin_C1(void); @@ -97,18 +100,35 @@ void InitPorts() { ANSELA = 0x00; // Port A pins are digital - ANSELC = 0x00; // Port B pins are digital + ANSELC = 0x00; // Port C pins are digital - TRISA = 0b00000000; // 1 - input, 0 - output, all A pins are outputs - TRISC = 0b00100000; // 1 - input, 0 - output, RC5 is an input, it's the input capture pin + TRISA = 0b00111010; // 1 - input, 0 - output; (?) - can be used for something else + /******************************** + A0 - output - Tx pin + (?)A1 - input - Rx pin + A2 - output - drives "water" LEDs + A3 - doesn't matter - MCLR pin + A4 - doesn't matter - CLKOut pin + A5 - doesn't matter - CLCKIn pin + ********************************/ + TRISC = 0b00100011; // 1 - input, 0 - output + /********************************** + C0 - input - data transfer button + C1 - input - demo mode button + C2 - output - drives "stop water" LEDs + (?) C3 - output- while loop indicator + C4 - output - turns on Ecco + C5 - input - input capture pin + ********************************/ - PORTA = 0b11100010; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) - PORTC = 0b00000000; - APFCON0 = 0x00; // Alternative pin function control register + PORTA = 0b00000000; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) + PORTC = 0b00000001; + + APFCON0 = 0b10000100; // Enables RA0 to be Tx pin, RA1 to be Rx pin (for EUSART) //OSCCON = 0b10000010; } @@ -159,6 +179,20 @@ void WatchDogTimer() { bit 0 SWDTEN: Software Enable/Disable for Watchdog Timer bit *****************************/ +} + +void InitComm() +{ + // configuration for EUSART + + BAUDCON = 0b00000000; // bit 3 (BRG16) = 0; default setting, indcluded for clarity + SPBRG = 25; // SPBRG = (Fosc / (16*BaudRate))-1; Fosc = 4MHz + SPBRGH = 0; + TXSTA = 0b00100100; //TxEn set, BRGH set, 8 bit trans, asynchronous + RCSTA = 0b10010000; //RxEn set, 8 bit receive, CREN set, no addr detection + + + } @@ -179,7 +213,7 @@ void InitInterrupts() CCP1IF = 0; // Interrupt request flag bit of the PIR1 register, this is set on capture - INTCON = 0b11000000; + INTCON = 0b11001000; /******************************************** bit 7(GIE) = 1; Global Interrupt Enable bit bit 6(PEIE) = 1; Peripheral Interrupt Enable bit @@ -190,12 +224,14 @@ void InitInterrupts() bit 1(INTF) = 0; INT External Interrupt Flag bit bit 0(IOCIF) = 0; Interrupt-on-Change Interrupt Flag bit *******************************************/ + INTF = 0; // clear IOC Flag } void interrupt ISR() // function needs to execute in <100ms { counter++; + tick++; if (TMR2IF) { if ((counter % 2) != 0) @@ -216,7 +252,6 @@ void interrupt ISR() // function needs to execute in <100ms if (CCP1IF) // flag is in register PIR1<2> { - static unsigned int uLastEdge; char highByte; char lowByte; @@ -224,7 +259,7 @@ void interrupt ISR() // function needs to execute in <100ms captureTracker ++; //keeps track of how many captures have been done - SightPin_C2(); // debugging + //SightPin_C2(); // debugging highByte = CCPR1H; // CCPR1H captures value from TMR1H register lowByte = CCPR1L; // CCPR1L captures value from TMR1L register @@ -246,6 +281,30 @@ void interrupt ISR() // function needs to execute in <100ms CCP1IF = 0; // clear the flag } + + if (INTF) // check to see if button (RC0) was pushed + { + // turn on LED + if ((PORTC & BIT0LO) == BIT0LO) + { + SightPin_C2(); + + if ((tick % 2) != 0) + { + PORTC |= BIT1HI; // 0b00000100 + + } + else + { + PORTC &= BIT1LO; // 0b11111011 + tick = 0; + } + + INTF = 0; + + } + + } } //pops previous address from the stack, restores registers, and sets GIE bit @@ -371,10 +430,10 @@ void main () PORTC |= BIT4HI; //PC stuck in loop until first capture (capTrack is an even number) - while (captureTracker % 2 == 0){PORTC |= BIT0HI;}//RA3 dim // even and 0 % 2 = 0 + while (captureTracker % 2 == 0){PORTC |= BIT3HI;}//RA3 dim // even and 0 % 2 = 0 //PC stuck in another loop until second capture (capTrack is an odd number) - while (captureTracker % 2 == 1){PORTC &= BIT0LO;}//RA4 dim //odd % 2 = 1 + while (captureTracker % 2 == 1){PORTC &= BIT3LO;}//RA4 dim //odd % 2 = 1 //turn off sensor //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle From 7049f2f97aa66b404062256180d5f93d9a7a9cda Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Thu, 11 Sep 2014 19:03:11 -0700 Subject: [PATCH 11/23] IOC Bug caught MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit turns out C0 isn’t an IOC pin - A2 is though. --- 1825_EccoPro_Run1.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index b89e9ea..933b90c 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -103,20 +103,20 @@ void InitPorts() ANSELC = 0x00; // Port C pins are digital - TRISA = 0b00111010; // 1 - input, 0 - output; (?) - can be used for something else + TRISA = 0b00111110; // 1 - input, 0 - output; (?) - can be used for something else /******************************** A0 - output - Tx pin (?)A1 - input - Rx pin - A2 - output - drives "water" LEDs + A2 - input - data transfer button A3 - doesn't matter - MCLR pin A4 - doesn't matter - CLKOut pin A5 - doesn't matter - CLCKIn pin ********************************/ - TRISC = 0b00100011; // 1 - input, 0 - output + TRISC = 0b00100001; // 1 - input, 0 - output /********************************** C0 - input - data transfer button - C1 - input - demo mode button + C1 - output - demo mode button C2 - output - drives "stop water" LEDs (?) C3 - output- while loop indicator C4 - output - turns on Ecco @@ -236,12 +236,12 @@ void interrupt ISR() // function needs to execute in <100ms { if ((counter % 2) != 0) { - PORTA |= BIT2HI; // 0b00000100 + PORTC |= BIT1HI; // 0b00000100 } else { - PORTA &= BIT2LO; // 0b11111011 + PORTC &= BIT1LO; // 0b11111011 counter = 0; } @@ -282,21 +282,21 @@ void interrupt ISR() // function needs to execute in <100ms CCP1IF = 0; // clear the flag } - if (INTF) // check to see if button (RC0) was pushed + if (INTF) // check to see if button (RA2) was pushed { // turn on LED - if ((PORTC & BIT0LO) == BIT0LO) + if ((PORTA & BIT2LO) == BIT2LO) { - SightPin_C2(); + //SightPin_C2(); if ((tick % 2) != 0) { - PORTC |= BIT1HI; // 0b00000100 + PORTC |= BIT2HI; // 0b00000100 } else { - PORTC &= BIT1LO; // 0b11111011 + PORTC &= BIT2LO; // 0b11111011 tick = 0; } From 648ff483be27e1b3f2a070595b3378ea11f19da6 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Fri, 12 Sep 2014 14:40:17 -0700 Subject: [PATCH 12/23] IOC Attempt 2 --- 1825_EccoPro_Run1.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 933b90c..1bf45a8 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -115,9 +115,9 @@ void InitPorts() TRISC = 0b00100001; // 1 - input, 0 - output /********************************** - C0 - input - data transfer button + C0 - input - C1 - output - demo mode button - C2 - output - drives "stop water" LEDs + C2 - output - IOC LED check (?) C3 - output- while loop indicator C4 - output - turns on Ecco C5 - input - input capture pin @@ -126,7 +126,7 @@ void InitPorts() PORTA = 0b00000000; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) - PORTC = 0b00000001; + PORTC = 0b00000101; APFCON0 = 0b10000100; // Enables RA0 to be Tx pin, RA1 to be Rx pin (for EUSART) //OSCCON = 0b10000010; @@ -213,18 +213,18 @@ void InitInterrupts() CCP1IF = 0; // Interrupt request flag bit of the PIR1 register, this is set on capture - INTCON = 0b11001000; + INTCON = 0b11010000; /******************************************** bit 7(GIE) = 1; Global Interrupt Enable bit bit 6(PEIE) = 1; Peripheral Interrupt Enable bit bit 5(TMR0IE) = 0; Timer0 Overflow Interrupt Enable bit bit 4(INTE) = 0; INT External Interrupt Enable bit - bit 3(IOCIE) = 0; Interrupt-on-Change Enable bit + bit 3(IOCIE) = 1; Interrupt-on-Change Enable bit bit 2(TMR0IF) = 0; Timer0 Overflow Interrupt FLag bit bit 1(INTF) = 0; INT External Interrupt Flag bit bit 0(IOCIF) = 0; Interrupt-on-Change Interrupt Flag bit *******************************************/ - INTF = 0; // clear IOC Flag + INTF = 0; // clear IOC Flag } @@ -308,7 +308,7 @@ void interrupt ISR() // function needs to execute in <100ms } //pops previous address from the stack, restores registers, and sets GIE bit - +//uint8_t myVar @0xD00; void MoistureCalc(void) { @@ -430,10 +430,10 @@ void main () PORTC |= BIT4HI; //PC stuck in loop until first capture (capTrack is an even number) - while (captureTracker % 2 == 0){PORTC |= BIT3HI;}//RA3 dim // even and 0 % 2 = 0 + while (captureTracker % 2 == 0){PORTC &= BIT3LO;}//RA3 dim // even and 0 % 2 = 0 //PC stuck in another loop until second capture (capTrack is an odd number) - while (captureTracker % 2 == 1){PORTC &= BIT3LO;}//RA4 dim //odd % 2 = 1 + while (captureTracker % 2 == 1){PORTC |= BIT3HI;}//RA4 dim //odd % 2 = 1 //turn off sensor //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle @@ -445,6 +445,11 @@ void main () //turn on LEDs if need to water SetLEDsForWatering(); + //while(!TXIF); + + //TXREG = 0x77; + + //Put device to sleep and wait for the next time to take a measurment //the sleep time is set by the postscaler of the WDT for (y=0;y<4;y++) {SLEEP();} // will sleep x number of times From bf4f840cf82fb9caac48877c8a647bc0724a4b6c Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Fri, 12 Sep 2014 20:08:07 -0700 Subject: [PATCH 13/23] Wake from Sleep on button push working using interrupt on change instead of ext interrupt, checking IOCIF flag, then doing a secondary check for the pin the button is connected to --- 1825_EccoPro_Run1.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 1bf45a8..1325c81 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -64,7 +64,7 @@ static char counter; int x, y; int i = 0; int captureTracker = 0; -int tick = 0; +int tick = 1; //int total_values = 24; //set the total number of values to capture int moistureValues[total_values]; //array for moisture values @@ -88,6 +88,7 @@ void InitTimers(void); void InitInterrupts(void); void InitComm(void); void WatchDogTimer(void); +void IOC_Config(void); void SightPin_C2(void); void SightPin_C1(void); void MoistureCalc(void); @@ -125,7 +126,7 @@ void InitPorts() - PORTA = 0b00000000; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) + PORTA = 0b00000100; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) PORTC = 0b00000101; APFCON0 = 0b10000100; // Enables RA0 to be Tx pin, RA1 to be Rx pin (for EUSART) @@ -213,7 +214,7 @@ void InitInterrupts() CCP1IF = 0; // Interrupt request flag bit of the PIR1 register, this is set on capture - INTCON = 0b11010000; + INTCON = 0b11001000; /******************************************** bit 7(GIE) = 1; Global Interrupt Enable bit bit 6(PEIE) = 1; Peripheral Interrupt Enable bit @@ -224,17 +225,26 @@ void InitInterrupts() bit 1(INTF) = 0; INT External Interrupt Flag bit bit 0(IOCIF) = 0; Interrupt-on-Change Interrupt Flag bit *******************************************/ - INTF = 0; // clear IOC Flag + // IOCIF = 0; // clear IOC Flag + +} + +void IOC_Config() +{ + IOCAP = 0x00; // IOC for rising edge disabled for port A + IOCAN = 0b00000100; // IOC for falling edge enabled for A2 + IOCAF = 0x00; // clear IOC flags for port A } void interrupt ISR() // function needs to execute in <100ms { - counter++; - tick++; + + if (TMR2IF) { - if ((counter % 2) != 0) + counter++; + if ((counter % 2) != 0) { PORTC |= BIT1HI; // 0b00000100 @@ -276,20 +286,23 @@ void interrupt ISR() // function needs to execute in <100ms //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? //the datasheet says to stop the timer before writing to below registers - TMR1H = 0; - TMR1L = 0; + //TMR1H = 0; + //TMR1L = 0; CCP1IF = 0; // clear the flag } - if (INTF) // check to see if button (RA2) was pushed + if (IOCIF) // check to see if button (RA2) was pushed { + //INTCON &= BIT3LO; // turn on LED - if ((PORTA & BIT2LO) == BIT2LO) + if ((IOCAF & BIT2HI) == BIT2HI) { //SightPin_C2(); - - if ((tick % 2) != 0) + TXREG = 0x77; + + tick++; + if ((tick % 2) != 0) { PORTC |= BIT2HI; // 0b00000100 @@ -300,7 +313,9 @@ void interrupt ISR() // function needs to execute in <100ms tick = 0; } - INTF = 0; + IOCAF &= BIT2LO; + IOCIF = 0; + INTCON |= BIT3HI; } @@ -419,7 +434,9 @@ void main () // Initializing PIC16LF1827 InitPorts(); InitTimers(); + InitComm(); InitInterrupts(); + IOC_Config(); From 6a695b54e7560d5451892573c0eebed9f78ab2bf Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Mon, 15 Sep 2014 15:38:25 -0700 Subject: [PATCH 14/23] Send Data on Button Push Working MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit turns out can’t really write to TXREG in interrupt or you’ll get trash as well data you wrote out. Instead we set flag, and once it’s set a function in foreground will send out data in a for loop --- 1825_EccoPro_Run1.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 1325c81..691b961 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -65,6 +65,8 @@ int x, y; int i = 0; int captureTracker = 0; int tick = 1; +char dummy; +int buttonPush = 0; //int total_values = 24; //set the total number of values to capture int moistureValues[total_values]; //array for moisture values @@ -299,7 +301,10 @@ void interrupt ISR() // function needs to execute in <100ms if ((IOCAF & BIT2HI) == BIT2HI) { //SightPin_C2(); - TXREG = 0x77; + + buttonPush = 1; + + INTCON &= BIT3LO; // turn off IOCIE - interrupt on change tick++; if ((tick % 2) != 0) @@ -313,9 +318,9 @@ void interrupt ISR() // function needs to execute in <100ms tick = 0; } - IOCAF &= BIT2LO; - IOCIF = 0; - INTCON |= BIT3HI; + IOCAF &= BIT2LO; + IOCIF = 0; + INTCON |= BIT3HI; } @@ -442,6 +447,21 @@ void main () while(1) { + //function to check flag if true then send data + + if (buttonPush == 1) + { + + for (int j = 0; j<30; j++) + { + while (!TXIF); + TXREG = moistureValues[j]; + } + + buttonPush = 0; + } + + //turn sensor on //PORTB &= BIT4LO; PORTC |= BIT4HI; @@ -456,6 +476,8 @@ void main () //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle PORTC &= BIT4LO; + + //do calculation MoistureCalc(); From f171bf225feabc601f0c68dfc139bf7d0e18fbe9 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Mon, 15 Sep 2014 15:48:01 -0700 Subject: [PATCH 15/23] Smarter For Loop # of times you iterate thru for loop is now set by how many values there are in moisture array --- 1825_EccoPro_Run1.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 691b961..c2b3eab 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -66,7 +66,8 @@ int i = 0; int captureTracker = 0; int tick = 1; char dummy; -int buttonPush = 0; +int buttonPush = 0; +int next_index; //int total_values = 24; //set the total number of values to capture int moistureValues[total_values]; //array for moisture values @@ -376,7 +377,7 @@ void MoistureCalc(void) moisture = 25; //this will be a formula based on the characterization curve //this gives the next index for the arrays - int next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide + next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide //add the next moisture value and rate change to the arrays moistureValues[next_index] = moisture; @@ -452,7 +453,7 @@ void main () if (buttonPush == 1) { - for (int j = 0; j<30; j++) + for (int j = 0; j<(next_index + 1); j++) { while (!TXIF); TXREG = moistureValues[j]; From 159d6ab3a7c8c033fbe42691eb74ccae6a25a2d9 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Mon, 15 Sep 2014 15:49:56 -0700 Subject: [PATCH 16/23] Resetting captureTracker at buttonPush --- 1825_EccoPro_Run1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index c2b3eab..d7007ef 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -459,7 +459,8 @@ void main () TXREG = moistureValues[j]; } - buttonPush = 0; + buttonPush = 0; + captureTracker = 0; } From effc175eff6eb6f21d0f358b6963377562555888 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Tue, 16 Sep 2014 19:05:22 -0700 Subject: [PATCH 17/23] New Moisture Algorithm, Powering ECCO deleted dead code, made some changes to reflect circuit design changes (i.e using BJT in powering ECCO) --- 1825_EccoPro_Run1.c | 135 +++++++++++++------------------------------- 1 file changed, 39 insertions(+), 96 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index d7007ef..7c8ba47 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -7,7 +7,7 @@ First going to get input caputure working with inputs from a signal generator. Josh has since gotten this to correctly receieve data from Ecco Pro sensor -author: Osagie Igbeare +author: Osagie Igbeare - o.igbeare@gmail.com 8/7/2014 Modified by: joshuafrancis80@gmail.com @@ -53,10 +53,9 @@ Date: 9/1/2014 /***************** # Defines *****************/ -#define lcd_data BIT3HI -#define lcd_command BIT3LO #define hangTime 1000 #define total_values 100 //this is the total number of values that will be saved in the array +#define DREAM_TIME 4 /*************** module level variables ************/ @@ -64,8 +63,6 @@ static char counter; int x, y; int i = 0; int captureTracker = 0; -int tick = 1; -char dummy; int buttonPush = 0; int next_index; @@ -73,12 +70,8 @@ int next_index; int moistureValues[total_values]; //array for moisture values int moistureChangeRate[total_values]; //array for change in moisture values -static unsigned int uPeriod; -static unsigned int rawInterval; +static unsigned int uPeriod; -int waterCal = 19667; //where does this number come from? -int twentyPer = 19235; //where does this number come from? -int airCal = 18587; //where does this number come from? int moisture = 0; //initialized to zero, maybe this should be unsigned int previous_moisture = 0; //initialized to zero int target_value = 20; //I set this arbitrarily to test the code @@ -244,7 +237,8 @@ void interrupt ISR() // function needs to execute in <100ms { - if (TMR2IF) + if (TMR2IF) + { counter++; if ((counter % 2) != 0) @@ -272,7 +266,6 @@ void interrupt ISR() // function needs to execute in <100ms captureTracker ++; //keeps track of how many captures have been done - //SightPin_C2(); // debugging highByte = CCPR1H; // CCPR1H captures value from TMR1H register lowByte = CCPR1L; // CCPR1L captures value from TMR1L register @@ -283,6 +276,10 @@ void interrupt ISR() // function needs to execute in <100ms uPeriod = CCPR1_Snapshot - uLastEdge; uLastEdge = CCPR1_Snapshot; // this variable should not be in scope next ISR + // above is a method to capture the values from the TMR1H and TMR1L register and combine + // them into a 16 bit integer. This 16 bit integer gives the "time reading" when the falling + // edge occurred. + if (uPeriod == 0) { uPeriod = 23; } //twentyPer = uPeriod; @@ -297,31 +294,20 @@ void interrupt ISR() // function needs to execute in <100ms if (IOCIF) // check to see if button (RA2) was pushed { - //INTCON &= BIT3LO; - // turn on LED + + if ((IOCAF & BIT2HI) == BIT2HI) { - //SightPin_C2(); + buttonPush = 1; INTCON &= BIT3LO; // turn off IOCIE - interrupt on change - tick++; - if ((tick % 2) != 0) - { - PORTC |= BIT2HI; // 0b00000100 - } - else - { - PORTC &= BIT2LO; // 0b11111011 - tick = 0; - } - - IOCAF &= BIT2LO; + IOCAF &= BIT2LO; // clear IOC Flag for port A2 IOCIF = 0; - INTCON |= BIT3HI; + INTCON |= BIT3HI; //Re-enable IOCIE interrupt } @@ -329,52 +315,18 @@ void interrupt ISR() // function needs to execute in <100ms } //pops previous address from the stack, restores registers, and sets GIE bit -//uint8_t myVar @0xD00; + void MoistureCalc(void) { - /* The following moisture calculation section is commented out until we - * can understand how this calculation yields the percentage of water in - * the soil. - - int x; - - if (uPeriod < airCal) - { - x = airCal; - - moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); - - } - - if (uPeriod <= twentyPer) - { - x = ((uPeriod - airCal)*100)/(twentyPer - airCal); - - moisture = ((uPeriod - airCal)*x )/((twentyPer - airCal)*100); - } - - - if (uPeriod > twentyPer) - { - x = ((uPeriod - twentyPer)*50)/((waterCal-twentyPer)+100); - - moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); - - } - - if (uPeriod > waterCal) - { - x = waterCal; - - moisture = ((uPeriod - twentyPer)*(x-100))/ ((waterCal-twentyPer)*50); - - } - */ - //set the value of the moisture, should be a number from 0 to 100 - moisture = 25; //this will be a formula based on the characterization curve + //this will be a formula based on the characterization curve + + /********************************************************************************/ + /**********this is where to put new algorithm for for moisture calc**************/ + /********************************************************************************/ + moisture = (15*uPeriod) - 2399; //this gives the next index for the arrays next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide @@ -390,8 +342,15 @@ void MoistureCalc(void) void SetLEDsForWatering(void) // must account for rate of watering. { - if (moisture < target_value) {PORTC &= BIT1LO;} //RB5 port LED bright - else {PORTC |= BIT1HI;} //RB5 port LED dim + if (moisture > target_value) + { + PORTA |= BIT2HI; // turn on lights indicating "water" + } + else + { + PORTC |= BIT2HI; // turn on lights indicating "stop watering" + + } } @@ -448,7 +407,7 @@ void main () while(1) { - //function to check flag if true then send data + //function to check flag, if true then send data via bluetooth to paired computer if (buttonPush == 1) { @@ -465,8 +424,9 @@ void main () //turn sensor on - //PORTB &= BIT4LO; - PORTC |= BIT4HI; + // pull low - turns off NPN BJT - which then turns on Ecco + + PORTC &= BIT4LO; //PC stuck in loop until first capture (capTrack is an even number) while (captureTracker % 2 == 0){PORTC &= BIT3LO;}//RA3 dim // even and 0 % 2 = 0 @@ -475,10 +435,8 @@ void main () while (captureTracker % 2 == 1){PORTC |= BIT3HI;}//RA4 dim //odd % 2 = 1 //turn off sensor - //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle - PORTC &= BIT4LO; - - + //pull high - turns on NPN BJT - turns Ecco off + PORTC |= BIT4HI; //do calculation MoistureCalc(); @@ -486,26 +444,11 @@ void main () //turn on LEDs if need to water SetLEDsForWatering(); - //while(!TXIF); - //TXREG = 0x77; - - - //Put device to sleep and wait for the next time to take a measurment + //Put device to sleep and wait for the next time to take a measurment //the sleep time is set by the postscaler of the WDT - for (y=0;y<4;y++) {SLEEP();} // will sleep x number of times - - //start the count over when the array's are full - //capture tracker will be an even number at this point - //if (captureTracker == (2*total_values)) {captureTracker = 0;} - - - /* this code works to strobe an LED connected to RB4 - PORTB &= BIT4LO; //makes LED on RB4 bright -- currenly 2.2V (Sensor Power) - for (y=0;y<2;y++) {SLEEP();} // will sleep x number of times - PORTB |= BIT4HI; //makes LED on RB4 dim - for (y=0;y<2;y++) {SLEEP();} // sleep x number of times - */ + // DREAM_TIME is a #define and can be altered to alter how long mcu is asleep + for (y=0;y Date: Tue, 16 Sep 2014 19:10:59 -0700 Subject: [PATCH 18/23] More Clean Up removed Config necessary for old version of MPLAB. --- 1825_EccoPro_Run1.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 7c8ba47..38d87c1 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -26,9 +26,6 @@ Date: 9/1/2014 /***************** Configuration Macros ***************/ -//__CONFIG(FCMEN_OFF & IESO_OFF & FOSC_LP & WDTE_OFF & MCLRE_ON & PWRTE_OFF & BOREN_OFF -// & LVP_ON & WRT_OFF & CPD_OFF & CP_OFF); - // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. @@ -276,13 +273,13 @@ void interrupt ISR() // function needs to execute in <100ms uPeriod = CCPR1_Snapshot - uLastEdge; uLastEdge = CCPR1_Snapshot; // this variable should not be in scope next ISR + /*********************************************************************************************/ // above is a method to capture the values from the TMR1H and TMR1L register and combine // them into a 16 bit integer. This 16 bit integer gives the "time reading" when the falling // edge occurred. - if (uPeriod == 0) { uPeriod = 23; } - //twentyPer = uPeriod; + if (uPeriod == 0) { uPeriod = 23; } // trick to get uPeriod to show up in MLBAB's Watches window //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? //the datasheet says to stop the timer before writing to below registers From 9ef1735afe7e427384440e1ddcc9efefbb78fa62 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Thu, 18 Sep 2014 15:33:42 -0700 Subject: [PATCH 19/23] 9/18/2014 changes adlkjflds --- 1825_EccoPro_Run1.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 38d87c1..22f54f6 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -62,10 +62,11 @@ int i = 0; int captureTracker = 0; int buttonPush = 0; int next_index; +int tick = 0; //int total_values = 24; //set the total number of values to capture -int moistureValues[total_values]; //array for moisture values -int moistureChangeRate[total_values]; //array for change in moisture values +int moistureValues[total_values] = 0x00; //array for moisture values +int moistureChangeRate[total_values] = 0x00; //array for change in moisture values static unsigned int uPeriod; @@ -107,9 +108,9 @@ void InitPorts() A5 - doesn't matter - CLCKIn pin ********************************/ - TRISC = 0b00100001; // 1 - input, 0 - output + TRISC = 0b00100000; // 1 - input, 0 - output /********************************** - C0 - input - + C0 - output - C1 - output - demo mode button C2 - output - IOC LED check (?) C3 - output- while loop indicator @@ -120,7 +121,7 @@ void InitPorts() PORTA = 0b00000100; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) - PORTC = 0b00000101; + PORTC = 0b00001000; APFCON0 = 0b10000100; // Enables RA0 to be Tx pin, RA1 to be Rx pin (for EUSART) //OSCCON = 0b10000010; @@ -237,7 +238,8 @@ void interrupt ISR() // function needs to execute in <100ms if (TMR2IF) { - counter++; + /* + counter++; if ((counter % 2) != 0) { PORTC |= BIT1HI; // 0b00000100 @@ -248,6 +250,7 @@ void interrupt ISR() // function needs to execute in <100ms PORTC &= BIT1LO; // 0b11111011 counter = 0; } + */ TMR2IF = 0; // clears the TIMR2IF (timer 2 interrupt flag) @@ -301,6 +304,18 @@ void interrupt ISR() // function needs to execute in <100ms INTCON &= BIT3LO; // turn off IOCIE - interrupt on change + tick++; + if ((tick % 2) != 0) + { + PORTC |= BIT1HI; // 0b00000100 + + } + else + { + PORTC &= BIT1LO; // 0b11111011 + tick = 0; + } + IOCAF &= BIT2LO; // clear IOC Flag for port A2 IOCIF = 0; @@ -341,11 +356,13 @@ void SetLEDsForWatering(void) // must account for rate of watering. { if (moisture > target_value) { - PORTA |= BIT2HI; // turn on lights indicating "water" + PORTC |= BIT0HI; // turn on lights indicating "water" + PORTC &= BIT2LO; } else { PORTC |= BIT2HI; // turn on lights indicating "stop watering" + PORTC &= BIT0LO; } @@ -423,7 +440,7 @@ void main () //turn sensor on // pull low - turns off NPN BJT - which then turns on Ecco - PORTC &= BIT4LO; + PORTC |= BIT4HI; //PC stuck in loop until first capture (capTrack is an even number) while (captureTracker % 2 == 0){PORTC &= BIT3LO;}//RA3 dim // even and 0 % 2 = 0 @@ -433,7 +450,7 @@ void main () //turn off sensor //pull high - turns on NPN BJT - turns Ecco off - PORTC |= BIT4HI; + PORTC = BIT4LO; //do calculation MoistureCalc(); From 7afe8ea439cef22d9c217155754c265dd20f3c67 Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Thu, 18 Sep 2014 21:28:22 -0700 Subject: [PATCH 20/23] Back to the Future I winked something such that the other set of LEDs turns on during the while loop not sure what it is. Went to this old version, have to iron out the send data though. --- 1825_EccoPro_Run1.c | 136 +++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 71 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 22f54f6..54a9400 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -7,7 +7,7 @@ First going to get input caputure working with inputs from a signal generator. Josh has since gotten this to correctly receieve data from Ecco Pro sensor -author: Osagie Igbeare - o.igbeare@gmail.com +author: Osagie Igbeare 8/7/2014 Modified by: joshuafrancis80@gmail.com @@ -26,6 +26,9 @@ Date: 9/1/2014 /***************** Configuration Macros ***************/ +//__CONFIG(FCMEN_OFF & IESO_OFF & FOSC_LP & WDTE_OFF & MCLRE_ON & PWRTE_OFF & BOREN_OFF +// & LVP_ON & WRT_OFF & CPD_OFF & CP_OFF); + // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. @@ -52,28 +55,31 @@ Date: 9/1/2014 /***************** # Defines *****************/ #define hangTime 1000 #define total_values 100 //this is the total number of values that will be saved in the array -#define DREAM_TIME 4 /*************** module level variables ************/ -static char counter; +static char counter; int x, y; int i = 0; int captureTracker = 0; +int tick = 1; int buttonPush = 0; -int next_index; -int tick = 0; //int total_values = 24; //set the total number of values to capture int moistureValues[total_values] = 0x00; //array for moisture values -int moistureChangeRate[total_values] = 0x00; //array for change in moisture values +int moistureChangeRate[total_values] =0x00; //array for change in moisture values -static unsigned int uPeriod; +static unsigned int uPeriod; +static unsigned int rawInterval; +int waterCal = 19667; //where does this number come from? +int twentyPer = 19235; //where does this number come from? +int airCal = 18587; //where does this number come from? int moisture = 0; //initialized to zero, maybe this should be unsigned int previous_moisture = 0; //initialized to zero int target_value = 20; //I set this arbitrarily to test the code - +int next_index; + /********* Function Prototypes ***************/ @@ -96,7 +102,7 @@ void InitPorts() ANSELA = 0x00; // Port A pins are digital ANSELC = 0x00; // Port C pins are digital - + TRISA = 0b00111110; // 1 - input, 0 - output; (?) - can be used for something else /******************************** @@ -121,11 +127,11 @@ void InitPorts() PORTA = 0b00000100; //Pins RA7 to RA0, 1 for VIH(>1.5V) and 0 for VIL(<0.5V) - PORTC = 0b00001000; + PORTC = 0b00000101; APFCON0 = 0b10000100; // Enables RA0 to be Tx pin, RA1 to be Rx pin (for EUSART) //OSCCON = 0b10000010; - + } void InitTimers() @@ -213,7 +219,7 @@ void InitInterrupts() bit 7(GIE) = 1; Global Interrupt Enable bit bit 6(PEIE) = 1; Peripheral Interrupt Enable bit bit 5(TMR0IE) = 0; Timer0 Overflow Interrupt Enable bit - bit 4(INTE) = 0; INT External Interrupt Enable bit + bit 4(INTE) = 0; INT External Interrupt Enable bit bit 3(IOCIE) = 1; Interrupt-on-Change Enable bit bit 2(TMR0IF) = 0; Timer0 Overflow Interrupt FLag bit bit 1(INTF) = 0; INT External Interrupt Flag bit @@ -227,19 +233,18 @@ void IOC_Config() { IOCAP = 0x00; // IOC for rising edge disabled for port A IOCAN = 0b00000100; // IOC for falling edge enabled for A2 - IOCAF = 0x00; // clear IOC flags for port A + IOCAF = 0x00; // clear IOC flags for port A } void interrupt ISR() // function needs to execute in <100ms { - - - if (TMR2IF) + + if (TMR2IF) { - /* - counter++; + /* + counter++; if ((counter % 2) != 0) { PORTC |= BIT1HI; // 0b00000100 @@ -251,21 +256,21 @@ void interrupt ISR() // function needs to execute in <100ms counter = 0; } */ - TMR2IF = 0; // clears the TIMR2IF (timer 2 interrupt flag) } - + if (CCP1IF) // flag is in register PIR1<2> { - static unsigned int uLastEdge; + static unsigned int uLastEdge; char highByte; char lowByte; int CCPR1_Snapshot; captureTracker ++; //keeps track of how many captures have been done + //SightPin_C2(); // debugging highByte = CCPR1H; // CCPR1H captures value from TMR1H register lowByte = CCPR1L; // CCPR1L captures value from TMR1L register @@ -276,13 +281,9 @@ void interrupt ISR() // function needs to execute in <100ms uPeriod = CCPR1_Snapshot - uLastEdge; uLastEdge = CCPR1_Snapshot; // this variable should not be in scope next ISR - /*********************************************************************************************/ - // above is a method to capture the values from the TMR1H and TMR1L register and combine - // them into a 16 bit integer. This 16 bit integer gives the "time reading" when the falling - // edge occurred. - - if (uPeriod == 0) { uPeriod = 23; } // trick to get uPeriod to show up in MLBAB's Watches window + if (uPeriod == 0) { uPeriod = 23; } + //twentyPer = uPeriod; //maybe write 0 to the TMR1H and TMR1L bytes to ensure against rollover? //the datasheet says to stop the timer before writing to below registers @@ -294,16 +295,14 @@ void interrupt ISR() // function needs to execute in <100ms if (IOCIF) // check to see if button (RA2) was pushed { - - + //INTCON &= BIT3LO; + // turn on LED if ((IOCAF & BIT2HI) == BIT2HI) { - + //SightPin_C2(); buttonPush = 1; - INTCON &= BIT3LO; // turn off IOCIE - interrupt on change - tick++; if ((tick % 2) != 0) { @@ -316,56 +315,55 @@ void interrupt ISR() // function needs to execute in <100ms tick = 0; } - - IOCAF &= BIT2LO; // clear IOC Flag for port A2 - IOCIF = 0; - INTCON |= BIT3HI; //Re-enable IOCIE interrupt + IOCAF &= BIT2LO; + IOCIF = 0; + INTCON |= BIT3HI; } } - -} //pops previous address from the stack, restores registers, and sets GIE bit +} //pops previous address from the stack, restores registers, and sets GIE bit +//uint8_t myVar @0xD00; void MoistureCalc(void) { - - //set the value of the moisture, should be a number from 0 to 100 - //this will be a formula based on the characterization curve - /********************************************************************************/ - /**********this is where to put new algorithm for for moisture calc**************/ - /********************************************************************************/ - moisture = (15*uPeriod) - 2399; + //set the value of the moisture, should be a number from 0 to 100 + moisture = 25; //this will be a formula based on the characterization curve //this gives the next index for the arrays next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide //add the next moisture value and rate change to the arrays - moistureValues[next_index] = moisture; - moistureChangeRate[next_index] = moisture - previous_moisture; + moistureValues[next_index] = uPeriod; + //moistureChangeRate[next_index] = moisture - previous_moisture; //save the current moisture reading to calculate the rate change - previous_moisture = moisture; + //previous_moisture = moisture; } void SetLEDsForWatering(void) // must account for rate of watering. { - if (moisture > target_value) + /* + if (moisture < target_value) {PORTC &= BIT2LO; PORTC |= BIT0HI;} //Blue LEDs on, Yellow dim + else {PORTC |= BIT2HI; PORTC &= BIT0LO;} //Yellow LEDs on, Blue dim + */ + + //try to figure out target values using uPeriod + if (uPeriod > 15000) { - PORTC |= BIT0HI; // turn on lights indicating "water" PORTC &= BIT2LO; - } - else + PORTC |= BIT0HI; + } //Blue LEDs dim, Yellow on + else { - PORTC |= BIT2HI; // turn on lights indicating "stop watering" + PORTC |= BIT2HI; PORTC &= BIT0LO; + } //Yellow LEDs dim, Blue on - } - } @@ -413,16 +411,14 @@ void main () // Initializing PIC16LF1827 InitPorts(); InitTimers(); - InitComm(); + InitComm(); InitInterrupts(); - IOC_Config(); + IOC_Config(); + - while(1) { - //function to check flag, if true then send data via bluetooth to paired computer - if (buttonPush == 1) { @@ -435,22 +431,20 @@ void main () buttonPush = 0; captureTracker = 0; } - //turn sensor on - // pull low - turns off NPN BJT - which then turns on Ecco - + //PORTB &= BIT4LO; PORTC |= BIT4HI; //PC stuck in loop until first capture (capTrack is an even number) - while (captureTracker % 2 == 0){PORTC &= BIT3LO;}//RA3 dim // even and 0 % 2 = 0 - + while (captureTracker % 2 == 0){PORTC &= BIT3LO;}//RC3 bright // even and 0 % 2 = 0 + //PC stuck in another loop until second capture (capTrack is an odd number) - while (captureTracker % 2 == 1){PORTC |= BIT3HI;}//RA4 dim //odd % 2 = 1 + while (captureTracker % 2 == 1){PORTC |= BIT3HI;}//RC3 dim //odd % 2 = 1 //turn off sensor - //pull high - turns on NPN BJT - turns Ecco off - PORTC = BIT4LO; + //PORTB |= BIT4HI; //turn the sensor off for the duration of the sleep cycle + PORTC &= BIT4LO; //do calculation MoistureCalc(); @@ -459,10 +453,10 @@ void main () SetLEDsForWatering(); - //Put device to sleep and wait for the next time to take a measurment + //Put device to sleep and wait for the next time to take a measurment //the sleep time is set by the postscaler of the WDT - // DREAM_TIME is a #define and can be altered to alter how long mcu is asleep - for (y=0;y Date: Fri, 19 Sep 2014 14:49:57 -0700 Subject: [PATCH 21/23] Witnessing Value on Terminal Able to witness value on terminal, need to switch the logic for on / off lights, need to calibrate for wet / dry soil --- 1825_EccoPro_Run1.c | 99 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 20 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 54a9400..ed446c8 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -22,13 +22,13 @@ Date: 9/1/2014 #include #include "pic.h" #include "chip_select.h" +#include +#include +#include /***************** Configuration Macros ***************/ -//__CONFIG(FCMEN_OFF & IESO_OFF & FOSC_LP & WDTE_OFF & MCLRE_ON & PWRTE_OFF & BOREN_OFF -// & LVP_ON & WRT_OFF & CPD_OFF & CP_OFF); - // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. @@ -66,20 +66,31 @@ int tick = 1; int buttonPush = 0; //int total_values = 24; //set the total number of values to capture -int moistureValues[total_values] = 0x00; //array for moisture values -int moistureChangeRate[total_values] =0x00; //array for change in moisture values +int moistureValues[total_values] = {0x00}; //array for moisture values +int moistureChangeRate[total_values] = {0x00}; //array for change in moisture values +char buffer[20]; +char moisture[8]; +char printOut[8]; + + +char Tenthousandth; +char Thousandth; +char Hundredth; +char Tenth; +char One; static unsigned int uPeriod; static unsigned int rawInterval; -int waterCal = 19667; //where does this number come from? -int twentyPer = 19235; //where does this number come from? -int airCal = 18587; //where does this number come from? -int moisture = 0; //initialized to zero, maybe this should be unsigned +//int moisture = 0; //initialized to zero, maybe this should be unsigned int previous_moisture = 0; //initialized to zero int target_value = 20; //I set this arbitrarily to test the code int next_index; +char dummy; + + + /********* Function Prototypes ***************/ @@ -297,6 +308,7 @@ void interrupt ISR() // function needs to execute in <100ms { //INTCON &= BIT3LO; // turn on LED + if ((IOCAF & BIT2HI) == BIT2HI) { //SightPin_C2(); @@ -331,13 +343,13 @@ void MoistureCalc(void) { //set the value of the moisture, should be a number from 0 to 100 - moisture = 25; //this will be a formula based on the characterization curve + //moisture = 25; //this will be a formula based on the characterization curve //this gives the next index for the arrays - next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide + //next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide //add the next moisture value and rate change to the arrays - moistureValues[next_index] = uPeriod; + //moistureValues[next_index] = uPeriod; //moistureChangeRate[next_index] = moisture - previous_moisture; //save the current moisture reading to calculate the rate change @@ -347,13 +359,16 @@ void MoistureCalc(void) void SetLEDsForWatering(void) // must account for rate of watering. { +//<<<<<<< HEAD +//======= /* if (moisture < target_value) {PORTC &= BIT2LO; PORTC |= BIT0HI;} //Blue LEDs on, Yellow dim else {PORTC |= BIT2HI; PORTC &= BIT0LO;} //Yellow LEDs on, Blue dim */ //try to figure out target values using uPeriod - if (uPeriod > 15000) +//>>>>>>> 7afe8ea439cef22d9c217155754c265dd20f3c67 + if (uPeriod < 16000) { PORTC &= BIT2LO; PORTC |= BIT0HI; @@ -415,22 +430,66 @@ void main () InitInterrupts(); IOC_Config(); - - while(1) { + buttonPush = 1; if (buttonPush == 1) { - - for (int j = 0; j<(next_index + 1); j++) + /* + itoa(uPeriod,buffer,10); //10 means decimal + + Tenthousandth = buffer[0]; + Thousandth = buffer[1]; + Hundredth = buffer[2]; + Tenth = buffer[3]; + One = buffer[4]; + */ + moisture[4] = (uPeriod % 10); + moisture[3] = ((uPeriod & 100)/10); + moisture[2] = ((uPeriod % 1000)/100); + moisture[1] = ((uPeriod % 10000)/1000); + moisture[0] = ((uPeriod % 100000) / 10000); + + int q = moisture[0]; + int r = moisture[1]; + int s = moisture[2]; + int t = moisture[3]; + int u = moisture[4]; + + char One = (char)(((int)'0')+q); + char Two = (char)(((int)'0')+r); + char Three = (char)(((int)'0')+s); + char Four = (char)(((int)'0')+t); + char Five = (char)(((int)'0')+u); + + + + char nums[11] = {'a','b','c','d','e','f','g','h','i','j','l'}; + for (int i=0; i<2; i++) { - while (!TXIF); - TXREG = moistureValues[j]; + + while(!TXIF); + TXREG = One; + while(!TXIF); + TXREG = Two; + while(!TXIF); + TXREG = Three; + while(!TXIF); + TXREG = Four; + while(!TXIF); + TXREG = Five; + while(!TXIF); + TXREG = 0x20; + + } buttonPush = 0; captureTracker = 0; + //nums[10] = 0x00; } + + //turn sensor on //PORTB &= BIT4LO; @@ -455,7 +514,7 @@ void main () //Put device to sleep and wait for the next time to take a measurment //the sleep time is set by the postscaler of the WDT - for (y=0;y<4;y++) {SLEEP();} // will sleep x number of times + for (y=0;y<2;y++) {SLEEP();} // will sleep x number of times } From 4c08da96cb3e9979cf978e6e12075ad3149d607b Mon Sep 17 00:00:00 2001 From: humbleSeraph Date: Fri, 19 Sep 2014 18:50:11 -0700 Subject: [PATCH 22/23] Dry and Wet Soil detection, bluetooth streaming can detect wet and dry soil, streams number of ticks (moisture) via bluetooth --- 1825_EccoPro_Run1.c | 78 +++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 55 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index ed446c8..414f377 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -66,19 +66,12 @@ int tick = 1; int buttonPush = 0; //int total_values = 24; //set the total number of values to capture -int moistureValues[total_values] = {0x00}; //array for moisture values -int moistureChangeRate[total_values] = {0x00}; //array for change in moisture values +//int moistureValues[total_values] = {0x00}; //array for moisture values +//int moistureChangeRate[total_values] = {0x00}; //array for change in moisture values char buffer[20]; char moisture[8]; char printOut[8]; - -char Tenthousandth; -char Thousandth; -char Hundredth; -char Tenth; -char One; - static unsigned int uPeriod; static unsigned int rawInterval; @@ -141,7 +134,7 @@ void InitPorts() PORTC = 0b00000101; APFCON0 = 0b10000100; // Enables RA0 to be Tx pin, RA1 to be Rx pin (for EUSART) - //OSCCON = 0b10000010; + } @@ -168,7 +161,7 @@ void InitTimers() *******************************************/ CCP1CON = 0b00110100; //capture mode: every falling edge - //CCP1CON = 0b00000100; //least 4 bits sets capture mode + T2CON = 0b01111110; // Fosc / (4 instruct * 16 prescale * 16 postscale * 60 PR2) = 65 Hz /******************************************** @@ -304,6 +297,8 @@ void interrupt ISR() // function needs to execute in <100ms CCP1IF = 0; // clear the flag } + /**** tried to implement button push had some bugs, this is where to do it*****/ + /**** can't send data in interrupt, get wonky stuff ******/ if (IOCIF) // check to see if button (RA2) was pushed { //INTCON &= BIT3LO; @@ -336,24 +331,12 @@ void interrupt ISR() // function needs to execute in <100ms } -} //pops previous address from the stack, restores registers, and sets GIE bit -//uint8_t myVar @0xD00; +} void MoistureCalc(void) { - //set the value of the moisture, should be a number from 0 to 100 - //moisture = 25; //this will be a formula based on the characterization curve - - //this gives the next index for the arrays - //next_index = (captureTracker / 2) - 1; //can also use left shift ">>1" to divide - - //add the next moisture value and rate change to the arrays - //moistureValues[next_index] = uPeriod; - //moistureChangeRate[next_index] = moisture - previous_moisture; - - //save the current moisture reading to calculate the rate change - //previous_moisture = moisture; + // this is where the moisture calc goes } @@ -361,14 +344,9 @@ void SetLEDsForWatering(void) // must account for rate of watering. { //<<<<<<< HEAD //======= - /* - if (moisture < target_value) {PORTC &= BIT2LO; PORTC |= BIT0HI;} //Blue LEDs on, Yellow dim - else {PORTC |= BIT2HI; PORTC &= BIT0LO;} //Yellow LEDs on, Blue dim - */ //try to figure out target values using uPeriod -//>>>>>>> 7afe8ea439cef22d9c217155754c265dd20f3c67 - if (uPeriod < 16000) + if (uPeriod > 15000) { PORTC &= BIT2LO; PORTC |= BIT0HI; @@ -435,15 +413,7 @@ void main () buttonPush = 1; if (buttonPush == 1) { - /* - itoa(uPeriod,buffer,10); //10 means decimal - - Tenthousandth = buffer[0]; - Thousandth = buffer[1]; - Hundredth = buffer[2]; - Tenth = buffer[3]; - One = buffer[4]; - */ + moisture[4] = (uPeriod % 10); moisture[3] = ((uPeriod & 100)/10); moisture[2] = ((uPeriod % 1000)/100); @@ -456,28 +426,26 @@ void main () int t = moisture[3]; int u = moisture[4]; - char One = (char)(((int)'0')+q); - char Two = (char)(((int)'0')+r); - char Three = (char)(((int)'0')+s); - char Four = (char)(((int)'0')+t); - char Five = (char)(((int)'0')+u); - + char firstDigit = (char)(((int)'0')+q); + char secondDigit = (char)(((int)'0')+r); + char thirdDigit = (char)(((int)'0')+s); + char fourthDigit = (char)(((int)'0')+t); + char fifthDigit = (char)(((int)'0')+u); - - char nums[11] = {'a','b','c','d','e','f','g','h','i','j','l'}; + // show data twice for readability for (int i=0; i<2; i++) { while(!TXIF); - TXREG = One; + TXREG = firstDigit; while(!TXIF); - TXREG = Two; + TXREG = secondDigit; while(!TXIF); - TXREG = Three; + TXREG = thirdDigit; while(!TXIF); - TXREG = Four; + TXREG = fourthDigit; while(!TXIF); - TXREG = Five; + TXREG = fifthDigit; while(!TXIF); TXREG = 0x20; @@ -486,7 +454,7 @@ void main () buttonPush = 0; captureTracker = 0; - //nums[10] = 0x00; + } @@ -506,7 +474,7 @@ void main () PORTC &= BIT4LO; //do calculation - MoistureCalc(); + //MoistureCalc(); //turn on LEDs if need to water SetLEDsForWatering(); From aec2e802bd06c9a343e7e947670b9170a4a3b0a2 Mon Sep 17 00:00:00 2001 From: Osagie Igbeare Date: Wed, 29 Jul 2015 00:59:45 -0700 Subject: [PATCH 23/23] Ampere's And?? --- 1825_EccoPro_Run1.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1825_EccoPro_Run1.c b/1825_EccoPro_Run1.c index 414f377..f31de47 100644 --- a/1825_EccoPro_Run1.c +++ b/1825_EccoPro_Run1.c @@ -348,7 +348,7 @@ void SetLEDsForWatering(void) // must account for rate of watering. //try to figure out target values using uPeriod if (uPeriod > 15000) { - PORTC &= BIT2LO; + PORTC &= BIT2LO; // PORTC = PORTC & BIT2LO; PORTC |= BIT0HI; } //Blue LEDs dim, Yellow on else @@ -415,7 +415,7 @@ void main () { moisture[4] = (uPeriod % 10); - moisture[3] = ((uPeriod & 100)/10); + moisture[3] = ((uPeriod % 100)/10); moisture[2] = ((uPeriod % 1000)/100); moisture[1] = ((uPeriod % 10000)/1000); moisture[0] = ((uPeriod % 100000) / 10000);