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.
Diff: main.cpp
- Revision:
- 7:de5b1bc07eb5
- Parent:
- 6:fa9df9f03bfa
- Child:
- 8:213824bed8d5
--- a/main.cpp Fri Jun 13 13:55:50 2014 +0000 +++ b/main.cpp Mon Jun 23 14:34:21 2014 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" #include "USBSerial.h" -#define VERSION "13_06_2014" -#define SPEED 1000 //µs +#define VERSION "23_06_2014" +#define SPEED 5000//1000 //µs #define BLOCUSB 64 //64 #define NBCHAN 2 #define NBSAMPLE BLOCUSB/NBCHAN // 2 samples 16bit @@ -17,9 +17,9 @@ #endif #if defined( __KL25) USBSerial pc; -DigitalOut led2(LED_GREEN); -DigitalOut led3(LED_RED); -DigitalOut led4(LED_BLUE); +PwmOut led2(LED_GREEN); +PwmOut led3(LED_RED); +PwmOut led4(LED_BLUE); AnalogIn adc_1(PTB0); AnalogIn adc_2(PTB1); #endif @@ -29,8 +29,8 @@ uint16_t index_hma_read=0; bool t_write=0; - - +uint16_t speed; +bool start_mesure; bool flag_write_USB=0; Ticker flipperADC; @@ -41,10 +41,10 @@ T_hma_u16[t_write][index_hma_write++]=adc_2.read_u16(); //read ADC - if(index_hma_write>NBSAMPLE) { + if(index_hma_write>=NBSAMPLE) { flag_write_USB=1; t_write=!t_write; //toggel buffer - index_hma_read=index_hma_write-NBCHAN; + index_hma_read=index_hma_write; index_hma_write=0; } @@ -67,29 +67,40 @@ str[start_str]=pc.getc(); } if( strncmp(str,"ABORt",strlen("ABORt"))==0 ) { + start_mesure=0; flipperADC.detach(); t_write=0; index_hma_read=0; index_hma_write=0; - } else if( strncmp(str,"*IDN?",strlen("*IDN?"))==0 ) { - pc.printf("LAAS-CNRS ,HMA serial, %s\r",VERSION); - + } + if(start_mesure==0) { + if( strncmp(str,"*IDN?",strlen("*IDN?"))==0 ) { + pc.printf("LAAS-CNRS ,HMA serial, %s\r",VERSION); + } else if( strncmp(str,"MEASure",strlen("MEASure"))==0 ) { + start_mesure=1; + flipperADC.attach_us(&flipADC, speed); + } else if( strncmp(str,"TIME",strlen("TIME"))==0 ) { + sscanf(&str[strlen("TIME")],"%d",&speed); - } else if( strncmp(str,"MEASure",strlen("MEASure"))==0 ) { - flipperADC.attach_us(&flipADC, SPEED); - } else if( strncmp(str,"TIME",strlen("TIME"))==0 ) { - - //... - + } } } int main() { +#if defined( __LPC1768) led2=0; led3=0; led4=0; +#endif +#if defined( __KL25) + led2=1.0; + led3=0.0; + led4=0.0; +#endif + speed=SPEED; + start_mesure=0; while(1) { if (pc.readable()) { @@ -98,16 +109,11 @@ if(flag_write_USB==1) { flag_write_USB=0; - led4=1; pc.printf("%04d%c\r",index_hma_read,'\0'); //'\0'fin de chaine ASCII '\r' fin de transmission for(unsigned int i=0; i<index_hma_read*NBCHAN; i+=BLOCUSB ) { // 2 cannaux de 16bits pc.writeBlock((uint8_t*)&T_hma_u16[!t_write][i/NBCHAN],BLOCUSB );//For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written. } - led4=0; } - - - } }