Counting pulses from a hall sensor. Erratic behaviour...

I'm trying to read the pulses from a hall effect sensor (inside the motor of my pool cover). The hall sensor type/model is unknown. 

The manufacturer can only tell me that it's a 24V DC hall sensor.

I have attached it to my Industruino digital CH1 pin and it does count pulses. The problem is that it doesn't seem to count them right and I'm unable to identify the problem. I'm stuck right now.

As a test I let the Industruino program partly open the cover. Then I tried to close it by letting the motor run in the opposite direction until the same amount of pulses were received.

This resulted in the pool not always closing completely. Even a difference of 10cm was possible.

It looks like the Industruino is sometimes missing pulses and sometimes counts too much pulses.

The hall effect sensor has a 220nf film capacitor between GND and digital CH1/Hall effect sensor. 

I connected my oscilloscope to the hall effect signal wire and you can see the signal here: https://ibb.co/3yXw4ZG

While the program is much more advanced, the only relevant code for counting the pulses are these lines:

Indio.digitalMode(1, INPUT);
Indio.digitalWrite(1, LOW);

attachInterrupt(8, cover_position_pulse, RISING); 

 

and the ISR function:

void cover_position_pulse() {
    if (device_mode == DM_RUNNING) { 
      if ( current_cover_relay_direction == MOTOR_DIR_OPENING ) {
        runtime_data.cover_position--;
      } else {
        runtime_data.cover_position++;
      }
    } else
    if (device_mode == DM_PROGRAMMING) {
      programming_pulse_counter++;
    }
}

I also tried the "FALLING" interrupt option but that didn't make much of a difference.

The digital pins are connected to an expander. Am I right to assume that this won't be a problem for an interrupt routine like this?

Any help / toughts are more than welcome.

Thanks

 

Andy Knuts
Andy Knuts
20
| 0 0 0
Asked on 3/25/22, 4:35 PM
0
vote
1559 Views

Hi, the interrupt will fire with any change on any of the 8 digital channels so i'd advise to mask all your other channels with INPUT_MASKED as in https://github.com/Industruino/documentation/blob/master/indio.md#interrupts

As far as i remember, the interrupt signal itself is a pulse, so it doesn't matter whether you use RISING or FALLING to catch it. This RISING/FALLING is not related to the actual signal on your scope, my understanding is that with your block-type signal, you will get an interrupt on the falling AND the rising edges of your signal, as the state changes on both occasions.

If the miscounting is due to noise on the signal, i'd suggest to try without the interrupt, and polling the channel with Indio.digitalRead(), that should be no problem at 73Hz (frequency seen on your scope image). In this case you can properly debounce in the code. But then you need to make sure the Industruino is not doing much else while counting. You could also use INPUT_LATCHED to make sure you don't miss any pulses.

 

 

Tom
Tom
5675
| 1 1 3
Answered on 4/1/22, 2:02 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

68 follower(s)

Stats

Asked: 3/25/22, 4:35 PM
Seen: 1559 times
Last updated: 4/1/22, 2:02 AM