Thread: calulating and showing RPM on display

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    2

    calulating and showing RPM on display

    As part of a project i want to display the speed of a small wheel on a 7 segment display. I am using a hall effect sensor to pick up the pulses of the rotation. I am not sure how to write a programe on C to calculate the RPM from this.... any advice and help would be greatful.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    There are a few ways to go about this. Off the top of my head, I came up with the following.

    First, you need to determine how many points there will be per rotation of the wheel (let's call this value 'N') . In your software, you could implement a counter and a timer. The timer can run for a specified amount of time (e.g. 100ms). During each run of the timer, the counter increments each time a pulse is received from the sensor. When the timer is done, the number of rotations will be equal to the counter value divided by 'N'. That gives you rotations per 100ms. Then you can simply use math scale that value to the necessary units, and output it to your seven-segment display.

    Note that the values in my example are completely arbitrary - you would have to do some research and experimentation to find a suitable period for the timer.

    I'm assuming you're coding for an embedded device - is this correct?

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    2
    Quote Originally Posted by Matticus View Post
    There are a few ways to go about this. Off the top of my head, I came up with the following.

    First, you need to determine how many points there will be per rotation of the wheel (let's call this value 'N') . In your software, you could implement a counter and a timer. The timer can run for a specified amount of time (e.g. 100ms). During each run of the timer, the counter increments each time a pulse is received from the sensor. When the timer is done, the number of rotations will be equal to the counter value divided by 'N'. That gives you rotations per 100ms. Then you can simply use math scale that value to the necessary units, and output it to your seven-segment display.

    Note that the values in my example are completely arbitrary - you would have to do some research and experimentation to find a suitable period for the timer.

    I'm assuming you're coding for an embedded device - is this correct?

    HI Matticus, excuse the late reply. I have attached a one magnet to the wheel so the hall effect sensor is sensing just at that one point. I have researched previouly and the counter and timer has been mentioned a few times, but im not very experienced using the programmer. Also yes I am coding for an embedded device.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    This is almost just like Matticus; but, it assumes hardware features exist that makes the software simpler.
    (It also mentions things to look for in most MCU programming manuals.)

    One way is using an external interrupt and a accurate time measure method maybe using a Real Time Clock (RTC) if max RPM is slow enough compared to RTC resolution.

    1. Figure out if the MCU supports external interrupt.
    2. Figure out a way to do accurate timing while using an external interrupt.
    3. If yes to both, learn to write an ISR (interrupt service routine) to record number of hall effect sensor results.
    4. Every so often to the math on elapsed time and number of revolutions to calculate RPMs

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I have researched previouly and the counter and timer has been mentioned a few times, but im not very experienced using the programmer.
    In order to make a project like this work, you need to really learn the workings of both the hardware (MCU and supporting circuitry) and the software (the development environment you choose for the given device).

    I get the sense that you have little to no experience working with these types of devices. That's okay, though, because you can learn. In the interest of completeness, I'll describe how to best approach learning these topics. (Note: you may have already done some of these things.)

    #1: Get your development environment set up, and verify that you can get some sample code to compile (a lot of software comes with a slew of exampe code you could use for this quick test).

    #2: Print out the data sheet for the device you're using. Read through the data sheet carefully and try to understand as much as you can - this might take a while, but is imperative to get a true understanding of the device. Use a highlighter and a pen right on the data sheet to mark important ideas and put complex descriptions "in your own words". If you're really new to this, you probably won't understand a lot of the data sheet at first, but that's okay - understanding will come with time and study.

    #3 (this is optional, but highly recommended): Get the documentation for the compiler/IDE of choice. Also check the website for your device and you'll likely find complementary documents describing certain peripherals in more detail (e.g. timers, interrupts, etc).

    #4: Write several small "test programs" yourself, burn them into the device, and verify they work. The first one can be as simple as making an LED blink. While seemingly trivial, this would be a huge step, as it confirms (1) your coding style is correct, (2) your logic is on the right track, (3) your compiler is configured correctly, (4) your programmer is working, and (5) your hardware is powered and clocked correctly. The second "test program" can simply be the addition of a switch to control the LED - again, seemingly trivial, but it will ensure you're configuring inputs/outputs correctly as well as interacting with the ports the right way.

    #5: More test programs, only this time, start incorporating the peripherals. First, practice using the timer(s), referring to the data sheet and any complementary documents as needed. Take notes! Processing the information and writing it down in your own words will give you a better understanding and will reduce the need to "re-understand" the complicated procedure each time you do it. Data sheets are very informative, but having that information digested and written down in a way that makes sense to you will make working with those peripherals much easier going forward.

    #6: Even more test programs! Another peripheral you should learn right away is interrupts. (Unless you need them, things like serial communication and ADC can come later.)

    #7: By now, you should have the some experience with and notes on the basics. Now you're ready to start developing the logic of your real program. This logic development should be done on paper. I personally find flow charts are a good approach for this.

    #8: Build up your code in little steps. For instance, you could start simply by (1) reading the input of the hall effect sensor and (2) turning on an LED each cycle. Test that code on the actual hardware. When that works, add a little more functionality to your code, and test it. Continue this process of growing your program gradually and in small calculated steps.



    I understand you came here with specific questions, but without the background knowledge, there is little advice that can be offered that would actually be helpful. That's why I chose to instead give a basic overview of the whole process. These are things you have to learn in order to successfully complete such a project, and you'll have to invest the time to learn these things yourself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 12-06-2013, 07:15 PM
  2. Replies: 13
    Last Post: 05-02-2012, 04:17 PM
  3. Showing pictures on display in real time
    By BlackOps in forum C Programming
    Replies: 4
    Last Post: 01-28-2011, 06:58 AM
  4. Pic not showing up
    By Hunter2 in forum Game Programming
    Replies: 14
    Last Post: 11-13-2002, 01:19 PM
  5. Calulating Elapsed Time of any EXE
    By santhosh_be in forum C++ Programming
    Replies: 1
    Last Post: 06-03-2002, 03:59 AM