about measuring AC frequency with digital input
hello guys, let me ask something
im sorry, im not expert on arduino
so have project making prototype measure ac line frequency, have ac voltage range 0-4v. put output digital pin 2 of arduino uno. here code :
i code in 1 random forum (im forget it, cant put link) , it's working. measure ac line , 50,... hz.
so it's questions :
1. safe put ac signal (sine wave) 0-4v in digital input of arduino?
2. how can delay 125ms every frequency readings serial monitor? because take 0.5-1.5s in code because of interrupt
thank sir
im sorry, im not expert on arduino
so have project making prototype measure ac line frequency, have ac voltage range 0-4v. put output digital pin 2 of arduino uno. here code :
code: [select]
int cnt=0;
int sample=75; //sample size, should @ least 1.5 times expected frequency
float t1,t2,freq;
void setup() // code counting increasing values
{
serial.begin(9600);
pinmode(2,input);
attachinterrupt(0,count,rising);
t1=millis();
t2=0;
serial.print("starting\n");
}
void loop()
{
if (t2!=0) {
nointerrupts(); //disable interrupts ensure accuracy of readings
freq=sample/((t2-t1)/1000);
serial.print(cnt);
serial.print(" freq: ");
serial.println(freq); //treat output liking
t1=millis(); //reset variables
t2=0;
cnt=0;
interrupts(); //enable interrupts again
}
}
void count()
{
cnt++;
if (cnt==sample) { //signal when set number of samples have been taken
t2=millis();
}
}
i code in 1 random forum (im forget it, cant put link) , it's working. measure ac line , 50,... hz.
so it's questions :
1. safe put ac signal (sine wave) 0-4v in digital input of arduino?
2. how can delay 125ms every frequency readings serial monitor? because take 0.5-1.5s in code because of interrupt
thank sir
if ac voltage, negative excursions, may destroy digital input. put 10k ohm resistor in series input pin prevent that.
Arduino Forum > Topics > Science and Measurement > about measuring AC frequency with digital input
arduino
Comments
Post a Comment