Hola a tod@s:
Estoy intentado registrar con Arduino unos pulsos de un proyecto que estoy haciendo. Son pulsos cuadrados de 5 voltios pero con una duración de unos 50 uS. Los pulsos son aleatorios, no se sabe cuando ni cuántos vienen.
He probado a intentar captarlos con las entradas analógicas y las digitales sin resultado. He probado también usando interrupciones, pero nada.
¿Se le ocurre a alguien algo?
Gracias!
Como no puedes captarlos con las interrupciones?
Supongo que te has conectado al pin2 o 3 si fuera un UNO.
Tranquilamente puede capturarlas.
Que necesitas detectar ademas de que este presente el pulso?
Describe en detalle que requieres del pulso, determinar su ancho?
Este código usa la UNIDAD DE CAPTURA asociada al timer 1
// Frequency timer using input capture unit
// Author: Nick Gammon
// Date: 31 August 2013
// Input: Pin D8
volatile boolean first;
volatile boolean triggered;
volatile unsigned long overflowCount;
volatile unsigned long startTime;
volatile unsigned long finishTime;
// timer overflows (every 65536 counts)
ISR (TIMER1_OVF_vect)
{
overflowCount++;
} // end of TIMER1_OVF_vect
ISR (TIMER1_CAPT_vect)
{
// grab counter value before it changes any more
unsigned int timer1CounterValue;
timer1CounterValue = ICR1; // see datasheet, page 117 (accessing 16-bit registers)
unsigned long overflowCopy = overflowCount;
// if just missed an overflow
if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 0x7FFF)
overflowCopy++;
// wait until we noticed last one
if (triggered)
return;
if (first)
{
startTime = (overflowCopy << 16) + timer1CounterValue;
first = false;
return;
}
finishTime = (overflowCopy << 16) + timer1CounterValue;
triggered = true;
TIMSK1 = 0; // no more interrupts for now
} // end of TIMER1_CAPT_vect
void prepareForInterrupts ()
{
noInterrupts (); // protected code
first = true;
triggered = false; // re-arm for next time
// reset Timer 1
TCCR1A = 0;
TCCR1B = 0;
TIFR1 = bit (ICF1) | bit (TOV1); // clear flags so we don't get a bogus interrupt
TCNT1 = 0; // Counter to zero
overflowCount = 0; // Therefore no overflows yet
// Timer 1 - counts clock pulses
TIMSK1 = bit (TOIE1) | bit (ICIE1); // interrupt on Timer 1 overflow and input capture
// start Timer 1, no prescaler
TCCR1B = bit (CS10) | bit (ICES1); // plus Input Capture Edge Select (rising on D8)
interrupts ();
} // end of prepareForInterrupts
void setup ()
{
Serial.begin(115200);
Serial.println("Frequency Counter");
// set up for interrupts
prepareForInterrupts ();
} // end of setup
void loop ()
{
// wait till we have a reading
if (!triggered)
return;
// period is elapsed time
unsigned long elapsedTime = finishTime - startTime;
// frequency is inverse of period, adjusted for clock period
float tiempo = float (elapsedTime*62.5); // each tick is 62.5 ns at 16 MHz
Serial.print ("Pulso: ");
Serial.print (tiempo);
Serial.print (" uSeg.");
// so we can read it
delay (500);
prepareForInterrupts ();
} // end of loop
En principio sólo detectar el pulso y encender un LED (por ejemplo) para verificarlo. Más adelante contar los pulsos y calcular la media por minuto.
bueno ahi tienes como hacerlo, con cada tick a 62.5nSeg puedes medir 50useg con 50useg/62.5nSeg = 800 cuentas
bastante bien.
Usa de entrada Pin D8 o sea pin 8 que es el INPUT CAPTURE del TIMER 1