![](/media/cache/profiles/cff02a74da64d145a4aed3a577a106ab.jpg.50x50_q85.jpg)
test
main.cpp@7:de5b1bc07eb5, 2014-06-23 (annotated)
- Committer:
- fblanc
- Date:
- Mon Jun 23 14:34:21 2014 +0000
- Revision:
- 7:de5b1bc07eb5
- Parent:
- 6:fa9df9f03bfa
- Child:
- 8:213824bed8d5
16 samples 2 channel time ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fblanc | 0:92dd9611bf80 | 1 | #include "mbed.h" |
fblanc | 4:75077e05de3e | 2 | #include "USBSerial.h" |
fblanc | 7:de5b1bc07eb5 | 3 | #define VERSION "23_06_2014" |
fblanc | 7:de5b1bc07eb5 | 4 | #define SPEED 5000//1000 //µs |
fblanc | 6:fa9df9f03bfa | 5 | #define BLOCUSB 64 //64 |
fblanc | 6:fa9df9f03bfa | 6 | #define NBCHAN 2 |
fblanc | 6:fa9df9f03bfa | 7 | #define NBSAMPLE BLOCUSB/NBCHAN // 2 samples 16bit |
fblanc | 6:fa9df9f03bfa | 8 | #define __KL25 |
fblanc | 4:75077e05de3e | 9 | #if defined( __LPC1768) |
fblanc | 5:832b59a73dec | 10 | Serial debug(USBTX, USBRX); |
fblanc | 4:75077e05de3e | 11 | USBSerial pc; |
fblanc | 0:92dd9611bf80 | 12 | DigitalOut led2(LED2); |
fblanc | 0:92dd9611bf80 | 13 | DigitalOut led3(LED3); |
fblanc | 0:92dd9611bf80 | 14 | DigitalOut led4(LED4); |
fblanc | 3:7acf6d1a6b1e | 15 | AnalogIn adc_1(p16); |
fblanc | 3:7acf6d1a6b1e | 16 | AnalogIn adc_2(p17); |
fblanc | 4:75077e05de3e | 17 | #endif |
fblanc | 4:75077e05de3e | 18 | #if defined( __KL25) |
fblanc | 4:75077e05de3e | 19 | USBSerial pc; |
fblanc | 7:de5b1bc07eb5 | 20 | PwmOut led2(LED_GREEN); |
fblanc | 7:de5b1bc07eb5 | 21 | PwmOut led3(LED_RED); |
fblanc | 7:de5b1bc07eb5 | 22 | PwmOut led4(LED_BLUE); |
fblanc | 6:fa9df9f03bfa | 23 | AnalogIn adc_1(PTB0); |
fblanc | 6:fa9df9f03bfa | 24 | AnalogIn adc_2(PTB1); |
fblanc | 4:75077e05de3e | 25 | #endif |
fblanc | 4:75077e05de3e | 26 | |
fblanc | 6:fa9df9f03bfa | 27 | uint16_t T_hma_u16[2][BLOCUSB]; |
fblanc | 0:92dd9611bf80 | 28 | uint16_t index_hma_write=0; |
fblanc | 0:92dd9611bf80 | 29 | |
fblanc | 0:92dd9611bf80 | 30 | uint16_t index_hma_read=0; |
fblanc | 0:92dd9611bf80 | 31 | bool t_write=0; |
fblanc | 7:de5b1bc07eb5 | 32 | uint16_t speed; |
fblanc | 7:de5b1bc07eb5 | 33 | bool start_mesure; |
fblanc | 0:92dd9611bf80 | 34 | bool flag_write_USB=0; |
fblanc | 0:92dd9611bf80 | 35 | Ticker flipperADC; |
fblanc | 0:92dd9611bf80 | 36 | |
fblanc | 0:92dd9611bf80 | 37 | void flipADC() |
fblanc | 0:92dd9611bf80 | 38 | { |
fblanc | 4:75077e05de3e | 39 | |
fblanc | 3:7acf6d1a6b1e | 40 | T_hma_u16[t_write][index_hma_write++]=adc_1.read_u16(); //read ADC |
fblanc | 3:7acf6d1a6b1e | 41 | T_hma_u16[t_write][index_hma_write++]=adc_2.read_u16(); //read ADC |
fblanc | 5:832b59a73dec | 42 | |
fblanc | 5:832b59a73dec | 43 | |
fblanc | 7:de5b1bc07eb5 | 44 | if(index_hma_write>=NBSAMPLE) { |
fblanc | 0:92dd9611bf80 | 45 | flag_write_USB=1; |
fblanc | 0:92dd9611bf80 | 46 | t_write=!t_write; //toggel buffer |
fblanc | 7:de5b1bc07eb5 | 47 | index_hma_read=index_hma_write; |
fblanc | 0:92dd9611bf80 | 48 | index_hma_write=0; |
fblanc | 0:92dd9611bf80 | 49 | } |
fblanc | 4:75077e05de3e | 50 | |
fblanc | 0:92dd9611bf80 | 51 | } |
fblanc | 0:92dd9611bf80 | 52 | |
fblanc | 0:92dd9611bf80 | 53 | Ticker flipperUSB; |
fblanc | 0:92dd9611bf80 | 54 | void flipUSB() |
fblanc | 0:92dd9611bf80 | 55 | { |
fblanc | 0:92dd9611bf80 | 56 | |
fblanc | 0:92dd9611bf80 | 57 | flag_write_USB=1; |
fblanc | 0:92dd9611bf80 | 58 | |
fblanc | 0:92dd9611bf80 | 59 | } |
fblanc | 0:92dd9611bf80 | 60 | |
fblanc | 0:92dd9611bf80 | 61 | void pc_rx(void) |
fblanc | 0:92dd9611bf80 | 62 | { |
fblanc | 5:832b59a73dec | 63 | char str[32]; |
fblanc | 0:92dd9611bf80 | 64 | |
fblanc | 5:832b59a73dec | 65 | |
fblanc | 5:832b59a73dec | 66 | for(int start_str=0; pc.readable()!=0; ++start_str) { |
fblanc | 0:92dd9611bf80 | 67 | str[start_str]=pc.getc(); |
fblanc | 0:92dd9611bf80 | 68 | } |
fblanc | 5:832b59a73dec | 69 | if( strncmp(str,"ABORt",strlen("ABORt"))==0 ) { |
fblanc | 7:de5b1bc07eb5 | 70 | start_mesure=0; |
fblanc | 0:92dd9611bf80 | 71 | flipperADC.detach(); |
fblanc | 0:92dd9611bf80 | 72 | t_write=0; |
fblanc | 0:92dd9611bf80 | 73 | index_hma_read=0; |
fblanc | 0:92dd9611bf80 | 74 | index_hma_write=0; |
fblanc | 4:75077e05de3e | 75 | |
fblanc | 7:de5b1bc07eb5 | 76 | } |
fblanc | 7:de5b1bc07eb5 | 77 | if(start_mesure==0) { |
fblanc | 7:de5b1bc07eb5 | 78 | if( strncmp(str,"*IDN?",strlen("*IDN?"))==0 ) { |
fblanc | 7:de5b1bc07eb5 | 79 | pc.printf("LAAS-CNRS ,HMA serial, %s\r",VERSION); |
fblanc | 7:de5b1bc07eb5 | 80 | } else if( strncmp(str,"MEASure",strlen("MEASure"))==0 ) { |
fblanc | 7:de5b1bc07eb5 | 81 | start_mesure=1; |
fblanc | 7:de5b1bc07eb5 | 82 | flipperADC.attach_us(&flipADC, speed); |
fblanc | 7:de5b1bc07eb5 | 83 | } else if( strncmp(str,"TIME",strlen("TIME"))==0 ) { |
fblanc | 7:de5b1bc07eb5 | 84 | sscanf(&str[strlen("TIME")],"%d",&speed); |
fblanc | 0:92dd9611bf80 | 85 | |
fblanc | 7:de5b1bc07eb5 | 86 | } |
fblanc | 0:92dd9611bf80 | 87 | } |
fblanc | 0:92dd9611bf80 | 88 | } |
fblanc | 0:92dd9611bf80 | 89 | |
fblanc | 0:92dd9611bf80 | 90 | int main() |
fblanc | 0:92dd9611bf80 | 91 | { |
fblanc | 7:de5b1bc07eb5 | 92 | #if defined( __LPC1768) |
fblanc | 5:832b59a73dec | 93 | led2=0; |
fblanc | 5:832b59a73dec | 94 | led3=0; |
fblanc | 5:832b59a73dec | 95 | led4=0; |
fblanc | 7:de5b1bc07eb5 | 96 | #endif |
fblanc | 7:de5b1bc07eb5 | 97 | #if defined( __KL25) |
fblanc | 7:de5b1bc07eb5 | 98 | led2=1.0; |
fblanc | 7:de5b1bc07eb5 | 99 | led3=0.0; |
fblanc | 7:de5b1bc07eb5 | 100 | led4=0.0; |
fblanc | 7:de5b1bc07eb5 | 101 | #endif |
fblanc | 7:de5b1bc07eb5 | 102 | speed=SPEED; |
fblanc | 7:de5b1bc07eb5 | 103 | start_mesure=0; |
fblanc | 5:832b59a73dec | 104 | while(1) { |
fblanc | 0:92dd9611bf80 | 105 | |
fblanc | 0:92dd9611bf80 | 106 | if (pc.readable()) { |
fblanc | 0:92dd9611bf80 | 107 | pc_rx(); |
fblanc | 0:92dd9611bf80 | 108 | } |
fblanc | 5:832b59a73dec | 109 | |
fblanc | 0:92dd9611bf80 | 110 | if(flag_write_USB==1) { |
fblanc | 0:92dd9611bf80 | 111 | flag_write_USB=0; |
fblanc | 2:88f866289381 | 112 | pc.printf("%04d%c\r",index_hma_read,'\0'); //'\0'fin de chaine ASCII '\r' fin de transmission |
fblanc | 6:fa9df9f03bfa | 113 | for(unsigned int i=0; i<index_hma_read*NBCHAN; i+=BLOCUSB ) { // 2 cannaux de 16bits |
fblanc | 6:fa9df9f03bfa | 114 | 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. |
fblanc | 0:92dd9611bf80 | 115 | } |
fblanc | 0:92dd9611bf80 | 116 | |
fblanc | 0:92dd9611bf80 | 117 | } |
fblanc | 0:92dd9611bf80 | 118 | } |
fblanc | 0:92dd9611bf80 | 119 | } |