Go Down

Topic: Hall Sensor SS451A Weird Behaviour? (Using "Interrupt") (Read 1 time) previous topic - next topic

doublec4

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!

retrolefty

#1
Mar 03, 2011, 04:16 am Last Edit: Mar 03, 2011, 04:18 am by retrolefty Reason: 1
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

doublec4

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!

retrolefty


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

doublec4

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

retrolefty

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.  ;)

Lefty

Go Up