From 9b2514481dbe12675f945c9570c76e3920a38f63 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Fri, 24 Apr 2020 14:38:07 -0500 Subject: Finish EE2361 --- Lab6.X/circBuffer.c | 53 ++- Lab6.X/circBuffer.h | 38 +-- Lab6.X/dist/default/production/memoryfile.xml | 36 +-- Lab6.X/lab6_main.c | 195 ++++++----- Lab6.X/nbproject/Makefile-genesis.properties | 20 +- Lab6.X/nbproject/configurations.xml | 449 +++++++++++++------------- Lab6.X/nbproject/private/configurations.xml | 50 +-- 7 files changed, 414 insertions(+), 427 deletions(-) diff --git a/Lab6.X/circBuffer.c b/Lab6.X/circBuffer.c index d4d120f..6ce4ee0 100644 --- a/Lab6.X/circBuffer.c +++ b/Lab6.X/circBuffer.c @@ -1,28 +1,25 @@ -#include "xc.h" -#include "circBuffer.h" -#define SIZE 1024 - -volatile unsigned int buffer[SIZE]; -int buffSize = 0, write = 0, read = 0; -void initBuffer(){ - int i; - for (i=0; i SIZE) + buffSize = 0; +} +long getAvg(){ + int i, sum = 0; + for (i=0; i // include processor files - each processor file is guarded. - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ -void putVal(int newValue); // add a new value to the buffer -int getAvg(); // average all buffer vals -void initBuffer(); // set all buffer vals to zero - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif - +#ifndef CIRCBUFF_H +#define CIRCBUFF_H + +#include // include processor files - each processor file is guarded. + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +void putVal(long newValue); // add a new value to the buffer +long getAvg(); // average all buffer vals +void initBuffer(); // set all buffer vals to zero + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/Lab6.X/dist/default/production/memoryfile.xml b/Lab6.X/dist/default/production/memoryfile.xml index e8d8e00..0c0496e 100644 --- a/Lab6.X/dist/default/production/memoryfile.xml +++ b/Lab6.X/dist/default/production/memoryfile.xml @@ -1,18 +1,18 @@ - - - - - - bytes - 8192 - 2176 - 6016 - - - bytes - 65274 - 8088 - 57186 - - - + + + + + + bytes + 8192 + 4216 + 3976 + + + bytes + 65274 + 8025 + 57249 + + + diff --git a/Lab6.X/lab6_main.c b/Lab6.X/lab6_main.c index e9258c4..7d46cd0 100644 --- a/Lab6.X/lab6_main.c +++ b/Lab6.X/lab6_main.c @@ -1,103 +1,92 @@ -#include "xc.h" -#include "../Lab5.X/lab5_lcd.h" -#include "circBuffer.h" -#include - -#pragma config ICS = PGx1 // Comm Channel Select (Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1) -#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled) -#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed) -#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled) -#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled) - -// CW2: FLASH CONFIGURATION WORD 2 (see PIC24 Family Reference Manual 24.1) -#pragma config I2C1SEL = PRI // I2C1 Pin Location Select (Use default SCL1/SDA1 pins) -#pragma config IOL1WAY = OFF // IOLOCK Protection (IOLOCK may be changed via unlocking seq) -#pragma config OSCIOFNC = ON // Primary Oscillator I/O Function (CLKO/RC15 functions as I/O pin) -#pragma config FCKSM = CSECME // Clock Switching and Monitor (Clock switching is enabled, - // Fail-Safe Clock Monitor is enabled) -#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL)) - -void setup(void) { - CLKDIVbits.RCDIV = 0; - AD1PCFG = 0x9fff; //all digital inputs and outputs - initBuffer(); - lcd_init(); - lcd_setCursor(0,0); - - // -- I2C STUFF -- - I2C2BRG = 0x9D; - I2C2CONbits.I2CEN = 1; - _I2CSIDL = 0; - IFS3bits.MI2C2IF=0; - - // -- ADC STUFF -- - AD1CON1 = 0; // set all control to 0. - AD1CON1bits.SSRC = 0b010; //Rollover to conversion - AD1CON1bits.ASAM = 1; // auto-sample - AD1CON1bits.FORM = 0b00; - AD1CON2 = 0; - AD1CON2bits.CSCNA = 0; // no scan - AD1CON2bits.SMPI = 0b0; // every conversion - AD1CON2bits.BUFM = 0; // two 8-word buffers - AD1CON3bits.ADCS = 0b1; - AD1CON3bits.ADRC = 0; - AD1CON3bits.SAMC = 0b1; - AD1CON1bits.ADON = 1; // ton - AD1CHS = 0; - AD1CHSbits.CH0NB = 0; - AD1CHSbits.CH0SB = 0; - AD1CHSbits.CH0NA = 0; - AD1CHSbits.CH0SA = 0; - - // -- TIMER 2 STUFF -- - T2CON = 0; - TMR2 = 0; - T2CONbits.TCKPS = 0b10; - PR2 = 25000; - T2CONbits.TON = 1; - - // -- TIMER 3 STUFF -- - T3CON = 0; - TMR3 = 0; - T3CONbits.TCKPS = 0b10; - PR3 = 1562; - T3CONbits.TON = 1; - - // -- INTERRUPT ENABLES -- - IEC0bits.AD1IE = 1; - IFS0bits.AD1IF = 0; - //ADC Interrupt (Enabled) - IEC0bits.T2IE = 1; - IFS0bits.T2IF = 0; - // T2 Interrupt (Enabled) -} - -volatile unsigned int *ADCpointer = &ADC1BUF0, ADCvalue = 0; -void __attribute__((__interrupt__, __auto_psv__)) _ADC1Interrupt(void) { - IFS0bits.AD1IF = 0; - - -} -volatile unsigned char flag = 0; -void __attribute__((__interrupt__, __auto_psv__)) _T2Interrupt(void) { - //Allow writing to LCD - _T2IF = 0; - TMR2 = 0; - flag = 1; -} - -int main(void) { - setup(); - while (1) { - char adStr[20]; - unsigned long adValue; - if (flag) { - flag = 0; - lcd_setCursor(0,0); - adValue = getAvg(); - sprintf(adStr, "%6.4f V", (3.3/1024)*adValue); - lcd_printStr(adStr); - } - } - return -1; -} +#include "xc.h" +#include +#include "../Lab5.X/lab5_lcd.h" + + +#pragma config ICS = PGx1 // Comm Channel Select (Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1) +#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled) +#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed) +#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled) +#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled) + +// CW2: FLASH CONFIGURATION WORD 2 (see PIC24 Family Reference Manual 24.1) +#pragma config I2C1SEL = PRI // I2C1 Pin Location Select (Use default SCL1/SDA1 pins) +#pragma config IOL1WAY = OFF // IOLOCK Protection (IOLOCK may be changed via unlocking seq) +#pragma config OSCIOFNC = ON // Primary Oscillator I/O Function (CLKO/RC15 functions as I/O pin) +#pragma config FCKSM = CSECME // Clock Switching and Monitor (Clock switching is enabled, + // Fail-Safe Clock Monitor is enabled) +#pragma config FNOSC = FRCPLL // Oscillator Select (Fast RC Oscillator with PLL module (FRCPLL)) + +void setup(void) { + CLKDIVbits.RCDIV = 0; + AD1PCFG = 0x9FFE; //AN1 analog + TRISA |= 1;; + + // -- I2C STUFF -- + I2C2BRG = 0x9D; + I2C2CONbits.I2CEN = 1; + _I2CSIDL = 0; + IFS3bits.MI2C2IF=0; + lcd_init(); + + // -- ADC STUFF -- + AD1CON1 = 0; // set all control to 0. + AD1CON1bits.SSRC = 0b010; //Rollover to conversion + AD1CON1bits.ASAM = 1; // auto-sample + AD1CON1bits.FORM = 0b00; + AD1CON2 = 0; + AD1CON2bits.CSCNA = 0; // no scan + AD1CON2bits.SMPI = 0b0; // every conversion + AD1CON2bits.BUFM = 0; // two 8-word buffers + AD1CON3bits.ADCS = 0b1; + AD1CON3bits.ADRC = 0; + AD1CON3bits.SAMC = 0b1; + AD1CON1bits.ADON = 1; // ton + AD1CHS = 0; + AD1CHSbits.CH0NB = 0; + AD1CHSbits.CH0SB = 0; + AD1CHSbits.CH0NA = 0; + AD1CHSbits.CH0SA = 0; + + // -- TIMER 2 STUFF -- + T2CON = 0; + TMR2 = 0; + T2CONbits.TCKPS = 0b10; + PR2 = 25000; + T2CONbits.TON = 1; + + // -- TIMER 3 STUFF -- + T3CON = 0; + TMR3 = 0; + T3CONbits.TCKPS = 0b10; + PR3 = 1562; + T3CONbits.TON = 1; + + // -- INTERRUPT ENABLES -- + IEC0bits.AD1IE = 1; + IFS0bits.AD1IF = 0; + //ADC Interrupt (Enabled) + IEC0bits.T2IE = 1; + IFS0bits.T2IF = 0; + // T2 Interrupt (Enabled) +} + +void __attribute__((__interrupt__, __auto_psv__)) _ADC1Interrupt(void) { + IFS0bits.AD1IF = 0; + //This interrupt only serves to allow the ADC to work as intended. + +} +unsigned char flag = 0; +void __attribute__((__interrupt__, __auto_psv__)) _T2Interrupt(void) { + _T2IF = 0; TMR2 = 0; + char adStr[20]; + lcd_setCursor(0,0); + sprintf(adStr, "%6.4f V", (3.3/1024)*ADC1BUF0); + lcd_printStr(adStr); +} + +int main(void) { + setup(); + while (1); + return -1; +} diff --git a/Lab6.X/nbproject/Makefile-genesis.properties b/Lab6.X/nbproject/Makefile-genesis.properties index d6d71c3..f6d3f87 100644 --- a/Lab6.X/nbproject/Makefile-genesis.properties +++ b/Lab6.X/nbproject/Makefile-genesis.properties @@ -1,10 +1,10 @@ -# -#Fri Apr 17 20:22:52 CDT 2020 -default.Pack.dfplocation=C\:\\Program Files (x86)\\Microchip\\MPLABX\\v5.35\\packs\\Microchip\\PIC24F-GA-GB_DFP\\1.2.101 -default.com-microchip-mplab-nbide-toolchainXC16-XC16LanguageToolchain.md5=859fc649e7017fd01769e2187e1537a7 -default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc16\\v1.50\\bin -configurations-xml=adb813cd4ce7c3e3b7bbe8664d6b0b98 -com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=5db0f4d6bbe0ec2a1f1096ccfb9d7ad3 -default.languagetoolchain.version=1.50 -host.platform=windows -conf.ids=default +# +#Fri Apr 24 14:35:39 CDT 2020 +default.Pack.dfplocation=C\:\\Program Files (x86)\\Microchip\\MPLABX\\v5.35\\packs\\Microchip\\PIC24F-GA-GB_DFP\\1.2.101 +default.com-microchip-mplab-nbide-toolchainXC16-XC16LanguageToolchain.md5=859fc649e7017fd01769e2187e1537a7 +default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc16\\v1.50\\bin +configurations-xml=e2a041a657844a3c50448a1abf14139b +com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=5db0f4d6bbe0ec2a1f1096ccfb9d7ad3 +default.languagetoolchain.version=1.50 +host.platform=windows +conf.ids=default diff --git a/Lab6.X/nbproject/configurations.xml b/Lab6.X/nbproject/configurations.xml index 5c9fd0e..89e7382 100644 --- a/Lab6.X/nbproject/configurations.xml +++ b/Lab6.X/nbproject/configurations.xml @@ -1,224 +1,225 @@ - - - - - circBuffer.h - - - - - lab6_main.c - circBuffer.c - - - Makefile - - - Makefile - - - - localhost - PIC24FJ64GA002 - - - PK3OBPlatformTool - XC16 - 1.50 - 3 - - - - - - - - ../Lab5.X/lab5_lcd.c - ../Lab5.X/lab5_lcd.h - - - - - - false - false - - - - - - - false - - false - - false - false - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + circBuffer.h + + + + + lab6_main.c + circBuffer.c + + + Makefile + + + Makefile + + + + localhost + PIC24FJ64GA002 + + + PK3OBPlatformTool + XC16 + 1.50 + 3 + + + + + + + + ../Lab5.X/lab5_lcd.c + ../Lab5.X/lab5_lcd.h + + + + + + false + false + + + + + + + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lab6.X/nbproject/private/configurations.xml b/Lab6.X/nbproject/private/configurations.xml index 099de7b..dbaf381 100644 --- a/Lab6.X/nbproject/private/configurations.xml +++ b/Lab6.X/nbproject/private/configurations.xml @@ -1,25 +1,25 @@ - - - Makefile - 0 - - - :=MPLABComm-USB-Microchip:=<vid>04D8:=<pid>8108:=<rev>0002:=<man>Digilent:=<prod>chipKitProgrammer:=<sn>DA63CA1:=<drv>x:=<xpt>h:=end - C:\Program Files\Microchip\xc16\v1.50\bin - - place holder 1 - place holder 2 - - - - - true - 0 - 0 - 0 - - - - - - + + + Makefile + 0 + + + :=MPLABComm-USB-Microchip:=<vid>04D8:=<pid>8108:=<rev>0002:=<man>Digilent:=<prod>chipKitProgrammer:=<sn>DA63CA1:=<drv>x:=<xpt>h:=end + C:\Program Files\Microchip\xc16\v1.50\bin + + place holder 1 + place holder 2 + + + + + true + 0 + 0 + 0 + + + + + + -- cgit v1.2.3