Converting milliseconds to frequency


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    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.

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Let us know how it goes

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