Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Misurazione periodo o frequenza con Arduino

Progetti, interfacciamento, discussioni varie su questa piattaforma.

Moderatori: Foto UtenteWALTERmwp, Foto Utentexyz

0
voti

[11] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utentelorenrus » 24 apr 2020, 23:11

Mi spieghi le tue perplessità e cosa, secondo te, potrebbe non essere corretto ?

Grazie ad entrambi per le risposte, confrontandosi si impara sempre :)
Avatar utente
Foto Utentelorenrus
5 2
New entry
New entry
 
Messaggi: 74
Iscritto il: 30 ott 2018, 18:30

0
voti

[12] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utenteboiler » 25 apr 2020, 9:47

lorenrus ha scritto:Devo verificare la frequenza o il periodo e il duty cycle.

Ti conviene usare un comparatore di fase simile a quello usato nei PLL.
Manda i due segnali agli ingressi di una porta XOR.
In uscita avrai degli impulsi positivi che indicano i momenti nei quali le due onde differiscono.
Se li filtri con un passa-basso ottieni una tensione proporzionale alla durata di questi momenti.

Se questa tensione, è costante, i due segnali hanno la stessa frequenza (o uno è un multiplo dell'altro).
Se la tensione varia, allora le tensioni frequenze sono diverse.

Tu vuoi anche informazioni sul duty-cycle, queste le ottieni con un passa basso sul segnale stesso.

Boiler
Avatar utente
Foto Utenteboiler
26,4k 5 9 13
G.Master EY
G.Master EY
 
Messaggi: 5613
Iscritto il: 9 nov 2011, 12:27

0
voti

[13] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utentelorenrus » 25 apr 2020, 10:09

Ciao e grazie sempre per la risposta.

Si questa soluzione mi torna però purtroppo ho omesso di dire che la scheda che mi hanno dato è oramai fatta e stata pensata da altri così. Non posso aggiungere nessun componente HW in più.-
Avatar utente
Foto Utentelorenrus
5 2
New entry
New entry
 
Messaggi: 74
Iscritto il: 30 ott 2018, 18:30

0
voti

[14] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utenteboiler » 25 apr 2020, 10:14

E allora che implementino questi altri la misurazione. I loro cervelloni avranno sicuramente pensato anche ad un'architettura di misura adeguata.

Boiler
Avatar utente
Foto Utenteboiler
26,4k 5 9 13
G.Master EY
G.Master EY
 
Messaggi: 5613
Iscritto il: 9 nov 2011, 12:27

0
voti

[15] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto UtenteMarcoD » 25 apr 2020, 10:26

Anni fa avevo utiizzato una funzione per misurare con arduino la frequenza di un segnale fino a qualche MHz.
Se può aiutarti ti allego il sorgente, che non avevo analizzato, ma che funzionava.
Se interessa posso inviarti il mio programma che la utilizzava.

Codice: Seleziona tutto
FreqCounter file CPP 4,40 kB

/*
  FreqCounter.h -
  Using Counter1 for counting Frequency on T1 / PD5 / digitalPin 5
  Using Timer2 for Gatetime generation

  Martin Nawrath KHM LAB3
  Kunsthochschule für Medien Köln
  Academy of Media Arts
  http://www.khm.de
  http://interface.khm.de/index.php/labor/experimente/
 
  History:
     Dec/08 - V0.0

   

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

*/



#include <FreqCounter.h>


unsigned long FreqCounter::f_freq;

volatile unsigned char FreqCounter::f_ready;
volatile unsigned char FreqCounter::f_mlt;
volatile unsigned int FreqCounter::f_tics;
volatile unsigned int FreqCounter::f_period;
volatile unsigned int FreqCounter::f_comp;



void FreqCounter::start(int ms) {

#if defined (__AVR_ATmega168__)

  f_period=ms/2;
  if (f_comp ==0) f_comp=1;
   
   // hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCR1A=0;                 // reset timer/counter1 control register A
  TCCR1B=0;                 // reset timer/counter1 control register A
  TCNT1=0;                 // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin T1 ( arduino pin 5)
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCR1B ,CS10);       // External clock source on T1 pin. Clock on rising edge.
  sbi (TCCR1B ,CS11);
  sbi (TCCR1B ,CS12);


  // timer2 setup / is used for frequency measurement gatetime generation
  // timer 2 presaler set to 256 / timer 2 clock = 16Mhz / 256 = 62500 Hz
  TCCR2A=0;
  TCCR2B=0;
  cbi (TCCR2B ,CS20);
  sbi (TCCR2B ,CS21);
  sbi (TCCR2B ,CS22);

  //set timer2 to CTC Mode
  cbi (TCCR2A ,WGM20); 
  sbi (TCCR2A ,WGM21);
  cbi (TCCR2B ,WGM22);
  OCR2A = 124;   


  f_ready=0;                // reset period measure flag
  f_tics=0;                 // reset interrupt counter
  sbi (GTCCR,PSRASY);       // reset presacler counting
  TCNT2=0;                  // timer2=0
  TCNT1=0;                  // Counter1 = 0

  cbi (TIMSK0,TOIE0);       // disable Timer0  //disable  millis and delay
  sbi (TIMSK2,OCIE2A);      // enable Timer2 Interrupt

  TCCR1B = TCCR1B | 7;      //  Counter Clock source = pin T1 , start counting now

#endif
}



//******************************************************************
//  Timer2 Interrupt Service is invoked by hardware Timer2 every 2ms = 500 Hz
//  16Mhz / 256 / 125 = 500 Hz
//  here the gatetime generation for freq. measurement takes place:

ISR(TIMER2_COMPA_vect) {
         // multiple 2ms = gate time = 100 ms
if (FreqCounter::f_tics >= FreqCounter::f_period) {            
                        // end of gate time, measurement ready

            // GateCalibration Value, set to zero error with reference frequency counter
    delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec
    TCCR1B = TCCR1B & ~7;            // Gate Off  / Counter T1 stopped
    cbi (TIMSK2,OCIE2A);             // disable Timer2 Interrupt
    sbi (TIMSK0,TOIE0);              // enable Timer0 again // millis and delay
    FreqCounter::f_ready=1;             // set global flag for end count period
   
                                     // calculate now frequeny value
    FreqCounter::f_freq=0x10000 * FreqCounter::f_mlt;  // mult #overflows by 65636
    FreqCounter::f_freq += TCNT1;         // add counter1 value
    FreqCounter::f_mlt=0;

  }
  FreqCounter::f_tics++;               // count number of interrupt events
  if (TIFR1 & 1) {                   // if Timer/Counter 1 overflow flag
    FreqCounter::f_mlt++;               // count number of Counter1 overflows
    sbi(TIFR1,TOV1);                 // clear Timer/Counter 1 overflow flag
  }
  // PORTB = PORTB ^ 32;              // int activity test
}

.................
FreqCounter file H  675 byte
.................

/*
  FreqCounter.h - Library for a Frequency Counter c.
  Created by Martin Nawrath, KHM Lab3, Dec. 2008
  Released into the public domain.
*/



#ifndef FreqCounter_h
#define FreqCounter_h

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#include <avr/interrupt.h>
#include <WProgram.h>

namespace FreqCounter {

   extern unsigned long f_freq;
   extern volatile unsigned char f_ready;
   extern volatile unsigned char f_mlt;
   extern volatile unsigned int f_tics;
   extern volatile unsigned int f_period;
   extern volatile unsigned int f_comp;
   
   void start(int ms);
   
   
}

#endif


...............
Programma di esempio

The Frequency input is fixed to digital pin 5. This pin is mapped to the alternate port
function T1 which is the input 16 Bit Hardware Counter1. To obtain a higher resolution than 16 Bit,
the counter overflows are counted also and are calculated with the counter value to the final
long integer result. The Frequency Source output must have a digital level so that weak Signals have
to be amplified for instance by an single transistor or a 74HC14 inverter.
The maximum input frequency is about 8 MHz when signal duty cycle is 50%.
If you like to measure higher frequencies you have to use an prescaler or divider circuit
which can be used from other counter projects published in the web.
The Gate Time for the counting period can be chosen in the start() function where values
of 10, 100 or 1000 ms are practicable for a resolution of 100, 10 and 1 Hz but any value can be used.
The internal resolution of the gatetime is 2 ms so that the time can be varied in the increment of 2.
If you wish to minimize the indication error the value of FreqCounter::f_comp variable can compensate
slight gatetime errors. Compared to an commercial ACECO counter it is possible to trim the deviation
to almost zero over the whole range. For gatetimes of 10,100,100 the values 1, 10 and 100 where found
to be good for our Duemilanova boards.
................

#include <FreqCounter.h>
void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println ("Frequency Counter");
}
long int frq;
Void loop() {
FreqCounter::f_comp= 8; // Set compensation to 12
FreqCounter::start(100); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0) //wait until counter ready
frq=FreqCounter::f_freq; // read result
Serial.println(frq); // print result
delay(20);
}
Avatar utente
Foto UtenteMarcoD
12,2k 5 9 13
Master EY
Master EY
 
Messaggi: 6696
Iscritto il: 9 lug 2015, 16:58
Località: Torino

0
voti

[16] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utentelorenrus » 25 apr 2020, 10:39

MarcoD ha scritto:Anni fa avevo utiizzato una funzione per misurare con arduino la frequenza di un segnale fino a qualche MHz.
Se può aiutarti ti allego il sorgente, che non avevo analizzato, ma che funzionava.
Se interessa posso inviarti il mio programma che la utilizzava.

Codice: Seleziona tutto
FreqCounter file CPP 4,40 kB

/*
  FreqCounter.h -
  Using Counter1 for counting Frequency on T1 / PD5 / digitalPin 5
  Using Timer2 for Gatetime generation

  Martin Nawrath KHM LAB3
  Kunsthochschule für Medien Köln
  Academy of Media Arts
  http://www.khm.de
  http://interface.khm.de/index.php/labor/experimente/
 
  History:
     Dec/08 - V0.0

   

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

*/



#include <FreqCounter.h>


unsigned long FreqCounter::f_freq;

volatile unsigned char FreqCounter::f_ready;
volatile unsigned char FreqCounter::f_mlt;
volatile unsigned int FreqCounter::f_tics;
volatile unsigned int FreqCounter::f_period;
volatile unsigned int FreqCounter::f_comp;



void FreqCounter::start(int ms) {

#if defined (__AVR_ATmega168__)

  f_period=ms/2;
  if (f_comp ==0) f_comp=1;
   
   // hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCR1A=0;                 // reset timer/counter1 control register A
  TCCR1B=0;                 // reset timer/counter1 control register A
  TCNT1=0;                 // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin T1 ( arduino pin 5)
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCR1B ,CS10);       // External clock source on T1 pin. Clock on rising edge.
  sbi (TCCR1B ,CS11);
  sbi (TCCR1B ,CS12);


  // timer2 setup / is used for frequency measurement gatetime generation
  // timer 2 presaler set to 256 / timer 2 clock = 16Mhz / 256 = 62500 Hz
  TCCR2A=0;
  TCCR2B=0;
  cbi (TCCR2B ,CS20);
  sbi (TCCR2B ,CS21);
  sbi (TCCR2B ,CS22);

  //set timer2 to CTC Mode
  cbi (TCCR2A ,WGM20); 
  sbi (TCCR2A ,WGM21);
  cbi (TCCR2B ,WGM22);
  OCR2A = 124;   


  f_ready=0;                // reset period measure flag
  f_tics=0;                 // reset interrupt counter
  sbi (GTCCR,PSRASY);       // reset presacler counting
  TCNT2=0;                  // timer2=0
  TCNT1=0;                  // Counter1 = 0

  cbi (TIMSK0,TOIE0);       // disable Timer0  //disable  millis and delay
  sbi (TIMSK2,OCIE2A);      // enable Timer2 Interrupt

  TCCR1B = TCCR1B | 7;      //  Counter Clock source = pin T1 , start counting now

#endif
}



//******************************************************************
//  Timer2 Interrupt Service is invoked by hardware Timer2 every 2ms = 500 Hz
//  16Mhz / 256 / 125 = 500 Hz
//  here the gatetime generation for freq. measurement takes place:

ISR(TIMER2_COMPA_vect) {
         // multiple 2ms = gate time = 100 ms
if (FreqCounter::f_tics >= FreqCounter::f_period) {            
                        // end of gate time, measurement ready

            // GateCalibration Value, set to zero error with reference frequency counter
    delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec
    TCCR1B = TCCR1B & ~7;            // Gate Off  / Counter T1 stopped
    cbi (TIMSK2,OCIE2A);             // disable Timer2 Interrupt
    sbi (TIMSK0,TOIE0);              // enable Timer0 again // millis and delay
    FreqCounter::f_ready=1;             // set global flag for end count period
   
                                     // calculate now frequeny value
    FreqCounter::f_freq=0x10000 * FreqCounter::f_mlt;  // mult #overflows by 65636
    FreqCounter::f_freq += TCNT1;         // add counter1 value
    FreqCounter::f_mlt=0;

  }
  FreqCounter::f_tics++;               // count number of interrupt events
  if (TIFR1 & 1) {                   // if Timer/Counter 1 overflow flag
    FreqCounter::f_mlt++;               // count number of Counter1 overflows
    sbi(TIFR1,TOV1);                 // clear Timer/Counter 1 overflow flag
  }
  // PORTB = PORTB ^ 32;              // int activity test
}

.................
FreqCounter file H  675 byte
.................

/*
  FreqCounter.h - Library for a Frequency Counter c.
  Created by Martin Nawrath, KHM Lab3, Dec. 2008
  Released into the public domain.
*/



#ifndef FreqCounter_h
#define FreqCounter_h

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#include <avr/interrupt.h>
#include <WProgram.h>

namespace FreqCounter {

   extern unsigned long f_freq;
   extern volatile unsigned char f_ready;
   extern volatile unsigned char f_mlt;
   extern volatile unsigned int f_tics;
   extern volatile unsigned int f_period;
   extern volatile unsigned int f_comp;
   
   void start(int ms);
   
   
}

#endif


...............
Programma di esempio

The Frequency input is fixed to digital pin 5. This pin is mapped to the alternate port
function T1 which is the input 16 Bit Hardware Counter1. To obtain a higher resolution than 16 Bit,
the counter overflows are counted also and are calculated with the counter value to the final
long integer result. The Frequency Source output must have a digital level so that weak Signals have
to be amplified for instance by an single transistor or a 74HC14 inverter.
The maximum input frequency is about 8 MHz when signal duty cycle is 50%.
If you like to measure higher frequencies you have to use an prescaler or divider circuit
which can be used from other counter projects published in the web.
The Gate Time for the counting period can be chosen in the start() function where values
of 10, 100 or 1000 ms are practicable for a resolution of 100, 10 and 1 Hz but any value can be used.
The internal resolution of the gatetime is 2 ms so that the time can be varied in the increment of 2.
If you wish to minimize the indication error the value of FreqCounter::f_comp variable can compensate
slight gatetime errors. Compared to an commercial ACECO counter it is possible to trim the deviation
to almost zero over the whole range. For gatetimes of 10,100,100 the values 1, 10 and 100 where found
to be good for our Duemilanova boards.
................

#include <FreqCounter.h>
void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println ("Frequency Counter");
}
long int frq;
Void loop() {
FreqCounter::f_comp= 8; // Set compensation to 12
FreqCounter::start(100); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0) //wait until counter ready
frq=FreqCounter::f_freq; // read result
Serial.println(frq); // print result
delay(20);
}



Ciao e grazie davvero


Si se puoi inviarmi il main mi faresti un favore così capisco bene come lo hai utilizzato.
Avatar utente
Foto Utentelorenrus
5 2
New entry
New entry
 
Messaggi: 74
Iscritto il: 30 ott 2018, 18:30

0
voti

[17] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utentelorenrus » 25 apr 2020, 10:47

MarcoD ha scritto:Anni fa avevo utiizzato una funzione per misurare con arduino la frequenza di un segnale fino a qualche MHz.
Se può aiutarti ti allego il sorgente, che non avevo analizzato, ma che funzionava.
Se interessa posso inviarti il mio programma che la utilizzava.

Codice: Seleziona tutto
FreqCounter file CPP 4,40 kB

/*
  FreqCounter.h -
  Using Counter1 for counting Frequency on T1 / PD5 / digitalPin 5
  Using Timer2 for Gatetime generation

  Martin Nawrath KHM LAB3
  Kunsthochschule für Medien Köln
  Academy of Media Arts
  http://www.khm.de
  http://interface.khm.de/index.php/labor/experimente/
 
  History:
     Dec/08 - V0.0

   

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

*/



#include <FreqCounter.h>


unsigned long FreqCounter::f_freq;

volatile unsigned char FreqCounter::f_ready;
volatile unsigned char FreqCounter::f_mlt;
volatile unsigned int FreqCounter::f_tics;
volatile unsigned int FreqCounter::f_period;
volatile unsigned int FreqCounter::f_comp;



void FreqCounter::start(int ms) {

#if defined (__AVR_ATmega168__)

  f_period=ms/2;
  if (f_comp ==0) f_comp=1;
   
   // hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCR1A=0;                 // reset timer/counter1 control register A
  TCCR1B=0;                 // reset timer/counter1 control register A
  TCNT1=0;                 // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin T1 ( arduino pin 5)
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCR1B ,CS10);       // External clock source on T1 pin. Clock on rising edge.
  sbi (TCCR1B ,CS11);
  sbi (TCCR1B ,CS12);


  // timer2 setup / is used for frequency measurement gatetime generation
  // timer 2 presaler set to 256 / timer 2 clock = 16Mhz / 256 = 62500 Hz
  TCCR2A=0;
  TCCR2B=0;
  cbi (TCCR2B ,CS20);
  sbi (TCCR2B ,CS21);
  sbi (TCCR2B ,CS22);

  //set timer2 to CTC Mode
  cbi (TCCR2A ,WGM20); 
  sbi (TCCR2A ,WGM21);
  cbi (TCCR2B ,WGM22);
  OCR2A = 124;   


  f_ready=0;                // reset period measure flag
  f_tics=0;                 // reset interrupt counter
  sbi (GTCCR,PSRASY);       // reset presacler counting
  TCNT2=0;                  // timer2=0
  TCNT1=0;                  // Counter1 = 0

  cbi (TIMSK0,TOIE0);       // disable Timer0  //disable  millis and delay
  sbi (TIMSK2,OCIE2A);      // enable Timer2 Interrupt

  TCCR1B = TCCR1B | 7;      //  Counter Clock source = pin T1 , start counting now

#endif
}



//******************************************************************
//  Timer2 Interrupt Service is invoked by hardware Timer2 every 2ms = 500 Hz
//  16Mhz / 256 / 125 = 500 Hz
//  here the gatetime generation for freq. measurement takes place:

ISR(TIMER2_COMPA_vect) {
         // multiple 2ms = gate time = 100 ms
if (FreqCounter::f_tics >= FreqCounter::f_period) {            
                        // end of gate time, measurement ready

            // GateCalibration Value, set to zero error with reference frequency counter
    delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec
    TCCR1B = TCCR1B & ~7;            // Gate Off  / Counter T1 stopped
    cbi (TIMSK2,OCIE2A);             // disable Timer2 Interrupt
    sbi (TIMSK0,TOIE0);              // enable Timer0 again // millis and delay
    FreqCounter::f_ready=1;             // set global flag for end count period
   
                                     // calculate now frequeny value
    FreqCounter::f_freq=0x10000 * FreqCounter::f_mlt;  // mult #overflows by 65636
    FreqCounter::f_freq += TCNT1;         // add counter1 value
    FreqCounter::f_mlt=0;

  }
  FreqCounter::f_tics++;               // count number of interrupt events
  if (TIFR1 & 1) {                   // if Timer/Counter 1 overflow flag
    FreqCounter::f_mlt++;               // count number of Counter1 overflows
    sbi(TIFR1,TOV1);                 // clear Timer/Counter 1 overflow flag
  }
  // PORTB = PORTB ^ 32;              // int activity test
}

.................
FreqCounter file H  675 byte
.................

/*
  FreqCounter.h - Library for a Frequency Counter c.
  Created by Martin Nawrath, KHM Lab3, Dec. 2008
  Released into the public domain.
*/



#ifndef FreqCounter_h
#define FreqCounter_h

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#include <avr/interrupt.h>
#include <WProgram.h>

namespace FreqCounter {

   extern unsigned long f_freq;
   extern volatile unsigned char f_ready;
   extern volatile unsigned char f_mlt;
   extern volatile unsigned int f_tics;
   extern volatile unsigned int f_period;
   extern volatile unsigned int f_comp;
   
   void start(int ms);
   
   
}

#endif


...............
Programma di esempio

The Frequency input is fixed to digital pin 5. This pin is mapped to the alternate port
function T1 which is the input 16 Bit Hardware Counter1. To obtain a higher resolution than 16 Bit,
the counter overflows are counted also and are calculated with the counter value to the final
long integer result. The Frequency Source output must have a digital level so that weak Signals have
to be amplified for instance by an single transistor or a 74HC14 inverter.
The maximum input frequency is about 8 MHz when signal duty cycle is 50%.
If you like to measure higher frequencies you have to use an prescaler or divider circuit
which can be used from other counter projects published in the web.
The Gate Time for the counting period can be chosen in the start() function where values
of 10, 100 or 1000 ms are practicable for a resolution of 100, 10 and 1 Hz but any value can be used.
The internal resolution of the gatetime is 2 ms so that the time can be varied in the increment of 2.
If you wish to minimize the indication error the value of FreqCounter::f_comp variable can compensate
slight gatetime errors. Compared to an commercial ACECO counter it is possible to trim the deviation
to almost zero over the whole range. For gatetimes of 10,100,100 the values 1, 10 and 100 where found
to be good for our Duemilanova boards.
................

#include <FreqCounter.h>
void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println ("Frequency Counter");
}
long int frq;
Void loop() {
FreqCounter::f_comp= 8; // Set compensation to 12
FreqCounter::start(100); // Start counting with gatetime of 100ms
while (FreqCounter::f_ready == 0) //wait until counter ready
frq=FreqCounter::f_freq; // read result
Serial.println(frq); // print result
delay(20);
}


Ora mi stavo leggendo il codice

Ho notato che fa uso del timer interno con l’interrupt.
Io nel mio primo messaggio anche utilizzo questo tipo di soluzione attraverso la funzione Pulse in, Solamente che superati 50 kHerz mi mi inizia a dare dei valori errati.

Io questi teste li sto facendo con Arduino mega E con una frequenza di 16 MHz.
Tu con quale Arduino avevi provato questo codice che ti leggeva bene anche le frequenze nell’intorno dei mega Herz ?

Grazie
Avatar utente
Foto Utentelorenrus
5 2
New entry
New entry
 
Messaggi: 74
Iscritto il: 30 ott 2018, 18:30

0
voti

[18] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto UtenteMarcoD » 25 apr 2020, 10:52

Guarda qui:
blog.elettronicain.it/.../uploads/2011/07/Analiz-Antenna-IK1PXM.pdf

http://blog.elettronicain.it/wp-content ... IK1PXM.pdf

Il listato è sul fondo dell'articolo. Se proprio serve
Dovrei avere il file xx.ino da qualche parte.

Era un arduino con clock a 16 MHz.
sono passati 10 anni !!! devo rinfrescare i ricordi.

corretto link...

BUON 25 APRILE :!:
Avatar utente
Foto UtenteMarcoD
12,2k 5 9 13
Master EY
Master EY
 
Messaggi: 6696
Iscritto il: 9 lug 2015, 16:58
Località: Torino

0
voti

[19] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utentelorenrus » 25 apr 2020, 11:11

Certo certo :)

Aprendo il link su internet non mi si apre nulla
Avatar utente
Foto Utentelorenrus
5 2
New entry
New entry
 
Messaggi: 74
Iscritto il: 30 ott 2018, 18:30

0
voti

[20] Re: Misurazione periodo o frequenza con Arduino

Messaggioda Foto Utentelorenrus » 25 apr 2020, 11:12

MarcoD ha scritto:Guarda qui:
blog.elettronicain.it/.../uploads/2011/07/Analiz-Antenna-IK1PXM.pdf

http://blog.elettronicain.it/wp-content ... IK1PXM.pdf

Il listato è sul fondo dell'articolo. Se proprio serve
Dovrei avere il file xx.ino da qualche parte.

Era un arduino con clock a 16 MHz.
sono passati 10 anni !!! devo rinfrescare i ricordi.

corretto link...

BUON 25 APRILE :!:



Ah okok ecco.

Ora lo guardo subito.

Buon 25 aprile a tutti voi :)
Avatar utente
Foto Utentelorenrus
5 2
New entry
New entry
 
Messaggi: 74
Iscritto il: 30 ott 2018, 18:30

PrecedenteProssimo

Torna a Arduino

Chi c’è in linea

Visitano il forum: Nessuno e 8 ospiti