10kHz ADC which reads from 17,18,19,20 pins and send the result to remote server (multicast now) via UDP
Dependencies: EthernetNetIf mbed
Revision 1:beae6624e569, committed 2012-03-26
- Comitter:
- mrcandy
- Date:
- Mon Mar 26 15:54:08 2012 +0000
- Parent:
- 0:7744cef9f8af
- Commit message:
- net::poll() added
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 7744cef9f8af -r beae6624e569 main.cpp --- a/main.cpp Tue Mar 13 14:57:54 2012 +0000 +++ b/main.cpp Mon Mar 26 15:54:08 2012 +0000 @@ -10,7 +10,7 @@ DigitalOut int_led(LED1); Serial pc(USBTX,USBRX); -Host multicast(IpAddr(239, 192, 1, 100), 50000, NULL); +Host multicast(IpAddr(192,168,0,199), 27200, NULL); //Target IP and port ADC adc(SAMPLE_RATE, 1); Ticker flipper; unsigned short samples1,samples2,samples3,samples4; @@ -19,7 +19,7 @@ char str[50]; -void onUDPSocketEvent(UDPSocketEvent e) { //îáðàáîòêà ïðèõîäÿùåãî ïàêåòà UDP +void onUDPSocketEvent(UDPSocketEvent e) { //Incoming UDP packet processing switch (e) { case UDPSOCKET_READABLE: //The only event for now char buf[64] = {0}; @@ -33,13 +33,14 @@ } } -void flip() { // èçìåðåíèå ïî ïðåðûâàíèþ è îòïðàâêà â UDP +void flip() { // interrupt function: measurement and sending a UDP packet int_led = !int_led; /* samples1=adc.read(p20); samples2=adc.read(p19); samples3=adc.read(p18); samples4=adc.read(p17);*/ - k++; //ñ÷åò÷èê êîëè÷åñòâà öèêëîâ + Net::poll(); //Do network stuff + k++; //cycle number counter sprintf(str, "1=%04u 2=%04u 3=%04u 4=%04u",adc.read(p17),adc.read(p18),adc.read(p19),adc.read(p20)); udp.sendto( str, strlen(str), &multicast ); } @@ -47,7 +48,7 @@ int main() { pc.baud(57600); - //óñòàíîâêà Ethernet + //Ethernet initializing, Serial Interface - 57600 kbit/s printf("Setting up...\n"); EthernetErr ethErr = eth.setup(); if (ethErr) { @@ -63,7 +64,7 @@ tmr.start(); - //âêëþ÷àåì ADC íà ïèíàõ 17,18,19,20 + //Turning ON Burst-mode ADC on pins 17,18,19,20 note: connect not used ADC ping to ground adc.startmode(0,0); adc.burst(1); adc.setup(p20,1); @@ -73,11 +74,11 @@ printf("start\n"); - flipper.attach_us(&flip, 100); // âêëþ÷àåì ïðåðûâàíèå - wait(10); // ìåðÿåì 10 ñåêóíä - flipper.detach(); + flipper.attach_us(&flip, 100); // Interrupt Turn ON 10kHz + wait(10); // 10 seconds measurement + flipper.detach(); // Interrupt Turn OFF - adc.burst(0); //âûêëþ÷àåì ADC + adc.burst(0); //ADC Turn OFF adc.setup(p20,0); adc.setup(p19,0); adc.setup(p18,0);