Converting milliseconds to frequency


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Location
    Grass Valley CA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Frequency is the reciprocal of time. For example, if you measure your square wave as 16.66...milliseconds, you have a 60 Hz. frequency.

    Now, dependent on whether your milliseconds are floating point (many decimal places), you can measure frequency with concomitant resolution. That is, if time is an integer and you only have choices of 16 or 17 milliseconds, the frequency comes out 62 Hz. or 58 Hz. respectively while the actual waveform is 60 Hz..

    Jim

  2. #2
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    With my millisecond values are integers, I don't expect 100% accuracy. Using PBP, how do I get from say, 16mS to 62Hz ?

    Scott

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    You can write a subroutine to determine the RPM from the z value. If to the nearest 100rpm is acceptable, this is the relevant data:

    Code:
    z           rpm
    -------------------------
    <10         out of limits
    10          6000
    11          5500
    12          5000
    13          4600
    14          4300
    15          4000
    16          3800
    17          3500
    18          3300
    19          3200
    20          3000
    21          2900
    22          2700
    23          2600
    24          2500
    25          2400
    26          2300
    27          2200
    28-29       2100
    30          2000
    31-32       1900
    33-34       1800
    35-36	    1700
    37-38	    1600
    39-41	    1500
    42-44	    1400
    45-48	    1300
    49-52	    1200
    53-57	    1100
    58-63	    1000
    64-70	    900
    71-80       800
    81-92       700
    93-109      600
    110-133     500
    134-171     400
    172-240     300
    241-400     200
    401-1200    100
    >12000      out of limits
    If you need help on how to write a subroutine to do this then let me know and i can help you out.

  4. #4
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    I am a bit of a rookie. Some direction would be much appreciated.

  5. #5
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    I had a few spare mins so i wrote up a subroutine that would work. Im sure its not the most elegant piece of code, but it will do what you want just fine.

    It will take the z value and store a relavant value into rpm. The value in rpm will be in hundreds of rpms. So if you write the value of the variable rpm to your lcd, followed by "00" it will display in rpms.

    If rpm=0 after the subroutine has run then the input was out of range.

    Code:
    convert_to_rpm:
    IF z<10 THEN rpm=0
    IF z=10 THEN rpm=60
    IF z=11 THEN rpm=55
    IF z=12 THEN rpm=50
    IF z=13 THEN rpm=46
    IF z=14 THEN rpm=43
    IF z=15 THEN rpm=40
    IF z=16 THEN rpm=38
    IF z=17 THEN rpm=35
    IF z=18 THEN rpm=33
    IF z=19 THEN rpm=32
    IF z=20 THEN rpm=30
    IF z=21 THEN rpm=29
    IF z=22 THEN rpm=27
    IF z=23 THEN rpm=26
    IF z=24 THEN rpm=25
    IF z=25 THEN rpm=24
    IF z=26 THEN rpm=23
    IF z=27 THEN rpm=22
    IF z>27 AND z<30 THEN rpm=21
    IF z=30 THEN rpm=20
    IF z>30 AND z<33 THEN rpm=19
    IF z>32 AND z<35 THEN rpm=18
    IF z>34 AND z<37 THEN rpm=17
    IF z>36 AND z<39 THEN rpm=16
    IF z>38 AND z<42 THEN rpm=15
    IF z>41 AND z<45 THEN rpm=14
    IF z>44 AND z<49 THEN rpm=13
    IF z>48 AND z<53 THEN rpm=12
    IF z>52 AND z<58 THEN rpm=11
    IF z>57 AND z<64 THEN rpm=10
    IF z>63 AND z<71 THEN rpm=9
    IF z>70 AND z<81 THEN rpm=8
    IF z>80 AND z<93 THEN rpm=7
    IF z>92 AND z<110 THEN rpm=6
    IF z>109 AND z<134 THEN rpm=5
    IF z>133 AND z<172 THEN rpm=4
    IF z>171 AND z<241 THEN rpm=3
    IF z>240 AND z<401 THEN rpm=2
    IF z>400 AND z<1201 THEN rpm=1
    IF z>1200 then rpm=0
    return

  6. #6
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Thanks. A bunch of if-thens came to my mind as well. I just was not sure about it. I think I'll try it.

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Let us know how it goes

  8. #8
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chips123 View Post
    With my millisecond values are integers, I don't expect 100% accuracy. Using PBP, how do I get from say, 16mS to 62Hz ?

    Scott
    Time and Frequency are reciprocal, so you can use a constant (in this case 1000) and divide you mS value into it. For example:

    1000 / 16mS = 62Hz.

    Or if you had 40mS -

    1000 / 40mS = 25Hz etc.

    You are probably kicking yourself right about now

    Regards,

    Andy

  9. #9
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    That would work, but that kind of division in PBP would take up a lot more processing time than the IF...THEN statements above.

  10. #10
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    I may not be understanding something here.

    For the basic math, I would have said:

    rpm=60000/z

    where z is in milliseconds.

    That would work, but that kind of division in PBP would take up a lot more processing time than the IF...THEN statements above.
    My question is: Why would doing that single division take longer than going through multiple IF...THEN statements (40-something of them in the example) until one is found where the condition is satisfied?

    Thanks to whomever clarifies this for me!
    Last edited by RussMartin; - 5th September 2007 at 05:38.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  11. #11
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks Andy.....kick, kick, kick...
    And Russ...equally good insight. I'll kick myself once for you too.
    Almost too obvious, I have been away from math for too long.

    Kamikaze...I tried your solution and ran into an exceeded address 3fff, if I remember correctly. I got sidetracked and have not investigated that further yet.

    Appreciate the input.
    Scott

Similar Threads

  1. HPWM command and oscillator frequency
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2009, 22:41
  2. HPWM10 Frequency Updating
    By duncan303 in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 19th January 2008, 12:30
  3. How do I convert an internal variable into frequency
    By schlaray in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2007, 07:26
  4. inaccurate frequency using TMR1 PI18F452
    By nkarpovich in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 14th October 2006, 16:22
  5. frequency measurement
    By big-x in forum General
    Replies: 2
    Last Post: - 25th November 2005, 00:53

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts