Linear to S Curve conversion


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Gain!
    x-aSIN(B)
    a is the gain.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mat janssen View Post
    Gain!
    x-aSIN(B)
    a is the gain.
    Yup again,

    But, PBP will have problems trying to multiply the negative values from the SIN function.
    So you'll need to remove the sign before multiplying.

    Been playing with it here. I think this program might do what you want Jon.

    It's only for 1 axis, but it should get you started. There are 3 POT's in this example. AN0 is the axis input, AN1 is the Gain setting, and AN2 is a Trim setting. 10-turn 10K pots should be good for the Gain and Trim.

    It uses HSEROUT to display the results in Hyperterminal.
    Code:
    <code><font color="#008000"><b>DEFINE </b></font><b>ADC_BITS </b><font color="#800000"><b>10
    </b></font><b>ADCON1</b>.<font color="#800000"><b>7 </b></font>= <font color="#800000"><b>1        </b></font><font color="#0000FF"><b><i>; Right Justify
    ;ADCON2.7 = 1        ; 18F4550
    
    </i></b></font><b>NEG      </b><font color="#008000"><b>VAR BIT
    </b></font><b>Temp     </b><font color="#008000"><b>VAR BYTE
    </b></font><b>Result   </b><font color="#008000"><b>VAR WORD
    </b></font><b>Xaxis    </b><font color="#008000"><b>VAR WORD
    </b></font><b>Xgain    </b><font color="#008000"><b>VAR WORD
    </b></font><b>Xtrim    </b><font color="#008000"><b>VAR WORD
    </b></font><b>ADvalue  </b><font color="#008000"><b>VAR WORD
    </b></font><b>GainAvg  </b><font color="#008000"><b>VAR WORD
    </b></font><b>TrimAvg  </b><font color="#008000"><b>VAR WORD
    </b></font><b>Avg      </b><font color="#008000"><b>VAR WORD
    </b></font><b>AvgCount </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>16
    </b></font><b>spread   </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>50
    
    </b></font><b>Main</b>:
        <font color="#008000"><b>ADCIN  </b></font><font color="#800000"><b>0</b></font>, <b>Xaxis               </b><font color="#0000FF"><b><i>; Axis input is not averaged
       
        </i></b></font><font color="#008000"><b>ADCIN  </b></font><font color="#800000"><b>1</b></font>, <b>ADvalue             </b><font color="#0000FF"><b><i>; 0 = no gain, 1023 = gain 3.98
        </i></b></font><b>Avg </b>= <b>GainAvg </b>: <font color="#008000"><b>GOSUB </b></font><b>Average </b><font color="#0000FF"><b><i>; Gain is averaged to stabilize it's value
        </i></b></font><b>Xgain </b>= <b>Avg   </b>: <b>GainAvg </b>= <b>Avg
        
        </b><font color="#008000"><b>ADCIN  </b></font><font color="#800000"><b>2</b></font>, <b>ADvalue             </b><font color="#0000FF"><b><i>; 0 = adjust center -127, 1023 = adjust +128
        </i></b></font><b>Avg </b>= <b>TrimAvg </b>: <font color="#008000"><b>GOSUB </b></font><b>Average </b><font color="#0000FF"><b><i>; Trim is averaged to stabilize it's value
        </i></b></font><b>Xtrim </b>= <b>Avg   </b>: <b>TrimAvg </b>= <b>Avg
        
    </b><font color="#0000FF"><b><i>;--- Add Sine and Trim to the Xaxis input ------------------------------------
        </i></b></font><b>Temp </b>= <font color="#008000"><b>SIN</b></font>(<b>Xaxis</b>&gt;&gt;<font color="#800000"><b>2</b></font>)
        <b>NEG </b>= <b>Temp</b>.<font color="#800000"><b>7
        </b></font><b>Result </b>= <font color="#008000"><b>ABS</b></font>(<b>Temp</b>) */ <b>Xgain
        </b><font color="#008000"><b>IF </b></font><b>NEG </b><font color="#008000"><b>THEN </b></font><b>Result </b>= -<b>Result
        Result </b>= <b>Xaxis </b>+ <b>Result </b>+ (<b>Xtrim </b>&gt;&gt; <font color="#800000"><b>2 </b></font>- <font color="#800000"><b>127</b></font>)
    
    <font color="#0000FF"><b><i>;--- Display the results in HyperTerminal ------------------------------------
        </i></b></font><font color="#008000"><b>HSEROUT </b></font>[<font color="#800000"><b>27</b></font>,<font color="#FF0000">&quot;[H&quot;</font>,<font color="#FF0000">&quot;Xaxis = &quot;</font>,<font color="#008000"><b>DEC </b></font><b>Xaxis</b>,<font color="#FF0000">&quot;    &quot;</font>,<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>, <b>_
          </b><font color="#FF0000">&quot;Xgain = &quot;</font>,<font color="#008000"><b>DEC </b></font><b>Xgain</b>&gt;&gt;<font color="#800000"><b>8</b></font>,<font color="#FF0000">&quot;.&quot;</font>,<font color="#008000"><b>DEC2 </b></font>((<b>Xgain </b>&amp; <font color="#800000"><b>$0FF</b></font>) */ <font color="#800000"><b>100</b></font>),<font color="#FF0000">&quot;    &quot;</font>,<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>, <b>_
          </b><font color="#FF0000">&quot;Xtrim = &quot;</font>,<font color="#008000"><b>SDEC </b></font>(<b>Xtrim </b>&gt;&gt; <font color="#800000"><b>2 </b></font>- <font color="#800000"><b>127</b></font>),<font color="#FF0000">&quot;    &quot;</font>,<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>, <b>_
          </b><font color="#FF0000">&quot;Result= &quot;</font>,<font color="#008000"><b>SDEC </b></font><b>Result</b>,<font color="#FF0000">&quot;    &quot;</font>,<font color="#800000"><b>13</b></font>,<font color="#800000"><b>10</b></font>]
         
        <font color="#008000"><b>PAUSE </b></font><font color="#800000"><b>100
    </b></font><font color="#008000"><b>GOTO </b></font><b>Main
    
    </b><font color="#0000FF"><b><i>' -=-=-=-=-=-=  Average Analog values -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    </i></b></font><b>Average</b>:    <font color="#0000FF"><b><i>' Smooth data
        </i></b></font><font color="#008000"><b>IF ABS </b></font>(<b>ADvalue </b>- <b>Avg</b>) &gt; <b>spread </b><font color="#008000"><b>THEN
            </b></font><b>Avg </b>= <b>ADvalue
        </b><font color="#008000"><b>ELSE
            </b></font><b>Avg </b>= (<b>Avg</b>*(<b>AvgCount</b>-<font color="#800000"><b>1</b></font>)+<b>ADvalue</b>)/<b>AvgCount 
        </b><font color="#008000"><b>ENDIF
    RETURN
    
    </b></font>
    The output in Hyperterminal should look like this ... (in real time)



    HTH,
    DT

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 02:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 17:26
  3. Conversion problem
    By eva in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th March 2007, 19:21
  4. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 19:20
  5. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 02:35

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