logo elektroda
logo elektroda
X
logo elektroda

How to count pulses from HAL AH49E sensor in Arduino for CNC?

SALLDHMF 2571 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18058618
    SALLDHMF
    Level 5  
    I am working on measuring the actual spindle speed on a small CNC machine tool.

    The module is a WiFi Lora 32 V2 (https://heltec.org/project/wifi-lora-32/). The HAL sensor is a Waveshare AH49E module - https://botland.com.pl/pl/czujniki-pradu/4494-czujnik-halla-ah49e-modul-waveshare.html, module diagram - https://www.waveshare.com/w/upload/2/28/Hall-Sensor-Schematic.pdf. Arduino IDE.
    For testing, I prepared a trivial code: For one second, the interrupts are to count pulses from the digital output of the Waveshare Hall AH49E module (it has both analogue and digital outputs). Then, I turn off the interrupts and display the number of counted pulses. In the target program, I will count the RPM. To start with, the number of pulses per second is enough for me.

    To check how the code works, I connect a signal from a rectangular waveform generator to the module input. The signal has a frequency of a few hundred Hz. This is a frequency close to that which will be given by the sensor mounted on the spindle. The code works perfectly. By varying the frequency from the generator I can measure "speed" from a few hundred to a few tens of thousands of RPM without any problem. Beautifully.

    Unfortunately beautiful is not. :-( The problems start when, instead of the generator, I connect a HAL sensor to the ESP 32 (GPIO 17).

    I made two attempts with the same sad result:

    1) The sensor is attached close to a magnet glued to the fan wings from the PC.

    2) The sensor mounted near the CNC spindle

    The results shown by the software are highly variable. They vary from second to second, e.g. between 780 and 1140 pulses counted in one second, despite the apparently constant speed of the fan or spindle. I would still be able to believe that the fan rotates unevenly, but the inverter-controlled spindle rather has a constant speed. The amplitude of the signal from the generator and the HAL module is the same.

    My toy oscilloscope shows that the signal rises slowly but falls quickly.

    I attach two images. One shows the results on the Arduino IDE console for the rectangular waveform and the waveform itself on the screen of my toy oscilloscope, the other shows the results plotted every second when the HAL sensor is connected to the ESP and the waveform from the digital output of the HAL sensor module. Even on the oscilloscope screen the frequency readout is not constant.

    Can anyone help? Where could the error be? I don't like the shape of the "digital" signal from the sensor module. Maybe move this post to some other forum closer to electronics ie Hal sensor.

    How to count pulses from HAL AH49E sensor in Arduino for CNC? How to count pulses from HAL AH49E sensor in Arduino for CNC? .


    ----------- Code -----------
    int hallsensor = 17;
    volatile long ticks = 0;

    void pick() {
    ticks++;
    }

    void setup() {
    Serial.begin(9600);
    pinMode(hallsensor, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(hallsensor), pick, FALLING);
    }

    void loop() {
    delay(1000);
    sei();
    Serial.println(ticks);
    ticks=0;
    cli();
    }
    --------------
  • ADVERTISEMENT
  • #2 18058700
    khoam
    Level 42  
    What voltage do you supply to the Waveshare AH49E module when connected to the ESP32?

    SALLDHMF wrote:
    module schematic
    .
    From the sensor schematic it (vaguely) appears that there is an RC junction connected to the DOUT digital output to ground - the shape of the output voltage on this pin would therefore be justified.
  • #3 18058703
    rb401
    Level 39  
    SALLDHMF wrote:
    Where could the error be? I don't like the shape of the "digital" signal from the sensor module.


    In my opinion, the comparator used in the module is loaded with a relatively high resistance at the output. And since the LM393 has an open collector output then those rising edges you see are mild because here only the resistor to the plus works. You could try adding a resistor between the module's output and the plus of its supply and watch how the shape improves.

    But in general, for this application a Hall sensor not linear but digital, integrated with a schmitt flipper, would be better. Something like this, for example:

    https://botland.com.pl/pl/czujniki-magnetyczn...ik-halla-pola-magnetycznego-iduino-se054.html
  • ADVERTISEMENT
  • #4 18058775
    SALLDHMF
    Level 5  
    I love the forums. Thank you for your replies.

    I am feeding the sensor with 3.3V from the module with ESP.

    I didn't recognise the difference between the sensors in Botland. When I bought one it said "Digital output signal", so I believed it would be digital ;-) . The price of the Iduino SE054 is less than £5, so Botland will have a customer right away :-) .

    How about reaching for yet another sensor? I care about precise measurement. Now my confidence in such sensors has "slightly" diminished.
  • ADVERTISEMENT
  • #5 18058836
    rb401
    Level 39  
    SALLDHMF wrote:
    In Botland, I did not recognize the difference between these sensors.


    Don't worry because Botland itself probably doesn't read too much into the difference between linear and digital.
    For example, this:

    https://botland.com.pl/pl/czujniki-pradu/1429...ul-z-czujnikiem-halla-pola-magnetycznego.html

    Where in the picture you can clearly see the symbol on the sensor "49E" meaning linear (same as on your module) and no resistor R1 needed for digital, and they sell this as digital.


    SALLDHMF wrote:
    I supply the sensor with 3.3V from the module with ESP.
    .

    A very important point here. The digital module I gave you as an example earlier with the A3144 sensor (or equivalent with the same number) has a catalogue power supply range of 4.5...24V.
    Therefore, on a 3.3V supply it is basically not suitable. But if you only have e.g. 5V available in the device then, because the sensor itself has an open collector output, you can supply the sensor with 5V and connect a pull-up resistor to the output to 3.3V and everything will be perfectly fine:

    How to count pulses from HAL AH49E sensor in Arduino for CNC? .

    If you don't have 5V then the issue gets complicated because you would need to find a digital Hall sensor that works at 3.3V. But yes off the top of my head I won't give you the type at the moment because you have to search and check availability, prices etc. . With 5V ones there is no problem because you know how cheap and easy they are to buy.
  • ADVERTISEMENT
  • #6 18058864
    khoam
    Level 42  
    By the way: The ESP32 has a built-in Hall sensor :) .
  • #7 18058867
    SALLDHMF
    Level 5  
    I found another one:
    https://botland.com.pl/pl/grove-czujniki-prad...?search_query=Czujnik+halla+gro&results=5

    https://www.seeedstudio.com/Grove-Hall-Sensor-p-965.html.

    A1101 sensor.

    Added after 9 [minutes]: .

    That the ESP has a Hall sensor built in I know, I just don't attach it to the spindle :-) .

    The whole system is already very advanced, and is much more complicated than just a tachometer. One ESP is at the CNC handling the reading and sending information to the other, located in a wireless console to the milling machine. The main function of the whole thing is to respond to a drop in spindle speed. I work in wood and it is not homogeneous. Sometimes the feed has to be slowed down to avoid stopping the spindle, whose power is low. I now do this myself as a 'biological attachment' to the CNC :-) . As I don't yet know the board or the species of wood I adjust the feed speed to the piece of wood in question. But I have more interesting things to do :-) .

    Tomasz

    Added after 10 [minutes]: .

    A. Of course I have 5V available. As long as the sensor doesn't give 3.8V output, and that's the information on the page: http://www.openplatform.cc/index.php/home/index/details/apiid/196 ESP not or get more than 3.3V. I haven't checked the limits, but I won't test them.
  • #8 18059064
    TvWidget
    Level 38  
    Check that this sensor is suitable for the frequencies you need.
    Count the pulses with a hardware counter and not in the scroll.
  • #9 18059220
    SALLDHMF
    Level 5  
    What do you mean when you write hardware counter?
  • #10 18059269
    rb401
    Level 39  
    SALLDHMF wrote:
    Byle the sensor did not give 3.8V output, and this information is on the
    page.

    This voltage is due not to the properties of the sensor itself but only to the fact that on the module the sensor output is connected to +5V via a resistor and an LED (red), which has a drop in the conduction direction of 1.2V (hence 5V-1.2V=3.8V).
    But don't worry about that, as this module needs to be modified slightly for your purposes anyway.
    Here is a schematic of this board, labelled SE054 by the vendors (used for both linear and digital sensors). Below, in digital sensor configuration (for linear sensors, the board is the same, only the resistor and LED spaces are vacant):
    How to count pulses from HAL AH49E sensor in Arduino for CNC? .
    source: http://www.okaauto.com/HallSensorD.html .

    Here you can also clearly see where this 3.8V is coming from.
    For your needs, you just have to remove this LED and to one of the solder fields of this LED (the one that is connected to the resistor) add a wire that goes to 3.3V.
    And a schematic will come out exactly as I drew earlier. Where the high state will be equal to 3.3V.




    SALLDHMF wrote:
    .

    This module does not save you, because the A1101 sensor has a minimum power supply of 3.8V in the catalogue, which is still too much. Besides, for you it may be more convenient to use a sensor in a through-hole housing like in these other modules, because in case of emergency you can bend it or even extend it with wires without much trouble. And the SMD one is much more difficult to fit somewhere together with the board. In addition, the module is prohibitively expensive.
  • #11 18059292
    SALLDHMF
    Level 5  
    I assumed that I would power the A1101 from 5V.

    SMD is definitely cumbersome.

    And the solution with modifying the SE054 is definitely worth considering.

    Thanks rb401
  • #13 18059415
    SALLDHMF
    Level 5  
    Oops. Well, yes, of course. And I thought of the spindle mounted equipment. :-)

Topic summary

The discussion revolves around measuring spindle speed using a HAL AH49E sensor with an Arduino for a CNC machine. The user is utilizing a WiFi Lora 32 V2 module and has prepared code to count pulses from the sensor's digital output. Responses highlight concerns about the sensor's output characteristics, suggesting that a digital Hall sensor with a Schmitt trigger would be more suitable for accurate measurements. Users discuss powering the sensor with 3.3V and the potential need for modifications to improve performance. The conversation also touches on the use of hardware counters in the ESP32 for pulse counting and the importance of selecting the right sensor for the required frequency range.
Summary generated by the language model.
ADVERTISEMENT