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.
Dependencies: AnalogIn_Diff_ok mbed
Diff: main.cpp
- Revision:
- 0:9eeda5b17b5b
- Child:
- 1:c340607e4661
diff -r 000000000000 -r 9eeda5b17b5b main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jul 10 12:22:18 2014 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "math.h"
+#include "MovingAverage.h"
+//USBSerial pc;
+struct{
+double gain;
+double offset;
+//AnalogIn adc;
+ }adc_volt,adc_curr;
+Serial pc(USBTX, USBRX);
+AnalogIn adc_1(PTB2);
+AnalogIn adc_2(PTB3);
+Ticker flipperADC;
+DigitalOut led1(LED_RED);
+DigitalOut led2(LED_GREEN);
+DigitalOut led3(LED_BLUE);
+MovingAverage<float> Trms_float(100,0);
+MovingAverage<int> Trms_int(100,0);
+void flipADC() {
+ led1=1;
+ int val_i32=adc_2.read_u16()-adc_1.read_u16(); //read ADC
+
+ float val=((float)val_i32*adc_volt.gain)-adc_volt.offset;
+ Trms_float.Insert(val*val);
+ led1=0;
+ }
+
+int main() {
+
+pc.baud(115200);
+adc_volt.gain=3.3/65535.0;
+adc_volt.offset=0.0;
+
+ flipperADC.attach_us(&flipADC, 200); //200µs
+
+ led1=1;
+ led2=0;
+ led3=1;
+ while (true) {
+
+ wait (1);
+ led3=1;
+
+ pc.printf("RMS=%0.3f \r\n",sqrt(Trms_float.GetAverage()));
+ led3=0;
+ }
+}
\ No newline at end of file
ADC DIFF K64F