I'm no doubt making a simple mistake, but I've been trying myriad variations to try and get an analog in value on p20 to print in teraterm... For HOURS.
Can anyone tell me where I'm going wrong? The following is supposed to give a flowrate and a voltage on a single refreshing teraterm line. But all I get is a static value for the voltage, I've had seemingly random figures and the present version is showing 0.00000
Help
Robin
- include "counter.h"
- include "mbed.h"
Serial pc(USBTX, USBRX);
counter SF800 (p29);
Timer t_a, t_b;
AnalogIn ain(p20);
int main() {
t_a.start();
t_b.start();
int a_init_pulses = 0;
int b_init_pulses = 0;
float flowrate = 0, ain;
int time_window = 1000;
bool a_b_flip_flop = true; if true use window a
pc.printf("\n\r***\n\rMBED restarted\n\r***\n");
while (1) {
wait(0.1);
if (a_b_flip_flop) {
flowrate = (float)(SF800.getPulses() - a_init_pulses)/(2500 * t_a.read_ms() / 60000);
} else {
flowrate = (float)(SF800.getPulses() - b_init_pulses)/(2500 * t_b.read_ms() / 60000);
}
if (t_a.read_ms() > time_window) { switch to window B
pc.printf("\rswitching to window B = %i pulses detected in window A\n", SF800.getPulses() - a_init_pulses);
t_a.reset();
a_b_flip_flop = false;
a_init_pulses = SF800.getPulses();
}
if (t_a.read_ms() > time_window/2 && !a_b_flip_flop) { switch to window A
pc.printf("\rswitching to window A = %i pulses detected in window B\n", SF800.getPulses() - b_init_pulses);
t_b.reset();
a_b_flip_flop = true;
b_init_pulses = SF800.getPulses();
}
pc.printf("\rflowrate = %f l/min", flowrate);
pc.printf(" Inclination = %f", ain);
}
}
I'm no doubt making a simple mistake, but I've been trying myriad variations to try and get an analog in value on p20 to print in teraterm... For HOURS. Can anyone tell me where I'm going wrong? The following is supposed to give a flowrate and a voltage on a single refreshing teraterm line. But all I get is a static value for the voltage, I've had seemingly random figures and the present version is showing 0.00000 Help Robin
Serial pc(USBTX, USBRX); counter SF800 (p29); Timer t_a, t_b; AnalogIn ain(p20);
int main() {
t_a.start(); t_b.start(); int a_init_pulses = 0; int b_init_pulses = 0; float flowrate = 0, ain; int time_window = 1000;
bool a_b_flip_flop = true; if true use window a
pc.printf("\n\r***\n\rMBED restarted\n\r***\n");
while (1) { wait(0.1);
if (a_b_flip_flop) { flowrate = (float)(SF800.getPulses() - a_init_pulses)/(2500 * t_a.read_ms() / 60000); } else { flowrate = (float)(SF800.getPulses() - b_init_pulses)/(2500 * t_b.read_ms() / 60000); }
if (t_a.read_ms() > time_window) { switch to window B
pc.printf("\rswitching to window B = %i pulses detected in window A\n", SF800.getPulses() - a_init_pulses);
t_a.reset(); a_b_flip_flop = false; a_init_pulses = SF800.getPulses(); }
if (t_a.read_ms() > time_window/2 && !a_b_flip_flop) { switch to window A
pc.printf("\rswitching to window A = %i pulses detected in window B\n", SF800.getPulses() - b_init_pulses);
t_b.reset(); a_b_flip_flop = true; b_init_pulses = SF800.getPulses(); }
pc.printf("\rflowrate = %f l/min", flowrate); pc.printf(" Inclination = %f", ain); } }