diff options
author | Matt Strapp <strap012@umn.edu> | 2021-04-04 18:01:11 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2021-04-04 18:01:22 -0500 |
commit | b94f1c42df60cc0b9f9df3331745808f1f42b1d7 (patch) | |
tree | cfdf469147eb60007ccdc32b9029c0d9c865eefe | |
parent | Figure out how to space things (diff) | |
download | ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.tar ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.tar.gz ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.tar.bz2 ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.tar.lz ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.tar.xz ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.tar.zst ee3102-b94f1c42df60cc0b9f9df3331745808f1f42b1d7.zip |
Add newest contributions to GitHub
Diffstat (limited to '')
-rw-r--r-- | PICCode.X/bufferlib.c | 8 | ||||
-rw-r--r-- | PICCode.X/bufferlib.h | 2 | ||||
-rw-r--r-- | PICCode.X/main.c | 15 | ||||
-rw-r--r-- | PICCode.X/nbproject/private/private.xml | 6 |
4 files changed, 20 insertions, 11 deletions
diff --git a/PICCode.X/bufferlib.c b/PICCode.X/bufferlib.c index 4768c95..e9816a8 100644 --- a/PICCode.X/bufferlib.c +++ b/PICCode.X/bufferlib.c @@ -3,10 +3,10 @@ #define BUFFERSIZE 32 volatile int write = 0, numE = 0; -volatile unsigned int buffer[BUFFERSIZE]; +volatile unsigned int buffer[BUFFERSIZE]; // Basic circular buffer. Prime for buffer overflows, probably. - void putVal(int newValue) { // add a new value to the buffer - buffer[write++] = newValue; + void putVal(int Vo, int ref) { // add a new value to the buffer + buffer[write++] = ref - Vo; // This is backwards because reasons write %= BUFFERSIZE; if (numE < BUFFERSIZE) { @@ -27,7 +27,7 @@ volatile unsigned int buffer[BUFFERSIZE]; return(avg); } - void initBuffer() { // set all buffer values to zero + void initBuffer() { // set all buffer values to zero, likely also prime for a buffer overflow int i; for(i = 0; i < BUFFERSIZE; i++) { buffer[i] = 0; diff --git a/PICCode.X/bufferlib.h b/PICCode.X/bufferlib.h index a218b8b..5619a47 100644 --- a/PICCode.X/bufferlib.h +++ b/PICCode.X/bufferlib.h @@ -5,7 +5,7 @@ extern "C" { #endif - void putVal(int newValue); + void putVal(int Vo, int ref); int getAvg(); void initBuffer(); diff --git a/PICCode.X/main.c b/PICCode.X/main.c index d9a7126..88d3f35 100644 --- a/PICCode.X/main.c +++ b/PICCode.X/main.c @@ -25,7 +25,7 @@ volatile int adValue; void __attribute__((__interrupt__,__auto_psv__)) _ADC1Interrupt(void) { _AD1IF = 0; - putVal(ADC1BUF0); //Grab latest sampled value after conversion and place it in buffer + putVal(ADC1BUF0, ADC1BUF1); //Grab latest sampled value after conversion and place it in buffer } void __attribute__((__interrupt__,__auto_psv__)) _T2Interrupt(void) { @@ -40,7 +40,7 @@ void setup (void) { T2CON = 0; //Set up timer 2 to have a delay of 100ms PR2 = 24999; //and enable the interrupt for timer 2 - T2CONbits.TCKPS = 2; + T2CONbits.TCKPS = 3; T2CONbits.TON = 1; _T2IE = 1; _T2IF = 0; @@ -56,13 +56,15 @@ void setup (void) { T3CONbits.TON = 1; AD1CON1 = 0, AD1CON2 = 0, AD1CON3 = 0; + AD1CSSL = 0x0003; //Set ADC1 to obtain both RA0 and RA1 _AD1IE = 1; _AD1IF = 0; AD1CON1bits.ASAM = 1; //Turn on automatic sampling AD1CON1bits.SSRC = 2; //Use timer 3 to end sampling time AD1CON2bits.VCFG = 0; //Configure reference voltages to be Vdd and GND - AD1CON2bits.SMPI = 0; //Interrupt after completion of every conversion + AD1CON2bits.SMPI = 1; //Interrupt after completion of every 2nd conversion + AD1CON2bits.CSCNA = 1; //Enable sequential scanning on bits specified in AD1CSSL register above AD1CON3bits.SAMC = 1; //Set Tsmp = 1*Tad AD1CON3bits.ADCS = 1; //Set Tad = 2*Tcy @@ -73,7 +75,7 @@ void setup (void) { double VtoI(float value) { //TODO: Verify this. I've done a few and the error seems to be no more than 0.5 mA //MAKE SURE THE ERROR IS NEVER >=1.0mA (as per project description) - return (double) ((value + 0.196) / 0.0335); + return (double) ((value + 0.204) / 0.032); } int main(void) { @@ -85,7 +87,10 @@ int main(void) { while(1) { lcd_setCursor(0,0); //Setting the cursor to the top left corner of the display - sprintf(adStr,"%6.4f A",VtoI((3.3/1024)*adValue)); //Formatting the string that will be written + int curr =VtoI((3.3/1024)*adValue); + if (curr < 0) + curr =0; + sprintf(adStr,"%6.4fmA",curr); //Formatting the string that will be written lcd_printStr(adStr); //Writing the entire string to the display } diff --git a/PICCode.X/nbproject/private/private.xml b/PICCode.X/nbproject/private/private.xml index 23ebd23..cc2ea97 100644 --- a/PICCode.X/nbproject/private/private.xml +++ b/PICCode.X/nbproject/private/private.xml @@ -3,7 +3,11 @@ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> <group> - <file>file:/C:/Users/Public/Documents/Altium/Projects/EE3102Testing.X/spies046_lab6_main_v001.c</file> + <file>file:/C:/Users/Public/Documents/Altium/Projects/PICCode.X/bufferlib.c</file> + <file>file:/C:/Users/Public/Documents/Altium/Projects/PICCode.X/lcd.c</file> + <file>file:/C:/Users/Public/Documents/Altium/Projects/PICCode.X/main.c</file> + <file>file:/C:/Users/Public/Documents/Altium/Projects/PICCode.X/lcd.h</file> + <file>file:/C:/Users/Public/Documents/Altium/Projects/PICCode.X/bufferlib.h</file> </group> </open-files> </project-private> |