sharing an interrupt

I’m using an Arduino Mega in a project with two 24VDC brushed motors with two hall effect sensors each. I was expecting 5 interrupts to be available. However, the I2C bus uses two of the 5 available hardware interrupts. With a RTC using a third, I have two interrupts remaining for 4 hall sensors. This should be enough as I am explicitly controlling motor direction and need only use one sensor for motor control. However, the square wave signals are not clean. They both have two voltage levels at the top of the square wave splitting the top evenly. One motor is at 4.8V and 5.2V. This is subtle enough that control is not affected. The other is at 5.2V and 6.0V. I am apparently experiencing phantom signals causing the motor to stop prematurely. I haven’t been able to isolate the cause of the interference. I may be able to tame the problem by using both sensors. I only count a pulse from Hall A if the previous pulse was from Hall B and vice versa. This brings me to my question. Can I share interrupt pins with two hall sensors? Since the motors do not run at the same time, I can use two pins for motor 1, then use the same two pins for motor 2. I haven’t yet tried this as I am concerned about back-feeding voltage from one sensor to another and damaging sensors. Sooo…

  1. Can one pin be connected to two sensors without damaging the sensors?
  2. What could explain a square wave with two evenly split voltage levels at the top of the waveform?

However, the square wave signals are not clean. They both have two voltage levels at the top of the square wave splitting the top evenly. One motor is at 4.8V and 5.2V. This is subtle enough that control is not affected. The other is at 5.2V and 6.0V.

Why does the voltage changes along the top of the pulse matter. The interrupt will be looking for RISING or FALLING edges. The voltage changes at the top, should not be triggering the interrupts.

What type of output are the hall sensors? Open collector? Push-Pull? If open collector, what are the pullups tied to? Are the hall sensors latching?

Are you certain that the artifact along the top of the pulse is not due to your oscilloscope?

I am apparently experiencing phantom signals causing the motor to stop prematurely

Do these "phantom signals" and the motor stopping have anything to do with the hall sensors and their stepped outputs?

gknapp19:
I was expecting 5 interrupts to be available. However, the I2C bus uses two of the 5 available hardware interrupts.

Use pinChange interrupts and most of the I/O pins can generate an interrupt.

...R

H-bridge control with PWM can be very complex. There are a few modes possible, which is yours using?
http://www.modularcircuits.com/blog/articles/h-bridge-secrets/

what are the pullups tied to?
This prompted me to examine my wiring and I found that I had connected the 10K pull-up resistors to the Arduino +5V. The hall sensors are powered by a separate 12V supply. I connected the 10K pull-up to the +12V line. The waveform for motor 1 is now far better. It still has a subtle 2-level output of about 6V +/- .08V My only worry with that is feeding the Arduino pins with 6V. I ignored motor 2 for the day.

What type of output are the hall sensors?
I have minimal information on the hall sensors. They are in the motors which my vendors purchased for their assemblies. The nameplate info from motor 1 allowed me to find the mfg website. The datecode on the motor (20151224) is not that old yet the motor model# is not on their website. I have previously been fairly successful using motors from the motor 1 vendor.
My only evidence of phantom signals is the pulse count reaching the expected value while the motor has not reached its destination. If the motor were to go further than expected, this would be evidence of missed counts.

Use pinChange interrupts?
I am considering this, but not until I can get the hardware interrupt and connected motor to perform properly.

H-bridge control with PWM?
This is my first use of such a motor controller. I have previously used my own home-brewed assembly of transistors and relays. I am now using a Pololu G2 High-Power Motor Driver 18v17. When I wish to start a motor, I set SLP high; DIR high or low depending on the desired direction; PWM high to run the motor. To stop the motor, I set PWM low; then SLP low. I have experimented using PWM to slow the motor just before stopping it. I have been to modularcircuits.com but have not studied the extensive material found there.

What is puzzling is how well behaved motor 2 is. My previous experience with the motor 1 vendor’s product was also plagued with random interference yet the errors were random enough it seemed to self-correct. I provided a simple mechanism to correct errors that creep in over time. It has been in successful operation for 3 years. It can go months needing correction every 2 – 3 weeks. But occasionally, it may need correction in 2 or 3 days.

what are the pullups tied to?
This prompted me to examine my wiring and I found that I had connected the 10K pull-up resistors to the Arduino +5V. The hall sensors are powered by a separate 12V supply. I connected the 10K pull-up to the +12V line. The waveform for motor 1 is now far better. It still has a subtle 2-level output of about 6V +/- .08V My only worry with that is feeding the Arduino pins with 6V. I ignored motor 2 for the day.

I don't understand this. If you have open collector output then you should be seeing the 12v. Is there a voltage divider in the path to the Arduino input pin? How do you measure the 6v at the input?

My only evidence of phantom signals is the pulse count reaching the expected value while the motor has not reached its destination. If the motor were to go further than expected, this would be evidence of missed counts.

This certainly sounds like you have a noisy signal and are getting extra counts. You will need to use hardware and software debounce. It sounds like you have scope to look at the output from the Hall sensor. Can you see the multiple trigger events from he noisy output?

Please post the code you are using, a drawing of your circuit, and an image of the noisy output if you have it?