test ADC avec page Web reduite
Dependencies: UIPEthernet mbed FCT_WEB hebergement
Fork of Nucleo_Web_ENC28J60 by
P.S : 1ère mise en fonctionnement de la carte NUCLEO STM32F411RET6
Instruction pour la mise en fonctionnement : https://developer.mbed.org/users/Fo170/notebook/the-stm32-nucleo-64-board/
Diff: main.cpp
- Revision:
- 17:7539e7bdfee9
- Parent:
- 16:5a3d10a54762
- Child:
- 18:7254aeaa41a8
--- a/main.cpp Thu Aug 06 12:42:30 2015 +0000 +++ b/main.cpp Thu Aug 06 13:55:44 2015 +0000 @@ -1,6 +1,6 @@ /* In this example LED1 is switched on/off using a web browser connected to this HTTP server. * The example is based on the Tuxgraphics Web Switch <http://www.tuxgraphics.org/>. - * This HTTP server is built around the the ENC28J60 chip + * This HTTP server is built around the the ENC28J60 chip * driven by the UIPEthernet library <https://github.com/ntruchsess/arduino_uip> * ported to mbed. */ @@ -80,39 +80,52 @@ float Seconds = 0.0; float time_between_two_measurement_ADC = 0.0; -float meas, meas_sum, meas_moy, meas_min, meas_max, v_min, v_max; +float meas, meas_sum, meas_moy, meas_min, meas_max; +float vdc, vdc_min, vdc_max; +float vac, pow2_vac, sum_pow2_vac, veff; Ticker time_measurement_ADC; - + void measurement_ADC() { - meas = a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0) + meas = 3300.0 * a_in.read(); // Converts and read the analog input value (value from 0.0 to 1.0) //wait_us(10); meas_sum += meas; if(meas_min > meas) meas_min = meas; if(meas_max < meas) meas_max = meas; + + vac = meas - 1650.0; // 0V AC = 3,3V/2 + pow2_vac = vac * vac; // valeur VAC au carré + sum_pow2_vac += pow2_vac; // somme des valeurs AC au carré + Samples++; - - if( Samples == NB_SAMPLES ) - { - meas_moy = meas_sum * 3300.0; // Change the value to be in the 0 to 3300 range - meas_moy /= (float)NB_SAMPLES; - Samples = 0; - meas_sum = 0.0; - v_min = 3300.0 * meas_min, v_max = 3300.0 * meas_max; - meas_min = 1.0 , meas_max = 0.0; + + if( Samples == NB_SAMPLES ) { + // VDC + meas_moy = meas_sum; + meas_moy /= (float)NB_SAMPLES; + // VAC + veff = sum_pow2_vac; + veff /= (float)NB_SAMPLES; + veff = sqrt(veff); + + Samples = 0; + meas_sum = 0.0; + vdc_min = meas_min, vdc_max = meas_max; + meas_min = 3300.0 , meas_max = 0.0; + sum_pow2_vac = 0.0; } } - + //------------ #define __Time_between_refresh_in_Second__ 0.1 Ticker second_ticker; void add_one_second() -{ - Seconds = Seconds + (float)__Time_between_refresh_in_Second__; +{ + Seconds = Seconds + (float)__Time_between_refresh_in_Second__; } //------------ const uint16_t MY_PORT = 80; // for HTTP connection @@ -169,13 +182,13 @@ httpContent = "/" + PASSWORD + "/"; else httpContent = ""; - /* - httpContent += "<h1>301 Moved Permanently "; - httpContent += __image_301_Moved_Permanently__; - httpContent += "</h1>\r\n"; - */ + /* + httpContent += "<h1>301 Moved Permanently "; + httpContent += __image_301_Moved_Permanently__; + httpContent += "</h1>\r\n"; + */ httpContent += str_moved_perm; - + return (httpContent); } @@ -183,7 +196,7 @@ { char buffer[128]; //char time_stamp[32]; - + //------------- httpContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n"; httpContent += "<meta http-equiv=\"refresh\" content=\""; @@ -194,34 +207,37 @@ httpContent += "<HTML><HEAD>\r\n"; httpContent += "<title>WEB Server Nucleo F411RE & ENC28J60 - ADC</title>\r\n"; - + httpContent += "</HEAD><BODY>\r\n"; httpContent += "<center><h2>WEB Server Nucleo F411RE (ADC)</h2>\r\n"; httpContent += "<p>Designed for STM32F411RE & ENC28J60 (ADC)\r\n"; - httpContent += "<p>Compilation avec mBED à " __TIME__ " le " __DATE__" \r\n"; - + httpContent += "<p>Compilation avec mBED à " __TIME__ " le " __DATE__" \r\n"; + httpContent += "<p></center>\r\n<hr><p>\r\n"; - + /* httpContent += "Local Time: "; time_t seconds = time(NULL)+ 19800; // time(null) gives the GMT time . // printf("Time as seconds since January 1, 1970 = %d\n", seconds); - strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds)); - // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp + strftime(time_stamp, 32, "%y %m %d, %H:%M:%Ss", localtime(&seconds)); + // this converts the value in seconds obtained above to human readable format and assigns it to the timestamp sprintf(buffer, "%s", time_stamp);// diplays the human readable time */ sprintf(buffer, "%.1f ", Seconds);// diplays the human readable Seconds httpContent += buffer; httpContent += "Seconds\r\n<hr>\r\n"; //---------------- - - httpContent += "AnalogIn(PC_5) : (DC de 0 a 3,3V)<p>\r\n"; - sprintf(buffer, "%.0f mV Moy ( sum : %.0f - Samples : %u )\r\n", meas_moy, meas_sum, Samples); - httpContent += buffer; - httpContent += "<p>\r\n"; - sprintf(buffer, "%.0f mV Min, %.0f mV Max , diff : %.0f mV\r\n", v_min, v_max, v_max - v_min); - httpContent += buffer; + + httpContent += "AnalogIn(PC_5) :<p>\r\n"; + sprintf(buffer, "%.0f mV Moy ( sum : %.0f - Samples : %u )\r\n", meas_moy, meas_sum, Samples); + httpContent += buffer; + httpContent += "<p>\r\n"; + sprintf(buffer, "DC (0 à 3,3V) : %.0f mV Min, %.0f mV Max , diff : %.0f mV\r\n", vdc_min, vdc_max, vdc_max - vdc_min); + httpContent += buffer; + httpContent += "<p>\r\n"; + sprintf(buffer, "AC (-1,65V à 1,65V) : %.0f mV eff\r\n", veff); + httpContent += buffer; httpContent += "</BODY></HTML>"; //----------- //wait(1); @@ -245,42 +261,40 @@ int main() { - meas_moy = 0.0; - Samples = 0; - meas_sum = 0.0; - meas_min = 1.0 , meas_max = 0.0; - // RTC - //set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC - - // Date and time are set. - - // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms) - second_ticker.attach(&add_one_second, __Time_between_refresh_in_Second__); - - //----------------- - // 50 Hz --> 20ms - // 100 samples par oscillations = 20 / 100 = 0.2ms = 200µs - // 100 samples * 50 oscillations = 5000 samples au total par secondes - // interval: 200 micro seconds chaques samples - time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us); - - //----------------- + meas_moy = 0.0; + Samples = 0; + meas_sum = 0.0; + meas_min = 3300.0 , meas_max = 0.0; + sum_pow2_vac = 0.0; + +// RTC +//set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC + +// Date and time are set. + +// Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms) + second_ticker.attach(&add_one_second, __Time_between_refresh_in_Second__); + +//----------------- +// 50 Hz --> 20ms +// 100 samples par oscillations = 20 / 100 = 0.2ms = 200µs +// 100 samples * 50 oscillations = 5000 samples au total par secondes +// interval: 200 micro seconds chaques samples + time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us); + +//----------------- UIPEthernet.begin(MY_MAC,MY_IP); myServer.begin(); - while(1) - { + while(1) { EthernetClient client = myServer.available(); - if(client) - { + if(client) { size_t size = client.available(); - if(size > 0) - { + if(size > 0) { uint8_t* buf = (uint8_t*)malloc(size); size = client.read(buf, size); string received((char*)buf); free(buf); - if(received.substr(0, 3) != "GET") - { + if(received.substr(0, 3) != "GET") { // head, post or other method // for possible status codes see: // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html @@ -290,8 +304,7 @@ continue; } - if(received.substr(0, 6) == "GET / ") - { + if(received.substr(0, 6) == "GET / ") { httpHeader = HTTP_OK; /* httpContent = "<p>Usage: http://host_or_ip/password</p>\r\n"; @@ -303,16 +316,14 @@ int cmd = analyse_get_url(received); - if(cmd == -2) - { + if(cmd == -2) { // redirect to the right base url httpHeader = MOVED_PERM; http_send(client, httpHeader, moved_perm(1)); continue; } - if(cmd == -1) - { + if(cmd == -1) { httpHeader = UNAUTHORIZED; /* httpContent = "<h1>401 Unauthorized ";