Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Impedance_Fast_Circuitry by
main.cpp@52:5a40cc58c4c2, 2015-01-31 (annotated)
- Committer:
- timmey9
- Date:
- Sat Jan 31 20:56:04 2015 +0000
- Revision:
- 52:5a40cc58c4c2
- Parent:
- 51:43143a3fc2d7
- Child:
- 53:83a90a47c1fd
Made minor cosmetic and comment changes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:bb128f0e952f | 1 | #include "mbed.h" |
timmey9 | 22:523e316cbe70 | 2 | |
timmey9 | 52:5a40cc58c4c2 | 3 | // Sampling |
timmey9 | 52:5a40cc58c4c2 | 4 | #include "Sample/adc.h" |
timmey9 | 52:5a40cc58c4c2 | 5 | #include "Sample/pdb.h" |
timmey9 | 52:5a40cc58c4c2 | 6 | #include "Sample/quad.h" |
timmey9 | 52:5a40cc58c4c2 | 7 | |
timmey9 | 22:523e316cbe70 | 8 | #include "AngleEncoder.h" |
timmey9 | 22:523e316cbe70 | 9 | |
timmey9 | 22:523e316cbe70 | 10 | // for debug purposes |
timmey9 | 18:b17ddeeb1c09 | 11 | Serial pc(USBTX, USBRX); |
timmey9 | 18:b17ddeeb1c09 | 12 | DigitalOut led_red(LED_RED); |
timmey9 | 18:b17ddeeb1c09 | 13 | DigitalOut led_green(LED_GREEN); |
timmey9 | 18:b17ddeeb1c09 | 14 | DigitalOut led_blue(LED_BLUE); |
timmey9 | 51:43143a3fc2d7 | 15 | DigitalOut quadA(PTC17); |
timmey9 | 51:43143a3fc2d7 | 16 | DigitalOut quadB(PTC16); |
timmey9 | 18:b17ddeeb1c09 | 17 | |
timmey9 | 22:523e316cbe70 | 18 | AngleEncoder angle_encoder(PTD2, PTD3, PTD1, PTD0, 8, 0, 1000000); // mosi, miso, sclk, cs, bit_width, mode, hz |
timmey9 | 51:43143a3fc2d7 | 19 | |
timmey9 | 52:5a40cc58c4c2 | 20 | // defined in dma.cpp |
timmey9 | 45:d591d138cdeb | 21 | extern int len; |
timmey9 | 45:d591d138cdeb | 22 | extern uint16_t sample_array0[]; |
timmey9 | 45:d591d138cdeb | 23 | extern uint16_t sample_array1[]; |
timmey9 | 45:d591d138cdeb | 24 | extern uint16_t angle_array[]; |
timmey9 | 41:3e0623d81b9a | 25 | |
timmey9 | 22:523e316cbe70 | 26 | using namespace std; |
timmey9 | 17:2f978f823020 | 27 | |
emilmont | 7:65188f4a8c25 | 28 | int main() { |
timmey9 | 22:523e316cbe70 | 29 | led_blue = 1; |
timmey9 | 35:df40c4566826 | 30 | led_green = 1; |
timmey9 | 18:b17ddeeb1c09 | 31 | led_red = 1; |
timmey9 | 47:54fafe151669 | 32 | quadA = 0; |
timmey9 | 47:54fafe151669 | 33 | quadB = 0; |
timmey9 | 34:44cc9b76a507 | 34 | |
timmey9 | 18:b17ddeeb1c09 | 35 | pc.baud(230400); |
timmey9 | 34:44cc9b76a507 | 36 | pc.printf("Starting\r\n"); |
timmey9 | 27:8c2b30c855d1 | 37 | |
timmey9 | 51:43143a3fc2d7 | 38 | quad_init(); // initialize FTM2 to quadrature decoder |
timmey9 | 45:d591d138cdeb | 39 | adc_init(); // always initialize adc before dma |
timmey9 | 51:43143a3fc2d7 | 40 | dma_init(); // initializes DMAs |
timmey9 | 51:43143a3fc2d7 | 41 | pdb_init(); // initialize PDB0 as the timer for ADCs and DMA2 |
timmey9 | 45:d591d138cdeb | 42 | |
timmey9 | 46:a015ebf4663b | 43 | led_green = 1; |
timmey9 | 38:ec3b16c130d7 | 44 | |
timmey9 | 40:bd6d8c35e822 | 45 | pc.printf("\r\n\r\n\r\n"); |
timmey9 | 37:8bdc71f3e874 | 46 | |
timmey9 | 34:44cc9b76a507 | 47 | while(1) { |
timmey9 | 47:54fafe151669 | 48 | // creates signals for the quad decoder to read for testing |
timmey9 | 47:54fafe151669 | 49 | quadA = !quadA; |
timmey9 | 47:54fafe151669 | 50 | for(int i = 0; i < 65535; i++) asm("nop"); |
timmey9 | 47:54fafe151669 | 51 | quadB = !quadB; |
timmey9 | 47:54fafe151669 | 52 | |
timmey9 | 34:44cc9b76a507 | 53 | if(pc.readable() > 0) { |
timmey9 | 34:44cc9b76a507 | 54 | char temp = pc.getc(); |
timmey9 | 34:44cc9b76a507 | 55 | |
timmey9 | 34:44cc9b76a507 | 56 | switch(temp) { |
timmey9 | 45:d591d138cdeb | 57 | case 'G': |
timmey9 | 45:d591d138cdeb | 58 | case 'g': |
timmey9 | 45:d591d138cdeb | 59 | pc.printf("Quad Cnt: %i\r\n", quad_read()); |
timmey9 | 45:d591d138cdeb | 60 | break; |
timmey9 | 50:33524a27e08c | 61 | case 'F': // clear the samples |
timmey9 | 50:33524a27e08c | 62 | case 'f': |
timmey9 | 50:33524a27e08c | 63 | for(int i = 0; i < len; i++) {sample_array0[i] = 0; sample_array1[i] = 0; angle_array[i] = 0;} |
timmey9 | 50:33524a27e08c | 64 | pc.printf("Arrays cleared\r\n"); |
timmey9 | 50:33524a27e08c | 65 | // then display the samples |
timmey9 | 50:33524a27e08c | 66 | case 'S': // display what's been sampled |
timmey9 | 42:52a92a8d2cc7 | 67 | case 's': |
timmey9 | 46:a015ebf4663b | 68 | for(int i = 0; i < len; i++) pc.printf("%i: %f\t %f\t %i\r\n",i,sample_array0[i]*3.3/65535,sample_array1[i]*3.3/65535, angle_array[i]); |
timmey9 | 42:52a92a8d2cc7 | 69 | pc.printf("\r\n"); |
timmey9 | 42:52a92a8d2cc7 | 70 | break; |
timmey9 | 50:33524a27e08c | 71 | |
timmey9 | 50:33524a27e08c | 72 | |
timmey9 | 47:54fafe151669 | 73 | // Programmable Delay Block debug |
timmey9 | 45:d591d138cdeb | 74 | case 'B': |
timmey9 | 45:d591d138cdeb | 75 | case 'b': |
timmey9 | 50:33524a27e08c | 76 | pc.printf("Started PCB...samples being taken\r\n"); |
timmey9 | 45:d591d138cdeb | 77 | pdb_start(); |
timmey9 | 45:d591d138cdeb | 78 | break; |
timmey9 | 45:d591d138cdeb | 79 | case 'K': |
timmey9 | 45:d591d138cdeb | 80 | case 'k': |
timmey9 | 50:33524a27e08c | 81 | pc.printf("Stopped PCB\r\n"); |
timmey9 | 45:d591d138cdeb | 82 | pdb_stop(); |
timmey9 | 45:d591d138cdeb | 83 | break; |
timmey9 | 47:54fafe151669 | 84 | case 'V': |
timmey9 | 47:54fafe151669 | 85 | case 'v': |
timmey9 | 47:54fafe151669 | 86 | pc.printf("PDB: %i\r\n",PDB0_CNT); |
timmey9 | 47:54fafe151669 | 87 | break; |
timmey9 | 34:44cc9b76a507 | 88 | } |
timmey9 | 34:44cc9b76a507 | 89 | } |
timmey9 | 17:2f978f823020 | 90 | } |
timmey9 | 42:52a92a8d2cc7 | 91 | } |