Pages: 1 [2] 3 4 5   Go Down
Author Topic: what input pin is it using?  (Read 4036 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

o yes of course

here i am now with the 3x hall input's

Code:


volatile int rpm1count;
volatile int rpm2count;
volatile int rpm3count;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
 {
   rpm1count++;
   rpm2count++;
   rpm3count++;
 // handle pin change interrupt for D0 to D7 here
 }  // end of PCINT2_vect


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

void loop(){
 
   if(rpm1count>=5) {
      rpm=(60000*rpm1count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm1count = 0;
      Serial.println("rear left");
      Serial.println(rpm,DEC);
   }
   
      if(rpm2count>=5) {
      rpm=(60000*rpm2count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm2count = 0;
      Serial.println("rear write");
      Serial.println(rpm,DEC);
   }
   
      if(rpm3count>=5) {
      rpm=(60000*rpm3count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm3count = 0;
      Serial.println("rear prob");
      Serial.println(rpm,DEC);
   }
}


Quote

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?

for a start i need 3 hall inputs as stated above but on the original code i could only run 2
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 597
Posts: 33311
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So you have three sensors and you increment all three counters when any one goes off!!!

You don't use the pin change interrupt like that anyway.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

So you have three sensors and you increment all three counters when any one goes off!!!

You don't use the pin change interrupt like that anyway.


ok could you show me a beter way of doing it?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 4704
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just check the pins with a port read at the start of loop() and don't fart around with delays or other blocking code. A fast loop() can read and evaluate, and report/store data for 3 pins many times per millisecond. Is > 1000 checks per second fast enough?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i could do it in a port read like you said but this will be linking up with some other code i already have, there is no delays in it will it still be fine as this might be seeing some high rpm's?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 597
Posts: 33311
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
ok could you show me a beter way of doing it?
Better than "totally wrong and will not work at all", is easy.

This project:-
http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html
Uses the pin change interrupt to monitor 6 pulse inputs. Maybe looking at that code would help you.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

now im more confused looking at that lol any one got a simple example thay can post?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 4704
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

New to forum, check your private messages... look upper right under the Search box.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes and i do not have any new messages?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 4704
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OOOOPS! Sorry, wrong thread!

How many reads/second will the high rpm's require? Assuming 1 magnet on a shaft at 10000 rpm I get ~167 reads/second giving 6 milliseconds per cycle though the sensor will be high for a much shorter time.
An Arduino running spare code can make digital reads with minor processing in under 5 microseconds. I have sensor code that does a digital read, unsigned long increment and unsigned long compare ( if statement ) is just over 1 usec per while loop. I give an extra 60 cycles for 5 usecs.

The code you showed in the first post has no foot-dragging parts and uses millis for timing.

You know that if you pass a magnet under a coil that the speed of the magnet will affect how much power is induced in the coil? So maybe you don't have to count rpms.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well my hall sensor is going to be an abs sensor on a car so theres quite a few triggers per revolution havent counted exactly but were looking at about 60, and the revolutions will depend on how fast the car is. so what do you think?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 4704
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ABS as in the braking system? So rpm is rpm of the wheel?

Do you have multiple sensors or multiple magnets activating a single sensor?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
ABS as in the braking system? So rpm is rpm of the wheel?
yes

Quote
Do you have multiple sensors or multiple magnets activating a single sensor?

3x sensors with approxmatly 60 triggers per revolution


basically what im trying to do is for my arduino to look at 2 of the sensors and pick the fastest travelling one and compare it against the 3rd one if it is going slower than the 3rd sensor then to execute another piece of code
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 4704
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

3 sensors on 1 wheel? Well, it's for ABS... how to know what they measure?

Do they all measure rotation of the same wheel?
Do you have data (including time and maybe speed) from any 1 sensor?

A 28" diameter wheel turns about 12 times a second at 60 mph (88 f/s).

12 rps x 60 magnets is only 720 pulses per second, but again how long are the pulses? The hall sensor only detects the magnet for a limited time, not 1/720th of a second so you have less time than that to catch the signal.
That stated, you might be able to use pulseIn to know the speed of the wheel from just one magnet going by one (but maybe not just any one) sensor.

If I was trying to find answers, I would collect related data first.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no 3 sensors one on the left wheel and one on the right and one on the prop shaft what is on 1 to 1 ratio

if i have to use a different sensor so we now what it is that is fine
maybe somthing like this;
http://uk.rs-online.com/web/p/magnetic-pickups/2355706/?searchTerm=235-5706&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E2C5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D424552267573743D3233352D353730362677633D4E4F4E4526


this is the trigger wheel
http://img.photobucket.com/albums/v626/shaheenramsay/9N/ABSSpeedSensor.jpg
or i can use somthing like this to
http://www.millersmule.com/MillersMuleStore/45-177-thickbox_default/trigger-wheel-mounting.jpg
Logged

Pages: 1 [2] 3 4 5   Go Up
Jump to: