A way to remove lookup tables and calculate those values?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2009
    Posts
    29

    Default A way to remove lookup tables and calculate those values?

    I have a number of lookup tabes to represent a number of plot points for a serial graphics controller. These plotting points are the center points of circles that are drawn. The center points are also in a circular formation. The x and y coordinates that are sent to the controller from the pic are each 2 bytes in length and each byte is sent seperately. In the example below lets say we want to plot 4 evenly spaced dots around a circle. The way I do it now is to lookup for position 0 for x1 (x byte 1), x2 (x byte 2), y1 (y byte 1), and then y2 (y byte 2), then the hole process again for positions 1, 2 and 3. I then send those byte hex values out the seriel pin and repeat. Is there a better way?


    LOOKUP z, [$00, $00, $00, $01], x1
    LOOKUP z, [$00, $33, $88, $FF], x2
    LOOKUP z, [$00, $00, $01, $01], y1
    LOOKUP z, [$00, $3C, $A1, $FF], y2
    SEROUT gpioa.1, 2, [x1,x2,y1,y2]

    Thanks

  2. #2
    Join Date
    Feb 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    I just tried crunching the 4 seperate 8 bit lookups with a single 32 bit lookup2 and it didnt seem to help the speed at all.

    LOOKUP2 z, [$00000000, $0033003C, $008801A1, $01FF01FF], x1
    SEROUT gpioa.1, 2, [x1.BYTE3,x1.BYTE2,x1.BYTE1,x1.BYTE0]

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


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    Can you use the usart serial port? Serout & serout2 are bit bang serial output and
    S L O W your MCU, even debug might be faster.
    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.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    Hi,
    What do you mean by "a better way"? One that executes faster or takes less codespace or looks "cleaner" or just "generally" better?

    Calculating the values will almost certanly increase the execution time (run slower) but might produce less code than a bunch of lookup tables. PBP do have SIN/COS/ATN which might be useful if you're dealing with circles, angles etc but again, it'll probably be slower than a lookuptable.

    Using HSEROUT as Joe suggests will allow the program to continue execute while the byte is being sent. To gain the most out of it you'll need to place the HSEROUT between each lookup, like:
    Code:
    LOOKUP z, [$00, $00, $00, $01], x1   'Get x1
    HSEROUT [x1]                        'Send x1
    LOOKUP z, [$00, $33, $88, $FF], x2   'Now get x2 while x1 is being sent in the background.
    HSEROUT [x2]                        'It's likely that x1 isn't fully sent yet so HSEROUT will "hang" until there's room in TXREG.
    LOOKUP z, [$00, $00, $01, $01], y1
    HSEROUT [y1]
    LOOKUP z, [$00, $3C, $A1, $FF], y2
    HSEROUT [y2]
    That will make it lookup "the next" byte while the previous one is being sent. Lookup is most likely way faster than the time it takes the USART to send the byte so sending the data is still the bottleneck, I think.

    Obviously you can replace the individual HSEROUT statements with a GOSUB by placing the looked up byte in the same variable each time.

    /Henrik.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    Since it is not clear to me what you want to acheive, I will attach a simple program in VB6 from which you can see how to use maths for drawing as many points you want on any given circle. All the maths are inside command1_click and should be not too difficult for you to translate the VB code into PBP code.

    Cheers

    Al.
    Attached Files Attached Files
    All progress began with an idea

  6. #6
    Join Date
    Feb 2009
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    I tried using sin/cos calculations and it resulted in the same speed or maybe slightly slower. I am only using 9600 baud out. This may be where im hanging up. I didnt figure that it would be the bottleneck in the operation. The next test will be to bump up the baud rate and see what happens.

    EDIT: I changed over to the USART and set it up at 19200 and sure enough its displaying the gauge points twice as fast. Now, I have to tie the 2 USART transmit pins together because I have to initiate communication with the GPU at 9600 baud and then change the baud rate. I need to change the baud rate for one USART on the fly and re-DEFINE-ing the baud rate doesnt seem to work.
    Last edited by sccoupe; - 2nd May 2011 at 21:51.

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    I think you will have to address the baud rate reg directly if you want to change on the fly. As near as I can tell, DEFINE will only work once in the program. Someone correct me if I am wrong
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  8. #8
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: A way to remove lookup tables and calculate those values?

    You can change the baud rate "on the fly". I generally try to find a combination of BRGH and BRG16 that will give me both of the baud rates that I want with writing only to SPBRG.

    I normally run at 40Mhz, so with the following in the header

    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 24H
    DEFINE HSER_CLROERR 1

    Then, in the main program...


    You can run at 9600 baud with the statement:

    SPBRG = 255


    Or at 57600 baud with the statement:

    SPBRG = 42
    Charles Linquist

Members who have read this thread : 1

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