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.
main.cpp@1:d9d6cf136120, 2010-12-10 (annotated)
- Committer:
- Mischa
- Date:
- Fri Dec 10 05:56:45 2010 +0000
- Revision:
- 1:d9d6cf136120
- Parent:
- 0:4414657a2618
Now includes a matlab script to show some of the results (overview.m, included as overview.cpp).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mischa | 0:4414657a2618 | 1 | #include "mbed.h" |
Mischa | 0:4414657a2618 | 2 | |
Mischa | 0:4414657a2618 | 3 | // Scans through the D/A converter values, and copies a set of A/D converter values to file on USB local filesystem. |
Mischa | 0:4414657a2618 | 4 | // Connect pin 18 to pin 17. |
Mischa | 0:4414657a2618 | 5 | |
Mischa | 0:4414657a2618 | 6 | AnalogOut aout(p18); |
Mischa | 0:4414657a2618 | 7 | AnalogIn ain(p17); |
Mischa | 0:4414657a2618 | 8 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
Mischa | 0:4414657a2618 | 9 | |
Mischa | 0:4414657a2618 | 10 | const int N = 100; |
Mischa | 0:4414657a2618 | 11 | int i; |
Mischa | 0:4414657a2618 | 12 | int n; |
Mischa | 0:4414657a2618 | 13 | unsigned short x[N]; |
Mischa | 1:d9d6cf136120 | 14 | //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.) |
Mischa | 0:4414657a2618 | 15 | |
Mischa | 0:4414657a2618 | 16 | int main() { |
Mischa | 0:4414657a2618 | 17 | FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing |
Mischa | 1:d9d6cf136120 | 18 | //LPC_ADC->ADTRM&=~0x00F0; //zero the ADC trim bits |
Mischa | 1:d9d6cf136120 | 19 | //LPC_ADC->ADTRM|=(trim<<4) & 0x00F0; //set the trim |
Mischa | 1:d9d6cf136120 | 20 | //LPC_SC->PCONP &= ~(1<<30); //optionally power down various parts of the lpc1768 |
Mischa | 1:d9d6cf136120 | 21 | //LPC_SC->PCONP &= ~(1<<10); |
Mischa | 1:d9d6cf136120 | 22 | //LPC_SC->PCONP &= ~(1<<27); |
Mischa | 0:4414657a2618 | 23 | for (i=0;i<1024;i++) { |
Mischa | 0:4414657a2618 | 24 | aout.write_u16(i<<6); |
Mischa | 0:4414657a2618 | 25 | wait(0.001); |
Mischa | 0:4414657a2618 | 26 | for (n=0;n<N;n++) { |
Mischa | 0:4414657a2618 | 27 | x[n]=ain.read_u16(); |
Mischa | 0:4414657a2618 | 28 | } |
Mischa | 0:4414657a2618 | 29 | fwrite(x,sizeof(x[0]),sizeof(x)/sizeof(x[0]),fp); |
Mischa | 0:4414657a2618 | 30 | } |
Mischa | 0:4414657a2618 | 31 | fclose(fp); |
Mischa | 0:4414657a2618 | 32 | } |