Program analysis

Hello I have to understand a variometer program for my school. I already understood a part of it but there are still some problems for me :

First of all what is the value of toneFreqLowpass at the first loop ?

Then when I test the program on a paper sheet with some value (for example pressure = 90000 ) It doesn't work. There is something I don't understand ...

I JOIN THE PROGRAM

Thank you very much for tour help

Fabien

bonjour , je dois comprendre un programme arduino pour mon école . J'ai déjà compris une partie mais il reste quelques lignes que je ne comprends pas.

Quelle est la valeur de toneFreqLowpass lors du premier passage car aucune valeur ne lui est attribuée ?

Quand je test le programme avec une feuille et un stylo , avec par exemple une pression de 900 hPa , la sortie est incohérente . Quelle est mon erreur ?

Merci beaucoup pour votre aide

Fabien

#include <Wire.h>

const byte led = 13;

unsigned int calibrationData[7];
unsigned long time = 0;

float toneFreq, toneFreqLowpass, pressure, lowpassFast, lowpassSlow ;

int ddsAcc;

void setup()
{
Wire.begin();
Serial.begin(115200);
setupSensor();

pressure = getPressure();
lowpassFast = lowpassSlow = pressure;
}

void loop()
{
pressure = getPressure();

lowpassFast = lowpassFast + (pressure - lowpassFast) * 0.1;
lowpassSlow = lowpassSlow + (pressure - lowpassSlow) * 0.05;

toneFreq = (lowpassSlow - lowpassFast) * 50;

toneFreqLowpass = toneFreqLowpass + (toneFreq - toneFreqLowpass) * 0.1;

toneFreq = constrain(toneFreqLowpass, -500, 500);

ddsAcc += toneFreq * 100 + 2000;

if (toneFreq < 0 || ddsAcc > 0)
{
tone(2, toneFreq + 510);
}
else
{
noTone(2);
}

ledOff();
while (millis() < time);
time += 20;
ledOn();
}

what is the value of toneFreqLowpass at the first loop ?

Global variables such as this are initialised to zero when declared if no value is specified. If you want it to be some other value then initialise it explicitly.

Incidentally, you could print the value in setup() to see what is is.

Ok thank you , I was not sure

What is the unit of the pressure in this program ? Pa , kPa, hPa ?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post your COMPLETE code please?
What is it supposed to do?
What model Arduino are you using?

Tom.. :slight_smile:

Fabss:
What is the unit of the pressure in this program ? Pa , kPa, hPa ?

There is no way we can tell. That isn't a complete program. The pressure is calculated in a function getPressure() that is not included in what you have posted. And presumably the value comes from a sensor that you haven't told us anything about which is initialised in the setupSensor() function that is not included either.

Steve