Pages: [1]   Go Down
Author Topic: Hall Sensor SS451A Weird Behaviour? (Using "Interrupt")  (Read 1049 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

I have a problem with the Hall sensor I'm trying to use. It is a SS451A sensor:

http://ca.mouser.com/ProductDetail/Honeywell/SS451A/?qs=MPfWMdygYOY2ny0hGuKK6Q==

should be non latching, and data sheet can be found here:

http://mouser.com/catalog/specsheets/ProductSheet_SS351_451.pdf

I am running very simple code, just trying to see if the hall sensor will detect the presence of a magnet. The code is as follows:

Quote

volatile unsigned int count;

void setup()
{
  Serial.begin(57600);
  Serial.println ("Start");     // signal initalization done
  attachInterrupt(0, countP, RISING);
  delay(100);
}

void loop()
{
   
}

void countP()
 {
   count++;
   Serial.println (count);
 }


The problem I am having is that when I view the Serial Monitor, the counter is increasing rapidly with no magnet present. I only want the counter to increase when a rising edge is detected. Instead, when I place a magnet near the hall sensor, the counter stops. It seems as if it is doing the opposite of what I want? Any suggestions?
Thank you!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16540
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That device has an open collector output which means you must supply a pull-up resistor to be able to get a valid output signal from it. Try this:

Quote
volatile unsigned int count;

pinMode(2, INPUT);   //set the interrupt0  pin2 to input
digitalWrite(2, HIGH);   // and enable it's internal pull-up resistor
 


 void setup()
{
  Serial.begin(57600);
  Serial.println ("Start");     // signal initalization done
  attachInterrupt(0, countP, FALLING);  // device signals a low when active
  delay(100);
}

void loop()
{
  
}

void countP()
 {
   count++;
   Serial.println (count);
 }


Try that and see if there is a change for the better.

Lefty
« Last Edit: March 02, 2011, 10:18:02 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Works beautifully.

I heard that Arduino had a built in pull up resistor on the digital pins, but I wasn't sure how to use it. That explains it.

Thanks again, you're a real help around here!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16540
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Works beautifully.

I heard that Arduino had a built in pull up resistor on the digital pins, but I wasn't sure how to use it. That explains it.

Thanks again, you're a real help around here!

Your welcome, but you made it very easy by posting the revelant datasheet and posting your code. It takes some posters a long time to understand that the quality and usefulness of answers is  directly proportional to the quality of their posting asking for the help.

Lefty
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I try and give as much info as possible. I figured I was probably just using some kind of feature of the Arduino improperly.

Just out of curiosity, would you happen to know if its possible to run a subroutine in the background? What I mean is, can you run the main task, and an alternate subroutine simultaneously? I would imagine constantly polling the hall sensor in the background isn't very efficient, but I would just like to try it anyways (rather than use an interrupt).

Thanks again,

Chris
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16540
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well it's a single processor chip, so it never can do anything more then one machine instruction at a time. However 16mhz is faster then you might imagine and what may seem inefficient on paper can be duck soup for the chip.
 Interrupts are a nice feature as you have used seen. There are also 'state machine' libraries that set up something that looks like multi-tasking, but really is polling via timed interrupts or polling inquires hidden from view.

 I'm more proficient in hardware then software so you might hold out for other suggestions. Mine would be just get something running that performs the tasks you want done and later see if there might be a better way to structure the sketch. It's always better if you can post a sketch that either works or is close to working, then ask for ideas on improving it. And my rule is if runs without errors, does what I wanted done, then time to move on to the next project no matter how awkward the code may look on paper.  smiley-wink

Lefty
Logged

Pages: [1]   Go Up
Jump to: