Pages: [1]   Go Down
Author Topic: Hall sensor readings at high-speed  (Read 1448 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I've been lurking around here for abit, but I never had an account... smiley-wink My issue is this:

I am working on a harddrive clock (essentially the same as this one: link), however I am not using a standard hall sensor.

The hall sensor I am using is salvaged from a defunct blackberry curve 8330, which uses hall sensors for trackball input. I have confirmed that the following datasheet is correct: (link). This sheet shows that the hall sensor is capable of measuring microsecond durations at a minimum (I think). I am supplying the sensor with GND and 5V and am simply interfacing with pin5 via analog input (is this the best way?). There are no capacitors, etc on the output line.



...this is the sensor by the way, it's pretty small!


The issue I am experiencing is that with the simplest code I can write I am not getting delay times (per rotation) of under 30 ms, which is incorrect (5400 rpm == 5.5 ms per rotation).
Code:
double hall = 0, hallpre = 0;
const int baseline = 1023;
const int sensitivity = 20;
boolean state = false;
unsigned long timerotat, timerotatprev, triggertime;

void setup()
{
  Serial.begin(9600);
  Serial.println("Welcome to Paul's HDD Clock debug output!");
  delay(100);
}

void loop()
{
 timerotat=millis();              // save the current time while magnet is NOT on sensor
 hall = analogRead(A1);
 while((hall < (baseline-sensitivity)) ) //& ((millis()-triggertime)>1))  //<- use with a filter value to stop flickering stopped on sensor
 {
   if (!state)
   {
     digitalWrite(13,1);
     state=true;
     timerotatprev=timerotat;           //the magnet crossed the sensor, output the current value - previous for rotation time after spun-up
   }
   hall = analogRead(A1);
 };
 state=false;
 digitalWrite(13,0);
}

Here is typical output once the drive is spun up at 5400 rpm.
Code:
passed in: 34ms
passed in: 34ms
passed in: 33ms
passed in: 33ms
passed in: 34ms
passed in: 34ms
passed in: 33ms
passed in: 34ms
passed in: 33ms
passed in: 34ms
passed in: 33ms
passed in: 34ms
Any help would be awesome!
Logged

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

That hall effect sensor is a digital sensor, it either sees a magnetic field of sufficient strength or it does not, and outputs either a 0 or +5vdc voltage, nothing in between those two voltages. You should not be reading it as a analog value, but rather use a digitalRead function. You need to time the time period between successive pulses, perhaps using the pulseIn function. I'm afraid you really need a complete rewrite of your sketch using the proper approach.

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...outputs either a 0 or +5vdc voltage, nothing in between those two voltages.

Great!

I was worried about the lack of difference between the saturated reading and the unsaturated reading too (1023 -> 922 approx), didn't seem surefire enough. I'll give this a try and post back with results tomorrow using digitalRead().
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I ended up finding the following circuit diagram for the sparkfun breakout board which uses the same hall sensors.
        (link)
I've just constructed the same circuit but was unable to get a digitalRead() of any value other than 1. The voltage still dips by approx 0.6 volts when the magnet is nearby though. Is there any reason that I cannot just digitalRead() from the sensor with the output pulled up to Vcc? I'm polling it constantly for pulses so interrupts shouldn't matter at this point right?
Logged

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

Quote
Is there any reason that I cannot just digitalRead() from the sensor with the output pulled up to Vcc? I'm polling it constantly for pulses so interrupts shouldn't matter at this point right?

What value resistor are you using to pull-up the sensor output pin to Vcc?

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What value resistor are you using to pull-up the sensor output pin to Vcc?

I'm using a 10k resistor at the moment, I also attached a 0.1 uf capacitor on the VCC and GND lines to no avail.
Logged

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

What value resistor are you using to pull-up the sensor output pin to Vcc?

I'm using a 10k resistor at the moment, I also attached a 0.1 uf capacitor on the VCC and GND lines to no avail.

Can you post your code, showing how you are doing the digitRead() for this sensor?

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your code, showing how you are doing the digitRead() for this sensor?

I'd love to! (I've removed commented out lines)

Code:
void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.println(String(digitalRead(9)));

I was just hoping that I'd be able to poll it this way, not sure if I need to implement pulsein() to read the sensor.
Logged

Pages: [1]   Go Up
Jump to: