I haven't, although here's a generic 'graph lookup' routine I've developed. Too big for 08M. I've put in the data for ArcTan (limiting it to a range of 0 to 82.14 degrees). It seems to work pretty well on the simulator. There's a spreadsheet to work out the data values and it's all pretty complex. Could extend it to 0 to 90 degrees if really required by having a second graph (which it supports).
<code><pre><font size=2 face='Courier'>
#picaxe 18x
'############################################################################
'# EEPROM #
'############################################################################
'GRAPH DEFINITION TABLE
'Record0 (ArcTan)
EEPROM 0, (10) 'DataStartAddress (Byte value)
EEPROM 1, (0) 'StartX_ID (Byte value)
EEPROM 2, (30) 'NumYValues (Byte value)
EEPROM 3, (6,1 ) 'X_Interval (Word value)
'ArcTan graph data
EEPROM 10 ,(0,0)
EEPROM 12 ,(245,5)
EEPROM 14 ,(226,10)
EEPROM 16 ,(213,14)
EEPROM 18 ,(251,17)
EEPROM 20 ,(122,20)
EEPROM 22 ,(115,22)
EEPROM 24 ,(2,24)
EEPROM 26 ,(63,25)
EEPROM 28 ,(61,26)
EEPROM 30 ,(10,27)
EEPROM 32 ,(179,27)
EEPROM 34 ,(66,28)
EEPROM 36 ,(189,28)
EEPROM 38 ,(41,29)
EEPROM 40 ,(138,29)
EEPROM 42 ,(225,29)
EEPROM 44 ,(49,30)
EEPROM 46 ,(122,30)
EEPROM 48 ,(187,30)
EEPROM 50 ,(245,30)
EEPROM 52 ,(40,31)
EEPROM 54 ,(85,31)
EEPROM 56 ,(123,31)
EEPROM 58 ,(157,31)
EEPROM 60 ,(189,31)
EEPROM 62 ,(220,31)
EEPROM 64 ,(0,32)
EEPROM 66 ,(45,32)
EEPROM 68 ,(104,32)
'############################################################################
'# DECLARATIONS #
'############################################################################
Symbol PARAM_W0 = 110
Symbol PARAM_0 = 110
Symbol PARAM_1 = 111
Symbol PARAM_W1 = 112
Symbol PARAM_2 = 112
Symbol PARAM_3 = 113
'Graph IDs
Symbol Graph_ArcTan = 0
'############################################################################
'# DEMO #
'############################################################################
Demo:
'Demo's use of Graph lookup for ArcTan.
'The value poked is 1000*the Tan value. MUST be in range 0 to 7250.
'The value returned is 100 * the degree value.
'NOTE: Current graph settings is for angle in range 0 to 82.140 degrees.
Poke PARAM_0,Graph_ArcTan
w0 = 456
Poke PARAM_W1,Word w0
Gosub GraphLookup
Peek PARAM_W0,Word w0
SerTxd ("ArcTan 0.456 = ",#w0)
End
#Rem
'############################################################################
'# GRAPH LOOKUP MODULE. J.Leach March 2007 #
'############################################################################
INTRODUCTION:
This module allows lookup of Y-(Word)values from EEPROM, given a known X-(Word)value.
EEPROM holds Y-values for a set of sequential, evenly spaced X-values, spaced at
X-Interval. The result is an interpolated value of Y between the known points
on the graph:
___-
o -'''
/.
/´ .
---------------- o .
Y-Value /´| .
o- | .
/´. | .
/ . | .
/´ . | .
/ . | .
/´ . | .
. | .
Lower X_ID | Upper X_ID
| | |
| | |
v | v
+-----------+---------+---------+---------+
X_ID: Xn Xn+1 Xn+2 Xn+3 Xn+4 ....
<--------->
X-Interval
^
|
Given X-Value
GRAPH DEFINITION TABLE:
This is an indexed table in EEPROM that holds the following data for each Graph:
- DataStartAddress (Byte Value)
- StartX_ID (Byte Value)
- NumYValues (Byte value)
- X_Interval (Word value)
LIMITATIONS:
- Maximum value X_Interval can take is 655, to avoid overflow in calcs.
- Maximum difference between successive Y_Values is 6553 to avoid overflow in calcs.
NOTES:
1.If the given X_Value is greater than the maximum X_ID defined by the Graph data, then the
Y_Result value is set to be that of the end point on the graph.
2.If the given X_Value is less than the StartX_ID defined by the Graph data, then the Y_Result
value is set to be that of the start point of the graph.
#endrem
Symbol EEPROM_GraphDefinitionTable = 0 'Set it to whatever is conveinient.
Symbol DefinitionBytes = 5 'The number of bytes used by each 'record' of definition
'in the Graph Definition Table.
Symbol LowerIndex = b0 'The index to the lower Y-Value in the EEPROM Graph data.
Symbol EEPROM_Address = b1 'General purpose address variable.
Symbol Graph_ID = b1 'The ID of the graph.
Symbol DataStartAddress = b2 'The start address of the graph data.
Symbol NumYValues = b3 'The number of Y Values stored in EEPROM.
Symbol MaxLowerIndex = b3 'The maximum permissible LowerIndex
Symbol StartX_ID = b4 'The X_ID of the first data point stored in EEPROM.
Symbol LowerX_ID = b5 'The lower X_ID corresponding to the X_Value.
Symbol PercOfInterval = b5 'The percentage that the X-Value is between intervals.
Symbol X_Interval = w3 'The difference between successive X_IDs on the X axis.
Symbol Y_Lower = w4 'The Y value corresponding to the Lower X_ID.
Symbol Y_Upper = w5 'The Y value corresponding to the Upper X_ID.
Symbol Y_Difference = w6 'The absolute difference between Y_Lower and Y_Upper.
Symbol Y_Result = w6 'The result value.
Symbol X_Value = w6 'The given X.
GraphLookup:
'ON ENTRY: PARAM_0 (Graph_ID) holds the index to the Graph to use
' PARAM_W1 (X_Value) is the known X-value (Word).
'ON EXIT: PARAM_W0 (Y_Result) holds the result.
'Load the variables
Peek PARAM_0,Graph_ID
Peek PARAM_W1,Word X_Value
'Get the graph definition values.
EEPROM_Address = DefinitionBytes * Graph_ID + EEPROM_GraphDefinitionTable
Read EEPROM_Address,DataStartAddress,StartX_ID,NumYValues,Word X_Interval
'Determine if Lower X_ID is less than the StartX_ID.
LowerX_ID = X_Value / X_Interval
If LowerX_ID >= StartX_ID Then X_ID_OK
'X_Value is outside the graph data, so set the Y_Result to be that of the
'the start point of the graph.
Read DataStartAddress,Word Y_Result
Return
X_ID_OK:
'Determine the maximum permissible LowerIndex value.
MaxLowerIndex = NumYValues - 2
'Determine the LowerIndex value.
LowerIndex = LowerX_ID - StartX_ID
If LowerIndex > MaxLowerIndex Then
'The X_Value is off the end of the Graph data, so set the Y_Result to be
'that of the end point on the graph.
EEPROM_Address = MaxLowerIndex + 1 * 2 + DataStartAddress
Read EEPROM_Address,Word Y_Result
Else
PercOfInterval = X_Value // X_Interval * 100 / X_Interval
'Get the Lower and Upper Y-values.
EEPROM_Address = LowerIndex * 2 + DataStartAddress
Read EEPROM_Address, Word Y_Lower,Word Y_Upper
'Calculate the result
If Y_Lower <= Y_Upper Then
Y_Difference = Y_Upper - Y_Lower
Y_Result = Y_Difference / 10 * PercOfInterval / 10 + Y_Lower
Else
Y_Difference = Y_Lower - Y_Upper
Y_Result = Y_Difference / 10 * PercOfInterval / 10
Y_Result = Y_Lower - Y_Result
EndIf
Endif
'Save the result
Poke PARAM_W0,Word Y_Result
Return
</font></pre></code>
Edited by - jeremy leach on 02/06/2007 17:56:13