Go Down

Topic: Control DC motor on/off with Hall Effect Sensor counts (Read 12165 times) previous topic - next topic

gknapp19

I'm trying to control the number of rotations of a 24V DC motor using the two latching Hall Sensors. I'm using interrupts to count and getting far too many counts (1.4x +). Is my code faulty or my approach?

/* Motor (not brushless) with two latching Hall Sensors (A3282)
   Sensors are triggered twice for each motor shaft rotation.
   One sensor cycle is about 14.1ms (2 cycles / rotation) or
   appx. 2128 RPM for the motor.
   Signal stays low for about 3.9ms, high for 10.2ms
   Should record about 71 half rotations per second.
   I'm getting far greater than that.
*/

volatile long int halfRot;        //half rotation
volatile int flagA;               //flag for sensor A
volatile int flagB;               //flag for sensor B
int oldRot=0;                     //prior rotational 1/2 count

void setup()
{
   Serial.begin(9600);
   attachInterrupt(0, hall_A, FALLING);
   attachInterrupt(1, hall_B, FALLING);
   digitalWrite(2, HIGH);
   digitalWrite(3, HIGH);
   
   halfRot = 0;
   flagA = 0;
   flagB = 0;
}

  void loop() {
    if(halfRot != oldRot) {
      Serial.println(halfRot);
      oldRot=halfRot;
    }
  }

  void hall_A() {
    if(flagB) {
      halfRot++;
      flagB=0;
    }
    else
      flagA=1;
  }

  void hall_B() {
    if(flagA) {
      halfRot++;
      flagA=0;
    }
    else
      flagB=1;
  }

MarkT

What is the magnet setup that the hall sensors are detecting?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

gknapp19

The motor is commercially produced. The magnet setup is unknown.
However, O-Scope traces provide the following:
10.2ms from sensor high to sensor low.
3.8ms from sensor low to sensor high.
Again - these are latching sensors.

MarkT

I don't understand why your code is attempting to do quadrature decoding - are
the sensors meant to be quadrature?  The M/S ratio is wrong if so.

Do you have photo from the oscilloscope showing A and B waveforms?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

gknapp19

Waveform doesn't look quite like quadrature (had to google it). What is m/s ratio?

Scope trace attached. Upper trace is A, lower trace B.

I will use relays to chose motor polarity and will therefore know motor direction. I need to be able to run the motor a specified number of revolutions at specified times. The motor output shaft is geared down 236:1 - then meshed with a slew bearing.

gknapp19

This motor drives a solar tracker for a solar array. I must have an interrupt that counts the Hall sensors reliably to be able to track the solar azimuth. With 2 counts per motor revolution and a 236:1 gear reduction to the output shaft; 10 revolutions of the output shaft should provide 2 x 236 x 10 = 4720 counts. I'm getting about 40% too many counts or around 6600 counts. I've examined my code and the O-scope trace and cannot understand where the extra counts are coming from.  Any insight would be very much appreciated. My goal is to be tracking the sun by Xmas day - assuming there is a sun; haven't seen much of it lately. Thanks.

TomGeorge

#6
Dec 19, 2013, 09:15 am Last Edit: Dec 19, 2013, 09:22 am by TomGeorge Reason: 1
Hi, have you tried slowing the motor down and seeing if the accuracy improves?
Slow down I mean by a factor of 5 or 10 so you can see what is happening.
It looks like you are tracking the sun with an algorithm, rather than track the sun using light sensors.
I understand you may need that speed and gear reduction to get torque, but for problem solving reduce the speed and see what your counts are.
If you are not quadrature encoding why two sensors on the shaft, only one on the  motor shaft speed should be enough.
Also a circuit diagram would be nice and a picture of your project, the diagram can even be a hand drawn photographed effort.
Hope it helps.. Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

gknapp19

Tracking the sun with light sensors is unreliable - especially when overcast.

A powered slew bearing is being used to rotate the tracker. The motor came with the slew bearing and has the two latching hall sensors from the factory. My results when reading only one sensor are worse. My coding requires that I see both sensors in sequence before recording a count. Frustrating is that today I got more phantom counts than yesterday (15.x to 1.9x vs 1.4x yesterday).
I would send a picture but my phone (camera) has failed on me - battery died and won't wake up. Overnight charge should resolve that. Attached is my circuit to attempt to read and count the sensors. My fallback is to fabricate an optical encoder but everything I read about hall sensors suggest they should be superior to any other method.
Do the scope traces provide any clues?

gknapp19


TomGeorge

#9
Dec 20, 2013, 08:18 am Last Edit: Dec 20, 2013, 08:22 am by TomGeorge Reason: 1
Hi, just looking at your circuit, are you putting 12V pulses into the arduino, 5V is what the inputs are designed for, unless micro is 3.3V supply.
So change the supply for the sensors to 5V.
Quote
Tracking the sun with light sensors is unreliable - especially when overcast.

I could get on a soapbox about that, when you are tracking the sun, you are pointing in the direction of maximum energy.
When it is cloudy the sensors will still find the direction of maximum energy.
When you track to an algorithm if you get localised cloud over the sun, and maximum is now in clear bit of sky, the panels will not be pointing in that direction.
But a sensor system will ALWAYS find direction of maximum energy, the accurate clock it uses is free and always right.
..off my soapbox now..

By the way you haven't shown or said if the neg or gnd of the supply for the sensor is connected to the gnd of the arduino.

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

gknapp19

There are 3 power supplies in this setup.
24V power supply for the motor
12V adjustable bench power supply for the Hall Sensor
5V (USB) for the arduino

I have also tried a 9V battery putting out about 8V for the Hall.

The bench PS has connections for +, -, gnd. I have not connected gnd to anything since I didn't really know where to connect it.

Interesting what you say about sun tracking with photo sensors. From what I have read and from anecdotal info, is that the sensor gets confused with overcast skies and keeps searching. Could it be that there is an optimal arrangement of the sensor unknown to these people?

gknapp19

I never did care for how noisy my scope trace looked. However, I recognize that a real-world square wave isn't going to be perfect.

Then again - there is another thing that bothered me from the beginning but dismissed as being paranoid. The 50 foot motor wire harness that will be installed at the solar tracker sat coiled up on my desk next to the motor - with included sensors.

Tonight I fabricated a 2 foot wire harness and tried again. The scope trace is much cleaner - although sensor A still has a curious dropout. using both sensors, my count is within 1/2% of the expected count. Using sensor B alone is not quite as good; 1.5% - 2.5% phantom counts.

TomGeorge

Hi, your latest trace shows that you are now putting 9V pulses on the digital input.
Supply the hall effect with 5V supply and you will then have 5V pulses which will make the arduino inputs safe from damage.

The noise is worrying, what do you get on your cro if  you just look at the hall device power supply, not the output, just the supply and ground?

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

gknapp19

The power supply voltage looks quite stable. The operating range of the sensor is 5-24V with nominal of 12V. This is why I'm operating at 12V.
I'm unsure where you see 9V.  I see 5.4V  Take a look at this measured trace.
Thanks,
Gil

TomGeorge

#14
Dec 22, 2013, 03:05 am Last Edit: Dec 22, 2013, 03:08 am by TomGeorge Reason: 1
HI, no problems, its lower than in reply 11, note the noise has decreased, now can you give us a trace of the DC power supply that goes to the sensors please.
I'm not worried about the voltage level applied to the sensors, I'm concerned that your are putting more than the 5V rated input into the arduino..................
The gnd on  the lab supply you don't need to worry about, however have you got the negative of the lab supply connected to the negative or gnd as marked on the arduino.
I assume all your scope traces are using lab neg as reference.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up