An example of using a Hall Effect sensor to make a simple tachometer. Link to my video on an LCD software driver: • Microcontroller User I... Link to my code and a schematic: github.com/hol...
Опубликовано:
29 авг 2024
Поделиться:
Ссылка:
Скачать:
Готовим ссылку...
Добавить в:
Мой плейлист
Посмотреть позже
Комментарии : 140
8 месяцев назад
This code to create a tachometer in Arduino is spot-on correct. Other like videos track # of revolutions in set amount of time, then extrapolate RPMs. The result is an RPM read that jumps in 60 increments, as every additional revolution in a given cycle results in +/- 60 revolutions. Mr. Hollinger's code is dated now, but still so relevant. Thank you!
Thanks for the very comprehensive video. You did an excellent job explaining a not so easy circuit to a noob like myself. A high quality video indeed it is.
Wow. Cant thank you enough for posting this very lucid explanation of this hall effect sensor project. Im new to this technology and am working my way through an Arduino tutorial with my first being the design of a chain counter on the anchor windlass on my boat. I dont need RPM. I need to count rotations and convert that into feet of chain but your post told me a lot of things I did not know about using hall effect sensors and a lot of the info in pertinent to my project. My primary challenge is figuring out a way to detect which way the wheel is spinning (i.e., is the chain coming in or running out). I was thinking that I could use two hall effect sensors and use some sort of logic loop to set the direction by detecting which sensor is triggered first to determine direction of rotation.
Good luck with your project. The internet has a lot of good information. You just need to sort through all the mis-information though. Thanks for watching.
PORTB.0 (Arduino digital pin 8) offers a very simple way to obtain amazing precision by capturing the Timer1 value on a rising/falling edge. By enabling timer overflow and capture interrupts, you can measure very long periods between the edges as well as sub-microsecond periods with exacting precision. I can give you some sample code that does this in the ISRs and passes the measurements back to main level code in a circular queue. It's surprisingly simple and small. Edit: Look at ICP1 facility in the datasheet.
Great video, it was really helpful in my application. Nevertheless, I would like to suggest an improvement if I may. Looking at the falling and rising edges obtained from the amplifier in 9:30, the slope shown is not so sharp due to the linear response of the sensor. Such behaviour could modify the interrupt identification of the falling and rising edges on the microprocessor when the velocity of the shaft increases or reduces. In fact, this effect would be more significant for low speeds because the slope would be less sharp as the speed reduces. In order to reduce such a problem, it could be used a Schmitt-trigger on the output of the amplifier. Actually, some Hall-effect sensors use Schmitt-triggers for digital measurement of the magnectic field.
My apologies for not replying sooner, super busy at work. Your point would be correct if the system was measuring the time between a rising and a falling edge. But that's not how my system does it. Only one edge (rising or falling, I can't remember which) is used to trigger the timer. The time between successive rising edges will always be proportional to the rotation of the motor. The slope of the signal from the amplifier doesn't come into play in this case. I'm glad you found my video helpful. Thanks for watching and your comments.
My apologies for not replying sooner, super busy at work. Your point would be correct if the system was measuring the time between a rising and a falling edge. But that's not how my system does it. Only one edge (rising or falling, I can't remember which) is used to trigger the timer. The time between successive rising edges will always be proportional to the rotation of the motor. The slope of the signal from the amplifier doesn't come into play in this case. I'm glad you found my video helpful. Thanks for watching and your comments.
My apologies for not replying sooner, super busy at work. Your point would be correct if the system was measuring the time between a rising and a falling edge. But that's not how my system does it. Only one edge (rising or falling, I can't remember which) is used to trigger the timer. The time between successive rising edges will always be proportional to the rotation of the motor. The slope of the signal from the amplifier doesn't come into play in this case. I'm glad you found my video helpful. Thanks for watching and your comments.
that explanation was so precise and easy to listen to.... you really have a talent for this..please we need more videos like these... i subscribed, gonna check the rest of your content.
Thanks for the tutorial. I want to create a cadence sensor for road cycling training and this may prove very useful. I will not have some of the speed issues you had but the concept is identical. Thanks again.
I'm late to "this" party.... Info is as fresh as a silicon daisy! Super 👍😁. Enjoying it immensely (it's Fri night 10:45pm:). This has SUBBED written all over it. Much appreciated. Cheers! Randy 🤗
Microchip makes some fairly decent opamps with rail to rail outputs. Some have a built in Vcc/2 reference output for biasing an input. Their weakness is that they are only 5V parts.
Brilliant piece of work thank you for all your trouble and for putting the code out, I realise that you had a slip of the pen with the hex, but that was only whilst you were under the pressure of talking to camera, who as not made mistakes in hex counting or binary or decimal, speaking of which the long number that you had misplaced, which caused you to work it out again, ie 10 to power 7 was wrong, your software got it right but you wrote 11,718,750, my calculation made it 1,171,875 again just another slip of the fingers, but overhaul you were spot on, so I thank you for your effort. Bob
Excellent explanation and tutorial. I plan on working with a tach like this. I'm new at biasing opamps and am wondering what purpose the voltage divider on the non-inverting input between the hall sensor and opamp serves.
+Joseph Carbone It raises the opamp reference so that it will track the signal from the Hall sensor. The Hall sensor sits at 1\2 the power supply rails and its signal will go positive or negative from this level depending on the polarity of the magnetic field. Thanks for watching!
excellent video, very well done. One question: you say that you need to detect the falling edge because if you ‘d use the low signal (flat part) you don’t know if a single cycle could be counted multiple times, since the time it stays low is longer than the cpu cycle... But, why don’t you simply measure both low and high signal , and then (and just THEN) set the counter ? Isn’t it easier to reset the counter to zero after a Low And an High signal is detect, in sequence?
When the pin goes low, the timer is started. The next time the pin goes low (after one revolution of the motor shaft) the timer is stopped and the accumulated count converted to RPM. The whole process starts over next time the pin goes low. There is no need to detect when the pin goes high.
Love the video, well done. I do have a question. Why have you used a 5A power regulator on a hall effect sensor? Would a LM317, @ 1.2A suffice? The current draw of the hall effect couldn't be more than a few mA. I'm new to this stuff, so my question is genuine. Thank you.
Thanks! I'm not sure what 5A power regulator you are referring to. If it's the LM7805 in the schematic, that's rated at only 1A. You are right, the Hall sensor doesn't draw that much current. In fact, the whole circuit wouldn't draw much current. I didn't measure it, but I'd suspect it would be 20-30mA tops. I threw the schematic together to give viewers an idea how to connect everything up. Any old regulator, as long as it can supply the current would do. Thanks for watching.
I am curious, Why instead of using two condition you are using such complicated interrupt system? I would detect the ground point just like you did and then detect the top point which will simply be ignored up until another drop point where I would calculate time interval and then reset counter and restart the loop waiting for another drop. It will reset itself every second rotation and it would not use INT0 and make a code way more simple and obvious. Detect first drop, detect first up, detect second drop, make time calculation, display result, reset timer, restart...
I believe this is how I'm doing it. I was using the INT0 pin as an ordinary digital input, but with some relatively simple code changes, the interrupt could be used. In this very simple case, the interrupt wasn't necessary, polling worked.
Well... You could have easily done it with a normal I/O pin by just saving the last state and comparing it to the current state, to see if it has fallen or was already low. That's not the ideal way of doing it however if you have a free interrupt pin anyway, since the timing will be less accurate the lower the sampling rate and you would therefore have to insure that the main loop runs at fast enough or use timer interrupts. Although that would only become a problem at relatively high rpm...
Yes, you are right, my code is not the best way to do this. I threw it together quickly just to get something done. What the code is doing is measuring the time for the motor shaft to go around once, and it does this by blocking at the while((EIFR & _BV(INTF0)) == 0); statement until there is a pulse from the Hall sensor, then reading the accumulated value in Timer 1. If the Hall pulse never comes, (when the motor is stopped, for example) the code stalls forever. This is where using the INT0 pin as it was intended - as an interrupt - would work best. That way the microcontroller can go and do something else between pulses. This method works for well low RPM, another method would be needed for higher RPM. I'll leave improving my code example as a homework exercise for you and other viewers. Thanks for your comment.
I don't know the system, so I don't know if this idea would be feasible or convenient. What I thought of at first was having a loop that sets the counter to zero then starts a timer and waits for it to finish. Timer based on how often you want the display to update. An INT on the falling edge would reset the INT and increment the counter then wait, Plenty fast for anything you'd like to count. When the timer ended, you take the value of the counter and multiply by whatever it takes to make the number of seconds 60 (if the timer was for 10 seconds, multiply by 6) There's your RPM value. Move that to your display. Back to the top of the loop, reset the counter to zero and start the timer again.
+Joseph Cote That would be another way to do it. You can connect the pulses from the Hall sensor directly to the increment input of one of the counters (not sure which one, I'd have to look it up). Use another counter as a timer, say one second, when it times out see what count has accumulated in the first counter. That would give rev/second, do some math to convert to RPM. This is how a frequency counter works. I did a video on that - check it out. Thanks for watching.
Get video. I got the circuits all working. Did you ever post the code and a link to your lcd library? I don't mind retyping in the code from screen shots but it is a bit time consuming. Thanks.
+Ken Horner Thanks for watching. I don't yet have anything set up yet to post software. I think the video is clear enough for you to be able to follow along and copy the software from your screen.
Thanks for this wonderful video. Im currently working on a university project wich is a joystick , what i want to know is that wither this circuit is going to give me an analog range from 0 to 1023 (on arduino) or just a digital 0s and 1s. Thanks in advance.
Yes, the circuit will give an analog output proportional to the distance the magnet is from the Hall sensor. Just be aware that the analog output from the opamp will sit at a voltage (2.5V, or half the power supply voltage if my memory is correct) when the magnet is far away from the sensor. The voltage will go up or down from there depending on the polarity of the magnet and it's distance from the sensor. You may have to play with the values of the opamp gain resistors to get it working to your satisfaction. Good luck!
Hi Craig, Thanks for the video. I found a small error. At around 16mins you tell that Timer1 is 16 bit but mention only 8 bit count(0xFF = Decimal 256) . A 16 bit counter would count from 0 to 65535 (0xFFFF). Could you please correct that ?
Is there a place I can download your code examples? Also wouldn't it be easier to use a sensor that puts out a digital signal rather than a linear one?
Here's a link to my code: github.com/hollingerc/hall-effect-tach I've also updated the video description with this link. Yes, there are chips out there that have signal conditioning circuitry built into them and they output a nice digital pulse, but I didn't have one. One of my intentions for this video was show some OpAmp biasing techniques for general interest sake.
Why not just use the out put of the HALL Effect to trigger an opto-isolator 5v and then to the Arduino or perhaps a ATTiny 85 and then to the LCD. very interesting video stimulates my imagination and makes me want to fire up my soldering iron.
This probably wouldn't work. The Hall sensor doesn't have much current output, so it wouldn't likely operate most common opto-isolators. Thanks for watching.
The input to the opto-coupler is an LED and needs a certain amount of current to drive it. Connecting the Hall sensor directly to an opto-coupler would probably not work as the Hall sensor cannot source or sink much current. Another problem is the output of the Hall sensor sits half-way between the power pin (Vcc) and ground when no magnet is nearby. This was 2.5V (half of 5V) in my example and if the Hall sensor could produce enough current to drive the opto-coupler, the coupler would always be on. I used the opamp to remove this 2.5V bias. An opto-coupler could be used, but some interface circuitry would have to be put between the Hall sensor and the coupler to make it all work. It would end up in being more complicated that the circuit I presented. Good thought though. Do get out your soldering iron and start building stuff - good way to learn. Thanks for watching.
Couldnt you use a magnetic reed switch and just put the i/o values in the algorithm with the constants of the rpm conversion equation? Simple math... that way the length of 0v, rise dont matter.. woukd just have to figure out a good update length for the lcd readout.. kind of like how the cheap tachs work where they have a wire that wraps around a spark plug wire using either as an ammeter or inductive pickup and set up the tach in a menu to tell it whether it fires 1,2,4 times per revolution...
Sir,i have to calculate the distance. so as if we are getting rpm on evry 2nd pulse,so it will create problem in calculating distance as while calculating RPM, we are neglecting the distance between 2 consecutive pulses
Navdeep Singh Thanks for watching the video and my apologies for taking so long to reply. The microcontroller is too slow to respond to the magnet passing by every revolution. So what I did was to use the microcontroller to measure the time the magnet took to go around one revolution. From that time, the revolutions per minute (RPM) can be calculated. Even if this measurement was done, for example every 10th revolution, the instantaneous RPM (at that time) can be calculated.
Hi, I'm a student from Brazil, and I've been whatching your videos, I wanna thank you for sending this videos, the tachometer explanaition helped a lot, with a little project that I've been working on it. I would like to ask you if possible, can you send me the codes that you used in your tachometer. I'm trying understand the code, but I can't see it properly
+Renato Silva de Carvalho Thanks for watching. Unfortunately I don't have anything set up where I could post my code. I'm planning on doing it sometime, but haven't had the time. Stay tuned.
I've seen guys do this with a few lines of code for Arduino. Is all this necessary for a falling edge signal or are you just starting more from scratch with your equipment?
Hi help me My tacho is dead when I try to start with third battery and the generator fuze 60 is cut then I replaced the fuse and the cluster. But unfortunately is dead again that cost my alot of mony lm bankrupt with dead tacho.. My truck is hyundai65 No mcu on it .. Is the convertor 12v for radio cause thes or ETACS....THNKS sorry for my bad English
I'm assuming you mean replacing the OpAmp with the 555. The signal from the Hall sensor output sits at 1/2 the supply voltage. The OpAmp circuit removes this bias so a digital input can respond to the pulses. The 555 probably wouldn't work if the output of the Hall sensor was fed in directly.
Thanks for the instructive video. Can you tell me which language are using to programme your integrated circuits? I hear it is quite comun to use Python. Can you clarify me a litlle? thanks again!
Excellent tutorials! I'm definitely going to make one of these.Can this technique be used to make a frequency meter/counter? If so, what would be the maximum frequency that could be measured? Thanks for sharing.
Thanks for the comment. Not sure how you would couple the signal you wanted to measure to the Hall sensor. It needs a certain amount of magnetic field to respond. Also, it's not a very fast device, you might get max 10kHz out of it.
Craig Hollinger Oh I meant using timer 1 and INT0 to measure the falling edge of the signal i want to measure the frequency of. For example instead of connecting the output of LM358 to INT0 connect the signal I want to measure, then do the calculations and conversions. English is not my native langue so I don’t know if i'm explaining myself correctly sorry.
Man LA OK, I understand what you want to do (BTW, your English is great). The way I implemented the tach is not a good way to make a frequency counter, there's a better way to do it. It will be too hard for me to explain how through RU-vid comments, but you've given me an idea for my next video. Stay tuned, I'll produce a video on making a simple frequency counter sometime in the next few weeks.
Craig Hollinger thanks for replying, for sure i'll stay tuned i bet it will be very interesting i've been watching your videos and i really like how you explain every detail in your designs i find that to be really helpful once again thanks and happy holidays!
You can. The sensor measures current (I). If you measure voltage (V), then you can compute watts (= V * I). The units of joules is watt-seconds (W * sec), so just measure the watts over a period of time. For example: if your device consumes 1 Watt for 1 minute, it has consumed 60 joules (1W * 60 seconds). I hope this helps. Thanks for watching!
hi! do you know whats the maximum detect-rate (with a raspberry pi and this sensor) if you want to measure the rpm of a motor? i have a 10k rpm motor and i dont know if the sensor or the pi thinks there is a constant magnetic field above a specific rpm..
I don't know what the Rpi can do, but the particular Hall sensor I used has an upper limit of about 40kHz. The OpAmp I used is not particularly fast either, but may do 40kHz in the configuration I used in the video. So, I suspect the circuit I presented in the video could be fast enough to detect the RPM of your motor.
If you are referring to pin1 of the opamp, it isn't connected to ground. This is the signal going to the microcontroller to measure the time between pulses as the magnet spins around. Check the link in the video description for the code I wrote and a copy of the schematic.
one thing i dont understand is the flag register intf0 . if it is set by writing a one to it , how is it also cleared by writing a one to it . Though this does correspond to the data sheet , but im a bit of aloss what is meant by it . Cheers folks
The flag register isn't as simple as a memory location in RAM. The MCU has some logic associated with the register to make it work that way. You'll find that most or all modern MCUs implement flag registers this way. Thanks for watching!
I only use Arduino as convenient break-out boards for the ATMEGA, I don't normally use the 'Arduino Language' (which is just the C++ language). My code is written in the C language and would have to be 'massaged' somewhat to make it work under C++. You could try the following to port my example tach.c code over to Arduino. I haven't tried this, so I don't know what would happen. - copy from my code all the #define statements and all the variable declarations to your Arduino file above setup() - copy from my code the code between the variables and the while() to you Arduino file into setup() - copy from my code everything in the while() loop and put it into your Arduino file in loop() The LCD driver (hd44780c.c) is available on my GitHub site. You are welcome to try it. This is where you may have a problem though, as it is not written in C++. You may want to use another LCD driver for your project. Good luck.
great explanation. i'm working out with this type of projects. so can i have this embedded c code. if possible please inbox me this code. thanks in advance.
now wonder nerds lead secret lives a world destroying demi-gods! This simple speed tester requires the intellect of aliens...at least from my point of view ;] Thanks for the high quality video letting me see into a magic world of electronic programming ;]
+Diego Ospina Thanks for watching. The A3212 may work for very slow RPM. It is heavily filtered to reduce jitter, but is too slow for most applications that I had in mind.
+Ujjwal Roy I had a brief look at the ATMega324 data sheet, and it looks like it would work as well. It shares many features and peripherals of the ATMega328. Thanks for watching.
the hardware explication was amazing but for the software please be more specific because I lost the interest in the middle of the video thanks you are so brave
Miguel Said Haddad Chavelas Thanks for watching the video and hanging in there as long as you did. Software explanations can be quite long (and tedious) depending on the depth of detail. I'm trying to keep my videos down to a reasonable length, less than 45 minutes, so I tend to gloss over some of the software details. At some point I will set up a repository on-line so viewers can download my code and go through it at their own pace. Stay tuned.
CurA (cursor A) is 8.8ms left of the trigger point or -8.8ms from the trigger. CurB (cursor B) is 58.8ms right of the trigger point. The difference between the two is 67.6ms, so there is a pulse from the magnet on the motor shaft every 67.6ms or 14.8 times per second. That means the shaft is rotating 14.8 times per second or 14.8 X 60 = 888 times per minute (RPM). This is how I figured out the RPM of the motor. Thanks for watching.