Detección 100hz
hola soy nuevo en esto de arduino y investigado mucho y probado tambien pero no obtenido buenos resultados ya que los sketch que probado se demora mucho tiempo en calcular la frecuencia la idea es que bajo los 100 hertz (onda cuadrada) mantenga un led apagado y sobre estos lo mantenga encendido obviamente en el menor tiempo posible espero que me puedan ayudar saludos y gracias de antemano .
buscando por hay encontre este frecuenciometro pero veo que contiene algunos delay se podra modificar este codigo para lo que necesito
aqui dejo el codigo saludos
aqui dejo el codigo saludos
code: [select]
/*
frequency counter arduino sketch
by: jim lindblom
sparkfun electronics
license: beerware
isn't accurate frequency counter, it's simple to
program , understand, , works in pinch. i've tested to
accurate @ least 96% (usually around 99.5%). should
able measure frequencies 6.5mhz(8mhz optimally)
circuit: powered @ 5v (5v lcd), arduino running @ 16mhz
d2 - rs (lcd)
d3 - r/w (lcd)
d4 - e (lcd)
d5 - frequency input
d6 - db4 (lcd)
d7 - db5 (lcd)
d8 - db6 (lcd)
d9 - db7 (lcd)
d10 - gate of npn transistor (collector tied 5v, emitter tied lcd backlight pin)
for liquidcrystal library, to:
david a. mellis
limor fried (http://www.ladyada.net)
tom igoe
*/
#include <liquidcrystal.h>
// initialize library numbers of interface pins
liquidcrystal lcd(2, 3, 4, 6, 7, 8, 9);
int brightness;
unsigned int tovf1 = 0;
unsigned long frequency = 0;
unsigned long temp = 0;
// timer 1 our counter
// 16-bit counter overflows after 65536 counts
// tovfl keep track of how many times overflow
isr(timer1_ovf_vect)
{
tovf1++;
}
void setup() {
pinmode(5, input); // frequency input
pinmode(10, output); // backlight control pin
digitalwrite(10, high); // turn backlight on
// timer 1 setup counter
// maximum frequency fclk_io/2
// (recommended < fclk_io/2.5)
// fclk_io 16mhz
tccr1a = 0;
// external clock source on d5, trigger on rising edge:
tccr1b = (1<<cs12) | (1<<cs11) | (1<<cs10);
// enable overflow interrupt
// jump isr(timer1_ovf_vect) when overflowed:
timsk1 = (1<<toie1);
// set lcd's number of rows , columns:
lcd.begin(16, 2);
// print splash screen lcd.
lcd.print("frequencycounter");
lcd.setcursor(0, 1);
lcd.print(" v1.0 ");
delay(2000);
}
void loop() {
// delay second. while we're delaying counter 1 still
// reading input on d5, , keeping track of how
// many times it's overflowed
delay(1000);
lcd.clear();
frequency = (tcnt1h<<8)|tcnt1l;
frequency = (tcnt1h<<8)|tcnt1l;
// correct weird counter bug
// small range of frequencies (~30k-50k) getting
// 42949 appended front of them
// works now
if (frequency > 40000000)
frequency -= 4294900000;
// 65536 (2^16) maximum of counter
// we'll multiply how many times overflowed
temp = 65536*(unsigned long)tovf1;
// add overflow value frequency
frequency += temp;
// print proper amount of spaces make pretty
lcd.setcursor(0,1);
if (frequency < 100)
lcd.print(" ");
else if (frequency < 10000)
lcd.print(" ");
else if (frequency < 1000000)
lcd.print(" ");
else
lcd.print(" ");
lcd.print(frequency);
lcd.print(" hz");
// reset counter variables , start over
tcnt1h = 0;
tcnt1l = 0;
tovf1 = 0;
}
Arduino Forum > International > Español > Software (Moderators: surbyte, Hector_A) > Detección 100hz
arduino
Comments
Post a Comment