Converting milliseconds to frequency


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Question Then, when should we use lookup ???

    All this thread bring back a question that I had in mind for a while. I was wondering at which point is that better (faster) to use lookup instead of calculated values?

    I know that I can find thread like "Sine wave power inverter" where a lookup table was used to increase calculation's speed. But is this only a trial an error process or can someone bring up guidelines that will lead to use one solution or the other?

    J-P
    Last edited by GrandPa; - 5th September 2007 at 04:48.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Question

    One more thought . . . instead of 40 IF THEN loops would't SELECT CASE be more appropriate? I throw this out there, having NEVER used select case, because you see, I want to learn too . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    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.
    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!
    I'm sure that SELECT CASE could be used, or LOOKDOWN (or should it be LOOKUP?), depending on the strategy, and maybe more effectively than IF...THENs. In all of those cases, though, it still looks like a bulky approach. I'm still not convinced that the single 16-bit division isn't going to be not only simpler but faster.

    Any thoughts? Is this one of those balancing acts between compact code and speed of operation?

    Scott, how often do you need to update the display with new information?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here is all the IF/THENS in ASM
    Code:
    	LABEL?L	_convert_to_rpm	
    
    	CMPGE?BCL	_z, 00Ah, L00001
    	MOVE?CB	000h, _rpm
    	LABEL?L	L00001	
    
    	CMPNE?BCL	_z, 00Ah, L00003
    	MOVE?CB	03Ch, _rpm
    	LABEL?L	L00003	
    
    	CMPNE?BCL	_z, 00Bh, L00005
    	MOVE?CB	037h, _rpm
    	LABEL?L	L00005	
    
    	CMPNE?BCL	_z, 00Ch, L00007
    	MOVE?CB	032h, _rpm
    	LABEL?L	L00007	
    
    	CMPNE?BCL	_z, 00Dh, L00009
    	MOVE?CB	02Eh, _rpm
    	LABEL?L	L00009	
    
    	CMPNE?BCL	_z, 00Eh, L00011
    	MOVE?CB	02Bh, _rpm
    	LABEL?L	L00011	
    
    	CMPNE?BCL	_z, 00Fh, L00013
    	MOVE?CB	028h, _rpm
    	LABEL?L	L00013	
    
    	CMPNE?BCL	_z, 010h, L00015
    	MOVE?CB	026h, _rpm
    	LABEL?L	L00015	
    
    	CMPNE?BCL	_z, 011h, L00017
    	MOVE?CB	023h, _rpm
    	LABEL?L	L00017	
    
    	CMPNE?BCL	_z, 012h, L00019
    	MOVE?CB	021h, _rpm
    	LABEL?L	L00019	
    
    	CMPNE?BCL	_z, 013h, L00021
    	MOVE?CB	020h, _rpm
    	LABEL?L	L00021	
    
    	CMPNE?BCL	_z, 014h, L00023
    	MOVE?CB	01Eh, _rpm
    	LABEL?L	L00023	
    
    	CMPNE?BCL	_z, 015h, L00025
    	MOVE?CB	01Dh, _rpm
    	LABEL?L	L00025	
    
    	CMPNE?BCL	_z, 016h, L00027
    	MOVE?CB	01Bh, _rpm
    	LABEL?L	L00027	
    
    	CMPNE?BCL	_z, 017h, L00029
    	MOVE?CB	01Ah, _rpm
    	LABEL?L	L00029	
    
    	CMPNE?BCL	_z, 018h, L00031
    	MOVE?CB	019h, _rpm
    	LABEL?L	L00031	
    
    	CMPNE?BCL	_z, 019h, L00033
    	MOVE?CB	018h, _rpm
    	LABEL?L	L00033	
    
    	CMPNE?BCL	_z, 01Ah, L00035
    	MOVE?CB	017h, _rpm
    	LABEL?L	L00035	
    
    	CMPNE?BCL	_z, 01Bh, L00037
    	MOVE?CB	016h, _rpm
    	LABEL?L	L00037	
    
    	CMPGT?BCB	_z, 01Bh, T1
    	CMPLT?BCB	_z, 01Eh, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00039
    	MOVE?CB	015h, _rpm
    	LABEL?L	L00039	
    
    	CMPNE?BCL	_z, 01Eh, L00041
    	MOVE?CB	014h, _rpm
    	LABEL?L	L00041	
    
    	CMPGT?BCB	_z, 01Eh, T1
    	CMPLT?BCB	_z, 021h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00043
    	MOVE?CB	013h, _rpm
    	LABEL?L	L00043	
    
    	CMPGT?BCB	_z, 020h, T1
    	CMPLT?BCB	_z, 023h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00045
    	MOVE?CB	012h, _rpm
    	LABEL?L	L00045	
    
    	CMPGT?BCB	_z, 022h, T1
    	CMPLT?BCB	_z, 025h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00047
    	MOVE?CB	011h, _rpm
    	LABEL?L	L00047	
    
    	CMPGT?BCB	_z, 024h, T1
    	CMPLT?BCB	_z, 027h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00049
    	MOVE?CB	010h, _rpm
    	LABEL?L	L00049	
    
    	CMPGT?BCB	_z, 026h, T1
    	CMPLT?BCB	_z, 02Ah, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00051
    	MOVE?CB	00Fh, _rpm
    	LABEL?L	L00051	
    
    	CMPGT?BCB	_z, 029h, T1
    	CMPLT?BCB	_z, 02Dh, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00053
    	MOVE?CB	00Eh, _rpm
    	LABEL?L	L00053	
    
    	CMPGT?BCB	_z, 02Ch, T1
    	CMPLT?BCB	_z, 031h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00055
    	MOVE?CB	00Dh, _rpm
    	LABEL?L	L00055	
    
    	CMPGT?BCB	_z, 030h, T1
    	CMPLT?BCB	_z, 035h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00057
    	MOVE?CB	00Ch, _rpm
    	LABEL?L	L00057	
    
    	CMPGT?BCB	_z, 034h, T1
    	CMPLT?BCB	_z, 03Ah, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00059
    	MOVE?CB	00Bh, _rpm
    	LABEL?L	L00059	
    
    	CMPGT?BCB	_z, 039h, T1
    	CMPLT?BCB	_z, 040h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00061
    	MOVE?CB	00Ah, _rpm
    	LABEL?L	L00061	
    
    	CMPGT?BCB	_z, 03Fh, T1
    	CMPLT?BCB	_z, 047h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00063
    	MOVE?CB	009h, _rpm
    	LABEL?L	L00063	
    
    	CMPGT?BCB	_z, 046h, T1
    	CMPLT?BCB	_z, 051h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00065
    	MOVE?CB	008h, _rpm
    	LABEL?L	L00065	
    
    	CMPGT?BCB	_z, 050h, T1
    	CMPLT?BCB	_z, 05Dh, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00067
    	MOVE?CB	007h, _rpm
    	LABEL?L	L00067	
    
    	CMPGT?BCB	_z, 05Ch, T1
    	CMPLT?BCB	_z, 06Eh, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00069
    	MOVE?CB	006h, _rpm
    	LABEL?L	L00069	
    
    	CMPGT?BCB	_z, 06Dh, T1
    	CMPLT?BCB	_z, 086h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00071
    	MOVE?CB	005h, _rpm
    	LABEL?L	L00071	
    
    	CMPGT?BCB	_z, 085h, T1
    	CMPLT?BCB	_z, 0ACh, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00073
    	MOVE?CB	004h, _rpm
    	LABEL?L	L00073	
    
    	CMPGT?BCB	_z, 0ABh, T1
    	CMPLT?BCB	_z, 0F1h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00075
    	MOVE?CB	003h, _rpm
    	LABEL?L	L00075	
    
    	CMPGT?BCB	_z, 0F0h, T1
    	CMPLT?BCB	_z, 00191h, T2
    	LAND?BBW	T1, T2, T2
    	CMPF?WL	T2, L00077
    	MOVE?CB	002h, _rpm
    	LABEL?L	L00077	
    
    	CMPGT?BCB	_z, 00190h, T1
    	CMPLT?BCB	_z, 004B1h, T2
    	LAND?BBW	T1, T2, T2
    
    	CMPF?WL	T2, L00079
    	MOVE?CB	001h, _rpm
    	LABEL?L	L00079	
    
    	CMPLE?BCL	_z, 004B0h, L00081
    	MOVE?CB	000h, _rpm
    	LABEL?L	L00081	
    
    	GOTO?L	_convert_to_rpm
    And here is the WORD division in ASM.
    Code:
    	LABEL?L	_TEST	
    
    	MOVE?CW	003E8h, _FREQ
    
    	MOVE?CW	010h, _SPEED
    
    	DIV?WWW	_FREQ, _SPEED, _ROTATIONS
    
    	GOTO?L	_TEST
    Do not know about CASE either.
    Last edited by mackrackit; - 5th September 2007 at 21:32.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks, Dave! That was a lot of extra effort to answer the question, but I appreciate it. I'm sure others will, too!

    Scott--what do you think?
    Last edited by RussMartin; - 5th September 2007 at 23:31.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No problem, PBP did all of the work.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Thumbs up

    Russ...The 60000 math thing worked great. The digits changing on the LCD actually looks quite natural and "smooth". It doesn't look jerky. It is faster that you can read.

    I applied all of this to another project where I am driving a stepper motor as a position indicator, ie. a needle on a scale. I am quite satisfied with it.

    The only issue I see with my current calculations is that a change in a millisecond at the high end of the scale represents a larger change in RPM than a millisecond does at the lower speeds. This makes the needle seem a bit twitchy at the higher speeds. I plan to see what I can do to improve that somewhat.

    I initially attempted this project using COUNT . It worked, but moving the needle was painfully slow.

    Thanks for all the input
    Scott
    Last edited by chips123; - 6th September 2007 at 02:54.

Similar Threads

  1. HPWM command and oscillator frequency
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2009, 23:41
  2. HPWM10 Frequency Updating
    By duncan303 in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 19th January 2008, 13: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, 08:26
  4. inaccurate frequency using TMR1 PI18F452
    By nkarpovich in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 14th October 2006, 17:22
  5. frequency measurement
    By big-x in forum General
    Replies: 2
    Last Post: - 25th November 2005, 01: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