How do you convert an algorithm to code?


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Thanks for all of the input. After working on it a while, I ran into the same problems that you guys pointed out. Here is where I ended up. It required LONGs for me to get it to work right. When I started to look at it, I had no idea how to do it. Why is it that some projects seem to make you need every function or process that you are new at?

    Code:
    <font color="#000000"><b>DEFINE </b>OSC 8 
    <b>DEFINE </b>DEBUG_REG PORTA 
    <b>DEFINE </b>DEBUG_BIT 0
    <b>DEFINE </b>DEBUG_BAUD 2400 
    <b>DEFINE </b>DEBUG_MODE 0
    
    TRISA   = %00100000      <font color="#0000FF"><i>' PortA : All outputs except RA.1 for INT_INT
    </i></font>TRISB   = %01000100      <font color="#0000FF"><i>' PWM1,3,5 outputs,RB2=INT, RB0,2,3: DIO
    </i></font>ADCON1  = %00001111      <font color="#0000FF"><i>' Set up ADCON1 
    </i></font>OSCCON  = %11111110      <font color="#0000FF"><i>' INTOSC, 8MHz
    </i></font>EchoTime     <b>VAR    WORD
    </b>Term1        <b>VAR    WORD
    </b>Term2        <b>VAR    WORD
    </b>Term3        <b>VAR    LONG      </b><font color="#0000FF"><i>' making this LONG solved the problem
    </i></font>Duty0        <b>VAR    WORD
    </b>Near0        <b>VAR    WORD
    </b>Far0         <b>VAR    WORD
    </b>EchoTime = 28750              <font color="#0000FF"><i>' test value for the measurement
    </i></font>Near0     = 6500              <font color="#0000FF"><i>' test setting for the minimum reading
    </i></font>Far0     = 51000              <font color="#0000FF"><i>' test setting for the maximum
    </i></font><b>DEBUG </b><font color="#FF0000">&quot;1330-2l&quot;</font>,13,10          <font color="#0000FF"><i>' splash
    
    </i></font>Main:
    Term1 =    Far0 - Near0           <font color="#0000FF"><i>'51000 - 6500 = 44500
    </i></font>Term2 =    EchoTime-Near0         <font color="#0000FF"><i>'25500 - 6500 = 19000
    </i></font>Term3 =    Term2*1000             <font color="#0000FF"><i>'19000 * 1000 = 19000000
    </i></font>Duty0 =    Term3/Term1            <font color="#0000FF"><i>'19000000/44500 = 426.996
    '                ' Word won't work: divisor&gt;32767, Need Long
    
    ' Duty0 = (EchoTime-Near0)/(Far0-Near0)*1000 
     </i></font><b>DEBUG </b>#Term1,<font color="#FF0000">&quot; &quot;</font>,#Term2,<font color="#FF0000">&quot; &quot;</font>,#Duty0,  13,10
     <b>PAUSE </b>700
     <b>GOTO </b>Main
    Thank you all for looking at it.
    Bo

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Wink

    Ähhh....

    What's about the DIV32-command ?
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  3. #3
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Thought about the DIV32 way, but I hadn't done either before and figured that the LONGs were the newest, so that was where I would concentrate my efforts unless pointed otherwise.

    I'm sure it would work, but I had to have a reason to justify my recent upgrade :-)

    Bo

Similar Threads

  1. Convert code 12C508 to 12F508
    By Olivier in forum General
    Replies: 2
    Last Post: - 25th October 2009, 16:19
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. convert code "c" lcd graphic to pbp
    By nicolasronan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2006, 15:49

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