Hi everyone.
I am having an assignment on ACS712. This exercise requires calculating the voltage Vq in the absence of current. It's very simple if you calculate it in theory, it's equal to Vcc/2. But when it comes to practicality, it's not stable. It is not equal to Vcc/2 but lower. And I determined that the smoothing factor "dt" of the low pass filter was the problem. I tried changing to 0.2 or 0.002 but still not stable. Vq ranges from 2.48 to 2.6V. It causes error when calculating current Ip if load is inserted.
In the datasheet of the ACS712 the noise frequency is around 2kHz.
Can anyone help me how to change the "dt" corresponding to the cutoff frequency of 2000Hz to get the most stable results.
Thanks everyone.
This is code:
const int analogpin = A0;
int Xn =0;
float yn = 0;
float yn1 = 0;
float alpha = 0;
float dt = 0.002;//Smoothing factor
float fc = 2000.0;//Noise frequency is 2kHz
//Calculate the voltage Vq at equilibrium
void setup()
{
Serial.begin(115200);
float k = 2*3.14*dt*fc;
alpha = k/(k+1); // alpha coefficient
}
void loop()
{
Xn = analogRead(sensor1);
yn = alpha *Xn + (1-alpha) * yn1;
yn1 = yn;
float vol = 5.03*(yn/1024.0);//vq = vol
Serial.println(vol,6);
}
I have moved your Topic to Programming Questions....Please try not to post in Uncategorised again, If you are unsure about the categories refer to this guide or to the stickies for each category.
With a digital filter, the filter frequency response depends on the sample frequency, as well as other factors.
In your case, the sample period (1/(sample frequency)) is the time it takes the loop function to run one cycle, which you don't know, and is variable because of the print statement.