Go Down

Topic: what input pin is it using? (Read 5 times) previous topic - next topic

Joes

hi thanks for your replies on that link http://www.gammon.com.au/forum/?id=11488 there is a lot of stuff on that website to get your head wrapped around lol i have come up with this compiles fine but somethings telling me im missing something here?

Code: [Select]



volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
{
// handle pin change interrupt for D0 to D7 here
}  // end of PCINT2_vect


void setup ()
  {
  Serial.begin(9600); 
  // pin change interrupt (example for D0)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

void loop(){
 
   if(rpmcount>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      //Serial.println(rpmcount,DEC);
      rpmcount = 0;
      Serial.println(rpm,DEC);
   }
}



p.s i dont wont the led output

UKHeliBob


somethings telling me im missing something here?

How about something to update rpmcount ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Joes

Code: [Select]



volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
{
   rpmcount;
// handle pin change interrupt for D0 to D7 here
}  // end of PCINT2_vect


void setup ()
  {
  Serial.begin(9600); 
  // pin change interrupt (example for D0)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

void loop(){
 
   if(rpmcount>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      //Serial.println(rpmcount,DEC);
      rpmcount = 0;
      Serial.println(rpm,DEC);
   }
}



better?

Grumpy_Mike

Quote
better?

No try:-

Code: [Select]

rpmcount++;

PeterH

You started with a sketch that did more or less what you wanted, in a fairly simple way - no messing with hardware registers and so on.

Why have you thrown that away and started again with a more complex approach?
I only provide help via the forum - please do not contact me for private consultancy.

Go Up