Scans through the D/A converter values, and copies a set of A/D converter readings to a file on USB local filesystem. Connect pin 18 to pin 17.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Mischa
Date:
Fri Dec 10 05:56:45 2010 +0000
Parent:
0:4414657a2618
Commit message:
Now includes a matlab script to show some of the results (overview.m, included as overview.cpp).

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
overview.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4414657a2618 -r d9d6cf136120 main.cpp
--- a/main.cpp	Tue Dec 07 05:31:04 2010 +0000
+++ b/main.cpp	Fri Dec 10 05:56:45 2010 +0000
@@ -11,15 +11,15 @@
 int i;
 int n;
 unsigned short x[N];
-short trim = 3; // ADC trim; appears this is added to the ADC readings (i.e, -8 gives results in too low readings, 0 gives about correct readings, +3 gives really correct readings for my system, and +7 gives too high readings.) 
+//short trim = 3; // ADC trim; appears this is added to the ADC readings (i.e, -8 gives results in too low readings, 0 gives about correct readings, +3 gives really correct readings for my system, and +7 gives too high readings.) 
 
 int main() {
     FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
-    LPC_ADC->ADTRM&=~0x00F0;  //zero the ADC trim bits
-    LPC_ADC->ADTRM|=(trim<<4) & 0x00F0;   //set the trim
-    LPC_SC->PCONP &= ~(1<<30);
-    LPC_SC->PCONP &= ~(1<<10);    
-    LPC_SC->PCONP &= ~(1<<27);    
+    //LPC_ADC->ADTRM&=~0x00F0;  //zero the ADC trim bits
+    //LPC_ADC->ADTRM|=(trim<<4) & 0x00F0;   //set the trim
+    //LPC_SC->PCONP &= ~(1<<30);  //optionally power down various parts of the lpc1768
+    //LPC_SC->PCONP &= ~(1<<10);    
+    //LPC_SC->PCONP &= ~(1<<27);    
     for (i=0;i<1024;i++) {
         aout.write_u16(i<<6);
         wait(0.001);
diff -r 4414657a2618 -r d9d6cf136120 overview.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/overview.cpp	Fri Dec 10 05:56:45 2010 +0000
@@ -0,0 +1,44 @@
+% matlab code to plot results (multiple files):
+
+fs={'OUT.TXT'
+    'OUTPSU.TXT'
+    'OUTUSBtiedgnd.TXT'
+    'OUTPSUtiedgnd.TXT'
+    'OUTUSBlongwait.TXT'
+    'OUTPSUlongwait.TXT'
+    'OUTUSBtiedgndlongwait.TXT'
+    'OUTPSUtiedgndlongwait.TXT'};
+clear d
+for i=1:numel(fs),
+  fh=fopen(fs{i},'r');
+  d(:,:,i)=fix(fread(fh,[100,1024],'uint16')/16);
+  fclose(fh);
+end
+
+%all the measurements as dots:
+figure
+m=0:1023;
+m=repmat(m*4,[size(d,1),1,size(d,3)]);
+c='rgbmrgbm';
+for i=5:8,
+  plot(m(:,:,i),d(:,:,i),[c(i) '.']); hold on
+end
+axis tight
+
+%statistics:
+d=reshape(d,100*1024,8);
+m=reshape(m,100*1024,8);
+m=m+median(d(:)-m(:));
+top=(d>4096-6 & m<4096-100);
+bottom=(d<6 & m>100);
+above=(d>m+100 & d<=4096-6);
+below=(d<m-100 & d>=6);
+bar(0:7,[sum(bottom); sum(below); sum(above); sum(top)]','stacked')
+
+figure
+plot(m,d,'k.'); hold on
+plot(m(top),d(top),'r.'); hold on
+plot(m(above),d(above),'y.'); hold on
+plot(m(below),d(below),'c.'); hold on
+plot(m(bottom),d(bottom),'b.'); hold on
+axis tight