test AnalogIn_Diff.lib for board K64F
Dependencies: AnalogIn_Diff_ok mbed
Revision 4:bcd2a4b5feaf, committed 2014-07-22
- Comitter:
- fblanc
- Date:
- Tue Jul 22 15:02:09 2014 +0000
- Parent:
- 3:f1ab02bc87f3
- Child:
- 5:f994e394a7ec
- Commit message:
- AnalogIn_Diff
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AnalogIn_Diff.lib Tue Jul 22 15:02:09 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JimCarver/code/AnalogIn_Diff/#7b36e4381d83
--- a/MoyenneMobile.lib Wed Jul 16 14:39:09 2014 +0000 +++ b/MoyenneMobile.lib Tue Jul 22 15:02:09 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Alegrowin/code/MoyenneMobile/#b310d132db09 +http://mbed.org/users/Alegrowin/code/MoyenneMobile/#da07a13d617f
--- a/main.cpp Wed Jul 16 14:39:09 2014 +0000
+++ b/main.cpp Tue Jul 22 15:02:09 2014 +0000
@@ -1,9 +1,11 @@
#include "mbed.h"
+#include "AnalogIn_Diff.h"
#include "math.h"
#include "MovingAverage.h"
-#define VERSION "15_07_2014"
+
+#define VERSION "21_07_2014"
#define CIBLE "K64F"
-//USBSerial pc;
+
#define max(a,b) (a>=b?a:b)
#define min(a,b) (a<=b?a:b)
#define UAC_NON 230.0
@@ -12,8 +14,11 @@
#define UAC_NON2 UAC_NON*UAC_NON
#define UAC_MAX2 UAC_MAX*UAC_MAX
#define UAC_MIN2 UAC_MIN*UAC_MIN
+#define R1 1E6
+#define R2
+AnalogIn_Diff a2d(0);
struct {
- float gain;
+ float gain;
float offset;
//AnalogIn adc;
} adc_volt,adc_curr;
@@ -22,8 +27,9 @@
Timer timer_max;
bool F_timer_max=false;
Serial pc(USBTX, USBRX);
-AnalogIn adc_1(PTB2);
-AnalogIn adc_2(PTB3);
+//AnalogIn adc_1(PTB2);
+//AnalogIn adc_2(PTB3);
+
Ticker flipperADC;
DigitalOut led1(LED_RED);
DigitalOut led2(LED_GREEN);
@@ -35,65 +41,69 @@
bool min_OK=false;
void flipADC()
{
+
float val;
led1=1;
- int val_i32=adc_2.read_u16()-adc_1.read_u16(); //read ADC
+ int val_i32=a2d.read_16(1);
val=(float)val_i32*adc_volt.gain-adc_volt.offset;
-moy.Insert(val);
+
+ moy.Insert(val);
Trms.Insert(val*val);
val=Trms.GetAverage();
max=max(val,max);
if(min_OK==true)
min=min(val,min);
- if(val<UAC_MIN2 && F_timer_min ==false)
- {
+ if(val<UAC_MIN2 && F_timer_min ==false) {
timer_min.reset();
timer_min.start();
- F_timer_min = true;
+ F_timer_min = true;
}
- if(val>UAC_MIN2 && F_timer_min ==true)
- {
+ if(val>UAC_MIN2 && F_timer_min ==true) {
timer_min.stop();
- F_timer_min = false;
+ F_timer_min = false;
}
- if(val>UAC_MAX2 && F_timer_max ==false)
- {
+ if(val>UAC_MAX2 && F_timer_max ==false) {
timer_max.reset();
timer_max.start();
- F_timer_max = true;
+ F_timer_max = true;
}
- if(val<UAC_MAX2 && F_timer_max ==true)
- {
+ if(val<UAC_MAX2 && F_timer_max ==true) {
timer_max.stop();
-
- F_timer_max = false;
+
+ F_timer_max = false;
}
+
led1=0;
}
int main()
{
+
+
led1=1;
led2=0;
led3=1;
pc.baud(115200);
pc.printf("LAAS-CNRS ,TRMS ,%s ,%s\r",CIBLE,VERSION);
- adc_volt.gain=(1960.0*3.3)/65535.0;
+ adc_volt.gain=(3920.0*3.3)/65535.0;
adc_volt.offset=-17.0;
flipperADC.attach_us(&flipADC, 1000); //200µs
wait (5);
-min_OK=true;
+ min_OK=true;
+
while (true) {
-
+
led3=1;
pc.printf("RMS=%f \r\n",sqrt(Trms.GetAverage()));
pc.printf("min=%0.0f t=%f max=%0.0f t=%f\r\n",sqrt(min),timer_min.read(),sqrt(max),timer_max.read());
pc.printf("moy=%f \r\n",moy.GetAverage());
+
led3=0;
+
wait (1);
}
}
\ No newline at end of file
--- a/mbed.bld Wed Jul 16 14:39:09 2014 +0000 +++ b/mbed.bld Tue Jul 22 15:02:09 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file
frederic blanc
ADC DIFF K64F