Nano 16bit timer pin?

Hello all,

I'm sorry for the nooby question here, but what pins do I use for the 16bit timer on the Nano? Everything I find refers to pin 5 of the UNO.

There are several pins connected to the 16 bit timer on the Nano (assuming you mean the original Nano, there are several newer ones). Which one do you want to use and why?

The original Arduino Nano uses the same model ATmega328P processor as the Arduino UNO R3 and the pins are numbered the same way. If the Arduino instructions say Pin 5, use Pin 5 on the Nano.

johnwasser:
The original Arduino Nano uses the same model ATmega328P processor as the Arduino UNO R3 and the pins are numbered the same way. If the Arduino instructions say Pin 5, use Pin 5 on the Nano.

Pin D5.

johnwasser:
The original Arduino Nano uses the same model ATmega328P processor as the Arduino UNO R3 and the pins are numbered the same way. If the Arduino instructions say Pin 5, use Pin 5 on the Nano.

On the Uno timer1 is the only 16-bit counter and it controls pins 9 and 10 for PWM and can count pulses on pin 5.

I'm pretty sure the nano pins are numbered the same as the Uno Pins, rather than in any way that reflects the physical layout. If D5 was the right pin on an Uno, you want D5 on the Nano as well. (keeping in mind that the pin ordering is like 1,0, RESET, GND, 2, 3, 4, 5, 6...) This is a clock INPUT for Timer1, but also a compare output for timer0, apparently.

Hi everyone,

Thank you all so much.

I'm trying to make a metal detector. The aim is to measure the frequency of a sine wave and amplitude. (It's not AC it's 1.5V biased 2V above 0V line i think) Have copied this circuit and code:

Source website for metal detector circuit & code

// Arduino based metal detector
// (C)Dzl july 2013
// http://dzlsevilgeniuslair.blogspot.dk/

// Connect search coil oscillator (20-200kHz) to pin 5
// Connect piezo between pin 13 and GND
// Connect NULL button between pin 12 anf GND

// REMEMBER TO PRESS NULL BUTTON AFTER POWER UP!!


#define SET(x,y) (x |=(1<<y))                 //-Bit set/clear macros
#define CLR(x,y) (x &= (~(1<<y)))             // |
#define CHK(x,y) (x & (1<<y))                 // |
#define TOG(x,y) (x^=(1<<y))                  //-+

unsigned long t0=0;         //-Last time
int t=0;                    //-time between ints
unsigned char tflag=0;      //-Measurement ready flag

float SENSITIVITY= 1000.0;  //-Guess what

//-Generate interrupt every 1000 oscillations of the search coil
SIGNAL(TIMER1_COMPA_vect)
{
  OCR1A+=1000;
  t=micros()-t0;
  t0+=t;
  tflag=1;
}

void setup()
{
  pinMode(13,OUTPUT);    //-piezo pin
  digitalWrite(12,HIGH); //-NULL SW. pull up
  //-Set up counter1 to count at pin 5
  TCCR1A=0;
  TCCR1B=0x07;
  SET(TIMSK1,OCF1A);
}
//-Float ABS
float absf(float f)
{
  if(f<0.0)
    return -f;
  else
    return f;
}

int   v0=0;  //-NULL value
float f=0;   //-Measurement value
unsigned int FTW=0;    //-Click generator rate
unsigned int PCW=0;    //-Click generator phase
unsigned long timer=0; //-Click timer
void loop()
{
  if(tflag)
  {
    if(digitalRead(12)==LOW)  //-Check NULL SW.
      v0=t;                   //-Sample new null value
    f=f*0.9+absf(t-v0)*0.1;   //-Running average over 10 samples
    tflag=0;                  //-Reset flag

    float clf=f*SENSITIVITY;  //-Convert measurement to click frequency
    if(clf>10000)           
      clf=10000;
    FTW=clf;
  }
 
  //-Click generator
  if(millis()>timer)
  {
    timer+=10;
    PCW+=FTW;
    if(PCW&0x8000)
    {
      digitalWrite(13,HIGH);
      PCW&=0x7fff;
    }
    else
      digitalWrite(13,LOW);
  }
}

I'm going to put a buzzer on A6 and the Null button on A7 as other pins are taken. Not got anything working yet. Here's the code I've uploaded to my Arduino. Sadly planned on using two coils on the one Arduino but if can only use pin 5 i guess thats not possible too.
Code currently uploaded to my Arduino

 #define SET(x,y) (x |=(1<<y))                 //-Bit set/clear macros
#define CLR(x,y) (x &= (~(1<<y)))             // |
#define CHK(x,y) (x & (1<<y))                 // |
#define TOG(x,y) (x^=(1<<y))                  //-+

unsigned long t0=0;         //-Last time
int t=0;                    //-time between ints
unsigned char tflag=0;      //-Measurement ready flag

float SENSITIVITY= 1000.0;  //-Guess what

//-Generate interrupt every 1000 oscillations of the search coil
SIGNAL(TIMER1_COMPA_vect)
{
  OCR1A+=1000;
  t=micros()-t0;
  t0+=t;
  tflag=1;
}

void setup()
{
  Serial.begin(57600);
  pinMode(A7,INPUT);    //-piezo pin
  pinMode(A6,OUTPUT);    //-piezo pin
 // digitalWrite(A6,HIGH); //-NULL SW. pull up
  //-Set up counter1 to count at pin 5
  TCCR1A=0;
  TCCR1B=0x07;
  SET(TIMSK1,OCF1A);
}
//-Float ABS
float absf(float f)
{
  if(f<0.0)
    return -f;
  else
    return f;
}

int   v0=0;  //-NULL value
float f=0;   //-Measurement value
unsigned int FTW=0;    //-Click generator rate
unsigned int PCW=0;    //-Click generator phase
unsigned long timer=0; //-Click timer
void loop()
{
  if(tflag)
  {
    if(digitalRead(A7)==1)  //-Check NULL SW.
      Serial.println("pressed");
      v0=t;                   //-Sample new null value
    f=f*0.9+absf(t-v0)*0.1;   //-Running average over 10 samples
    tflag=0;                  //-Reset flag

    float clf=f*SENSITIVITY;  //-Convert measurement to click frequency
    if(clf>10000)           
      clf=10000;
    FTW=clf;
  }
 
  //-Click generator
  if(millis()>timer)
  {
    timer+=10;
    PCW+=FTW;
    if(PCW&0x8000)
    {
      digitalWrite(A6,HIGH);
      PCW&=0x7fff;
      Serial.println(f);
    }
    else
      digitalWrite(A6,LOW);
      Serial.println(f);
  }
}

Which Nano do you have?

DopeySnailS:
I'm going to put a buzzer on A6 and the Null button on A7 as other pins are taken.

Taken by what? I don't see anything like that.

jremington:
Which Nano do you have?

I'm not sure, ATmega328P if this helps.

aarg:
Taken by what? I don't see anything like that.

I've seperated the code but it's actually a remote controlled metal detector so pins for the motors h bridge and radio frequency comms module are already taking most of the digital side of the arduino. Can deffinitely rearrange things to free some up though.

DopeySnailS:
I'm going to put a buzzer on A6 and the Null button on A7 as other pins are taken.

WARNING: A6 and A7 can ONLY do analog input (analogRead()). They are just two more inputs to the analog input multiplexer and have none of the digital pin hardware that would allow them to be read or written. You can't use one for an OUTPUT pin at all so I don't think a buzzer will work and you can't use one with digitalRead() (pinMode() INPUT or INPUT_PULLUP) so you will have to supply your own pull-up or pull-down resistor and use analogRead() to see if the "Null button" reads as 0 (LOW) or 1023 (HIGH). Something like "(analogRead(A7)>512)" should produce a HIGH/LOW value very similar to digitalRead().