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
- Committer:
- timmey9
- Date:
- 2015-01-31
- Revision:
- 45:d591d138cdeb
- Parent:
- 44:41c262caf898
- Child:
- 46:a015ebf4663b
File content as of revision 45:d591d138cdeb:
// Server code #include "mbed.h" #include "AngleEncoder.h" #include "adc.h" #include "pdb.h" #include "quadrature.h" // for debug purposes Serial pc(USBTX, USBRX); DigitalOut led_red(LED_RED); DigitalOut led_green(LED_GREEN); DigitalOut led_blue(LED_BLUE); //DigitalOut test1(PTB19); //DigitalOut test2(PTB18); AngleEncoder angle_encoder(PTD2, PTD3, PTD1, PTD0, 8, 0, 1000000); // mosi, miso, sclk, cs, bit_width, mode, hz extern int len; extern uint16_t sample_array0[]; extern uint16_t sample_array1[]; extern uint16_t angle_array[]; extern DigitalIn AMT20_A; // input for quadrature encoding from angle encoder extern DigitalIn AMT20_B; // input for quadrature encoding from angle encoder // Declaration of functions int rotary_count = 0; using namespace std; int main() { led_blue = 1; led_green = 1; led_red = 1; pc.baud(230400); pc.printf("Starting\r\n"); quad_init(); adc_init(); // always initialize adc before dma dma_init(); pdb_init(); pc.printf("\r\n\r\n\r\n"); while(1) { rotary_count++; if(rotary_count & 0x01) AMT20_A.mode(PullUp); else AMT20_A.mode(PullDown); if((rotary_count>>1) & 0x01) AMT20_B.mode(PullUp); else AMT20_B.mode(PullDown); if(pc.readable() > 0) { char temp = pc.getc(); switch(temp) { case 'G': case 'g': pc.printf("Quad Cnt: %i\r\n", quad_read()); break; case 'A': case 'a': adc_start(); for(int i = 0; i < 1500; i++) asm("nop"); adc_stop(); // then proceed to 's' to display the array case 'S': case 's': for(int i = 0; i < len; i++) pc.printf("%i: %f\t %f\t %i%i\r\n",i,sample_array0[i]*3.3/65535,sample_array1[i]*3.3/65535, (angle_array[i]>>1)&0x01, angle_array[i]&0x01); pc.printf("\r\n"); break; case 'D': case 'd': adc_single_sample(); break; case 'F': case 'f': for(int i = 0; i < len; i++) {sample_array0[i] = 0; sample_array1[i] = 0; angle_array[i] = 0;} pc.printf("Arrays cleared\r\n"); break; case 'R': case 'r': pc.printf("Quadrature: %i%i \r\n", (HW_GPIO_PDIR_RD(HW_PORTC)>>1)&0x01, HW_GPIO_PDIR_RD(HW_PORTC)&0x01); case 'B': case 'b': pdb_start(); break; case 'K': case 'k': pdb_stop(); break; } } } }