awdgsx
- 4th April 2012, 18:15
I'm trying to figure out how to do a complete 256 byte eeprom write and dump with usb. any help would be appreciated..
here is the code I found for doing it with serial..
<TBODY>
<CODE class="vb comments">' Name : EE.pbp </CODE>
</TBODY>
<TBODY>
<CODE>02</CODE>
<CODE class="vb comments">' Compiler : PICBASIC PRO Compiler 2.6 </CODE>
</TBODY>
<TBODY>
<CODE>03</CODE>
<CODE class="vb comments">' Assembler : PM or MPASM </CODE>
</TBODY>
<TBODY>
<CODE>04</CODE>
<CODE class="vb comments">' Target PIC : 12F, 16F or 18F types </CODE>
</TBODY>
<TBODY>
<CODE>05</CODE>
<CODE class="vb comments">' Hardware : Non specific </CODE>
</TBODY>
<TBODY>
<CODE>06</CODE>
<CODE class="vb comments">' Oscillator : internal or external </CODE>
</TBODY>
<TBODY>
<CODE>07</CODE>
<CODE class="vb comments">' Keywords : READ, SEROUT, WRITE </CODE>
</TBODY>
<TBODY>
<CODE>08</CODE>
<CODE class="vb comments">' Description : PICBASIC PRO program to demonstate the EEPROM, READ and WRITE Commands. </CODE>
</TBODY>
<TBODY>
<CODE>09</CODE>
<CODE class="vb comments">' Works on targets with data EE only!!! Initialized address 0..3 and 8. Writes 10..63. </CODE>
</TBODY>
<TBODY>
<CODE>10</CODE>
<CODE class="vb comments">' </CODE>
</TBODY>
<TBODY>
<CODE>11</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>12</CODE>
<CODE class="vb keyword">Include</CODE> <CODE class="vb string">"modedefs.bas"</CODE> <CODE class="vb comments">' Include serial modes </CODE>
</TBODY>
<TBODY>
<CODE>13</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>14</CODE>
<CODE class="vb plain">SO </CODE><CODE class="vb keyword">Con</CODE> <CODE class="vb plain">0 </CODE><CODE class="vb comments">' Define serial output pin </CODE>
</TBODY>
<TBODY>
<CODE>15</CODE>
<CODE class="vb plain">B0 </CODE><CODE class="vb keyword">Var</CODE> <CODE class="vb keyword">byte</CODE>
</TBODY>
<TBODY>
<CODE>16</CODE>
<CODE class="vb plain">B1 </CODE><CODE class="vb keyword">Var</CODE> <CODE class="vb keyword">byte</CODE>
</TBODY>
<TBODY>
<CODE>17</CODE>
<CODE class="vb plain">B2 </CODE><CODE class="vb keyword">Var</CODE> <CODE class="vb keyword">byte</CODE>
</TBODY>
<TBODY>
<CODE>18</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>19</CODE>
<CODE class="vb keyword">EEPROM</CODE> <CODE class="vb plain">[</CODE><CODE class="vb string">"wxyz"</CODE><CODE class="vb plain">] </CODE><CODE class="vb comments">' EEPROM[0..3] = 119..122 </CODE>
</TBODY>
<TBODY>
<CODE>20</CODE>
<CODE class="vb keyword">EEPROM</CODE> <CODE class="vb plain">8,[100] </CODE><CODE class="vb comments">' EEPROM[8] = 100 </CODE>
</TBODY>
<TBODY>
<CODE>21</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>22</CODE>
<CODE class="vb plain">mainloop: </CODE>
</TBODY>
<TBODY>
<CODE>23</CODE>
<CODE class=spaces> </CODE><CODE class="vb plain">B0 = 63 </CODE><CODE class="vb comments">' Set Size of EEPROM </CODE>
</TBODY>
<TBODY>
<CODE>24</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>25</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">For</CODE> <CODE class="vb plain">B1 = 10 </CODE><CODE class="vb keyword">To</CODE> <CODE class="vb plain">B0 </CODE><CODE class="vb comments">' Check WRITE Command </CODE>
</TBODY>
<TBODY>
<CODE>26</CODE>
<CODE class=spaces> </CODE><CODE class="vb plain">B2 = B1 + 100 </CODE><CODE class="vb comments">' EEPROM[10..63] = 110..163 </CODE>
</TBODY>
<TBODY>
<CODE>27</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Write</CODE> <CODE class="vb plain">B1,B2 </CODE>
</TBODY>
<TBODY>
<CODE>28</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Next</CODE> <CODE class="vb plain">B1 </CODE>
</TBODY>
<TBODY>
<CODE>29</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>30</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">For</CODE> <CODE class="vb plain">B1 = 0 </CODE><CODE class="vb keyword">To</CODE> <CODE class="vb plain">B0 </CODE><CODE class="vb comments">' Check READ Command </CODE>
</TBODY>
<TBODY>
<CODE>31</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Read</CODE> <CODE class="vb plain">B1,B2 </CODE><CODE class="vb comments">' Dump EEPROM Contents </CODE>
</TBODY>
<TBODY>
<CODE>32</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Serout</CODE> <CODE class="vb plain">SO,N2400,[#B2,</CODE><CODE class="vb string">" "</CODE><CODE class="vb plain">] </CODE>
</TBODY>
<TBODY>
<CODE>33</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Next</CODE> <CODE class="vb plain">B1 </CODE>
</TBODY>
<TBODY>
<CODE>34</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>35</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Serout</CODE> <CODE class="vb plain">SO,N2400,[10,10] </CODE><CODE class="vb comments">' Skip 2 Lines </CODE>
</TBODY>
<TBODY>
<CODE>36</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Goto</CODE> <CODE class="vb plain">mainloop </CODE><CODE class="vb comments">' Forever </CODE>
</TBODY>
<TBODY>
<CODE>37</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>38</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">End</CODE>
</TBODY>
Here is my code so far. The program takes a 0-5V input, converts it to a flow with a program memory lookup table. will eventually do some math to the flow value, then takes the flow value and converts it back to AD counts in an eeprom lookup table for an external DAC.
I would like to send letters to the pic from a VB program telling it to either write eeprom, read eeprom, send flow value, send v out value, etc.
Include "cdc_desc.bas" ' Include the HID descriptors
Define OSC 48
define ADC_BITS 10
Define ADC_clock 6
Define ADC_sampleus 3
' initial EEPROM values (flow to dac counts out)
DATA WORD 0,WORD 16,WORD 32,WORD 48,WORD 64,WORD 80,WORD 96,WORD 112,WORD 128
DATA WORD 144,WORD 160,WORD 176,WORD 192,WORD 208,WORD 224,WORD 240,WORD 256
DATA WORD 272,WORD 288,WORD 304,WORD 320,WORD 336,WORD 352,WORD 368,WORD 384
DATA WORD 400,WORD 416,WORD 432,WORD 448,WORD 464,WORD 480,WORD 496
DATA WORD 512,WORD 528,WORD 544,WORD 560,WORD 576,WORD 592,WORD 608,WORD 624,WORD 640
DATA WORD 656,WORD 672,WORD 688,WORD 704,WORD 720,WORD 736,WORD 752,WORD 768
DATA WORD 784,WORD 800,WORD 816,WORD 832,WORD 848,WORD 864,WORD 880,WORD 896
DATA WORD 912,WORD 928,WORD 944,WORD 960,WORD 976,WORD 992,WORD 1008
DATA WORD 1024,WORD 1024
'eeprom 230, [254,0,210,0,190,0,100,0,60,0,40,0,30,0,0,0] 'temp out table word size ohm out values
'eeprom 244, [147,147,130,130,125,125,125,120,120,115,115,115,11 5,115,115,115] 'desired afr table
'eeprom 250, [122,0] 'displacement scalar
'eeprom 252, [ 50] 'min load for auto tune
eeprom 253, [ 100,0] 'tube size scalar (tube area used vs tube size used for orginal calculations)
buffer Var Byte[16]
cnt Var Byte[16]
mafin var word
mafout var byte[2]
maf0 var byte
maf1 var byte
outputval VAR WORD ' output value
tempval VAR WORD ' temporary
tablehigh VAR WORD ' high table value
tablelow VAR WORD ' low table value
tempval2 VAR WORD ' temporary #2
flow var word
inputtable con ext
mafscalar var word
hzout var word
flowinval var word
flowinval2 var word
flowinval3 var word
flowinval4 var word
flowfinal var word
' OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10
TRISC = %11000000
ADCON2 = %10000000
ANSELH = %00000010
USBInit ' Get USB going
startloop:
Adcin 9, mafin
READ 253, mafscalar
goto overdata
'0-5v hpx-e transfer function in 2.9 tube
asm
inputtable
DW 0, 0, 0, 0, 0, 7, 12, 16, 20, 24, 28, 33, 39, 45, 53, 62, 72, 83, 94, 107
DW 121, 136, 152, 169, 188, 208, 229, 252, 277, 304, 332, 363, 395, 430, 468
DW 507, 549, 594, 641, 691, 743, 798, 855, 915, 977, 1043, 1110, 1181, 1255
DW 1331, 1410, 1493, 1579, 1668, 1761, 1858, 1960, 2065, 2175, 2289, 2408, 2532
DW 2659, 2791, 2925, 2925
endasm
overdata:
usbservice
tempval = mafin >> 3 ' shift input for table lookup
tempval2 = tempval & %1111111111111110 ' clear last bit for WORD lookup
'get table high and low values
READcode (inputtable+tempval2+2),tablehigh.BYTE0
READcode (inputtable+tempval2+3),tablehigh.BYTE1
READcode (inputtable+tempval2),tablelow.BYTE0
READcode (inputtable+tempval2+1),tablelow.BYTE1
'Table Interpolation
tempval = mafin & %0000000000001111 ' get interpolation value
IF tablehigh >= tablelow THEN ' get space between table values
tempval2 = tablehigh - tablelow '
ELSE '
tempval2 = tablelow - tablehigh '
ENDIF '
tempval = tempval2 * tempval 'multiply high/low diff by interp value
flow = tempval >> 4 'divide by table spacing
IF tablehigh >= tablelow THEN ' offset table value by calculated
flow = flow + tablelow ' interpolation value
ELSE '
flow = tablelow - flow '
ENDIF '
flowsub:
usbservice
'mafscalar = mafscalar/100
' flow = flow*mafscalar 'multiply flow value by maf housing size scalar
flowfinal = flow
if flowfinal > 511 then goto mafouthighloop
mafoutlowloop:
flowinval = flowfinal /16 ' shift input for table lookup take 10 bit flow number change to 0-64 number of memory locations
flowinval2 = tempval & %1111111111111110 ' clear last bit for WORD lookup
'get table high and low values
READ flowinval2+2,tablehigh.BYTE0
READ flowinval2+3,tablehigh.BYTE1
READ flowinval2,tablelow.BYTE0
READ flowinval2+1,tablelow.BYTE1
'Table Interpolation
flowinval = flowfinal & %0000000000001111 ' get interpolation value add 15 to adval
IF tablehigh >= tablelow THEN ' get space between table values
flowinval2 = tablehigh - tablelow '
ELSE '
flowinval2 = tablelow - tablehigh '
ENDIF '
flowinval = flowinval2 * tempval 'multiply high/low diff by interp value
outputval = flowinval /16 'divide by table spacing 8
IF tablehigh >= tablelow THEN ' offset table value by calculated
outputval = outputval + tablelow ' interpolation value
ELSE '
outputval = tablelow - outputval '
goto outputsub
endif
mafouthighloop: '
usbservice
flowinval3 = flowfinal /128 ' shift input for table lookup take 14 bit mafin number change to 131-261 number of eeprom locations
flowinval4 = flowinval & %1111111111111110 ' clear last bit for WORD lookup
'get table high and low values
READ flowinval4+61+2,tablehigh.BYTE0
READ flowinval4+61+3,tablehigh.BYTE1
READ flowinval4+61,tablelow.BYTE0
READ flowinval4+61+1,tablelow.BYTE1
'Table Interpolation
flowinval3 = flowfinal & %0000000001111111 ' get interpolation value add 127 to adval
IF tablehigh >= tablelow THEN ' get space between table values
flowinval4 = tablehigh - tablelow '
ELSE '
flowinval4 = tablelow - tablehigh '
ENDIF '
outputval = flowinval4 * flowinval3 'multiply high/low diff by interp value
outputval = tempval /128 'divide by table spacing
IF tablehigh >= tablelow THEN ' offset table value by calculated
outputval = outputval + tablelow ' interpolation value
ELSE '
outputval = tablelow - outputval '
endif
outputsub:
usbservice
mafout[0] = outputval.byte1
mafout[1] = outputval.byte0
hzout = 10
HPWM 1,127,hzout
' Wait for USB input
idleloop:
high portc.3
USBService ' Must service USB regularly
cnt = 16 ' Specify input buffer size
USBIn 3, buffer, cnt, startloop
' Message received
outloop:
here is the code I found for doing it with serial..
<TBODY>
<CODE class="vb comments">' Name : EE.pbp </CODE>
</TBODY>
<TBODY>
<CODE>02</CODE>
<CODE class="vb comments">' Compiler : PICBASIC PRO Compiler 2.6 </CODE>
</TBODY>
<TBODY>
<CODE>03</CODE>
<CODE class="vb comments">' Assembler : PM or MPASM </CODE>
</TBODY>
<TBODY>
<CODE>04</CODE>
<CODE class="vb comments">' Target PIC : 12F, 16F or 18F types </CODE>
</TBODY>
<TBODY>
<CODE>05</CODE>
<CODE class="vb comments">' Hardware : Non specific </CODE>
</TBODY>
<TBODY>
<CODE>06</CODE>
<CODE class="vb comments">' Oscillator : internal or external </CODE>
</TBODY>
<TBODY>
<CODE>07</CODE>
<CODE class="vb comments">' Keywords : READ, SEROUT, WRITE </CODE>
</TBODY>
<TBODY>
<CODE>08</CODE>
<CODE class="vb comments">' Description : PICBASIC PRO program to demonstate the EEPROM, READ and WRITE Commands. </CODE>
</TBODY>
<TBODY>
<CODE>09</CODE>
<CODE class="vb comments">' Works on targets with data EE only!!! Initialized address 0..3 and 8. Writes 10..63. </CODE>
</TBODY>
<TBODY>
<CODE>10</CODE>
<CODE class="vb comments">' </CODE>
</TBODY>
<TBODY>
<CODE>11</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>12</CODE>
<CODE class="vb keyword">Include</CODE> <CODE class="vb string">"modedefs.bas"</CODE> <CODE class="vb comments">' Include serial modes </CODE>
</TBODY>
<TBODY>
<CODE>13</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>14</CODE>
<CODE class="vb plain">SO </CODE><CODE class="vb keyword">Con</CODE> <CODE class="vb plain">0 </CODE><CODE class="vb comments">' Define serial output pin </CODE>
</TBODY>
<TBODY>
<CODE>15</CODE>
<CODE class="vb plain">B0 </CODE><CODE class="vb keyword">Var</CODE> <CODE class="vb keyword">byte</CODE>
</TBODY>
<TBODY>
<CODE>16</CODE>
<CODE class="vb plain">B1 </CODE><CODE class="vb keyword">Var</CODE> <CODE class="vb keyword">byte</CODE>
</TBODY>
<TBODY>
<CODE>17</CODE>
<CODE class="vb plain">B2 </CODE><CODE class="vb keyword">Var</CODE> <CODE class="vb keyword">byte</CODE>
</TBODY>
<TBODY>
<CODE>18</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>19</CODE>
<CODE class="vb keyword">EEPROM</CODE> <CODE class="vb plain">[</CODE><CODE class="vb string">"wxyz"</CODE><CODE class="vb plain">] </CODE><CODE class="vb comments">' EEPROM[0..3] = 119..122 </CODE>
</TBODY>
<TBODY>
<CODE>20</CODE>
<CODE class="vb keyword">EEPROM</CODE> <CODE class="vb plain">8,[100] </CODE><CODE class="vb comments">' EEPROM[8] = 100 </CODE>
</TBODY>
<TBODY>
<CODE>21</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>22</CODE>
<CODE class="vb plain">mainloop: </CODE>
</TBODY>
<TBODY>
<CODE>23</CODE>
<CODE class=spaces> </CODE><CODE class="vb plain">B0 = 63 </CODE><CODE class="vb comments">' Set Size of EEPROM </CODE>
</TBODY>
<TBODY>
<CODE>24</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>25</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">For</CODE> <CODE class="vb plain">B1 = 10 </CODE><CODE class="vb keyword">To</CODE> <CODE class="vb plain">B0 </CODE><CODE class="vb comments">' Check WRITE Command </CODE>
</TBODY>
<TBODY>
<CODE>26</CODE>
<CODE class=spaces> </CODE><CODE class="vb plain">B2 = B1 + 100 </CODE><CODE class="vb comments">' EEPROM[10..63] = 110..163 </CODE>
</TBODY>
<TBODY>
<CODE>27</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Write</CODE> <CODE class="vb plain">B1,B2 </CODE>
</TBODY>
<TBODY>
<CODE>28</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Next</CODE> <CODE class="vb plain">B1 </CODE>
</TBODY>
<TBODY>
<CODE>29</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>30</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">For</CODE> <CODE class="vb plain">B1 = 0 </CODE><CODE class="vb keyword">To</CODE> <CODE class="vb plain">B0 </CODE><CODE class="vb comments">' Check READ Command </CODE>
</TBODY>
<TBODY>
<CODE>31</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Read</CODE> <CODE class="vb plain">B1,B2 </CODE><CODE class="vb comments">' Dump EEPROM Contents </CODE>
</TBODY>
<TBODY>
<CODE>32</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Serout</CODE> <CODE class="vb plain">SO,N2400,[#B2,</CODE><CODE class="vb string">" "</CODE><CODE class="vb plain">] </CODE>
</TBODY>
<TBODY>
<CODE>33</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Next</CODE> <CODE class="vb plain">B1 </CODE>
</TBODY>
<TBODY>
<CODE>34</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>35</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Serout</CODE> <CODE class="vb plain">SO,N2400,[10,10] </CODE><CODE class="vb comments">' Skip 2 Lines </CODE>
</TBODY>
<TBODY>
<CODE>36</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">Goto</CODE> <CODE class="vb plain">mainloop </CODE><CODE class="vb comments">' Forever </CODE>
</TBODY>
<TBODY>
<CODE>37</CODE>
<CODE class=spaces> </CODE>
</TBODY>
<TBODY>
<CODE>38</CODE>
<CODE class=spaces> </CODE><CODE class="vb keyword">End</CODE>
</TBODY>
Here is my code so far. The program takes a 0-5V input, converts it to a flow with a program memory lookup table. will eventually do some math to the flow value, then takes the flow value and converts it back to AD counts in an eeprom lookup table for an external DAC.
I would like to send letters to the pic from a VB program telling it to either write eeprom, read eeprom, send flow value, send v out value, etc.
Include "cdc_desc.bas" ' Include the HID descriptors
Define OSC 48
define ADC_BITS 10
Define ADC_clock 6
Define ADC_sampleus 3
' initial EEPROM values (flow to dac counts out)
DATA WORD 0,WORD 16,WORD 32,WORD 48,WORD 64,WORD 80,WORD 96,WORD 112,WORD 128
DATA WORD 144,WORD 160,WORD 176,WORD 192,WORD 208,WORD 224,WORD 240,WORD 256
DATA WORD 272,WORD 288,WORD 304,WORD 320,WORD 336,WORD 352,WORD 368,WORD 384
DATA WORD 400,WORD 416,WORD 432,WORD 448,WORD 464,WORD 480,WORD 496
DATA WORD 512,WORD 528,WORD 544,WORD 560,WORD 576,WORD 592,WORD 608,WORD 624,WORD 640
DATA WORD 656,WORD 672,WORD 688,WORD 704,WORD 720,WORD 736,WORD 752,WORD 768
DATA WORD 784,WORD 800,WORD 816,WORD 832,WORD 848,WORD 864,WORD 880,WORD 896
DATA WORD 912,WORD 928,WORD 944,WORD 960,WORD 976,WORD 992,WORD 1008
DATA WORD 1024,WORD 1024
'eeprom 230, [254,0,210,0,190,0,100,0,60,0,40,0,30,0,0,0] 'temp out table word size ohm out values
'eeprom 244, [147,147,130,130,125,125,125,120,120,115,115,115,11 5,115,115,115] 'desired afr table
'eeprom 250, [122,0] 'displacement scalar
'eeprom 252, [ 50] 'min load for auto tune
eeprom 253, [ 100,0] 'tube size scalar (tube area used vs tube size used for orginal calculations)
buffer Var Byte[16]
cnt Var Byte[16]
mafin var word
mafout var byte[2]
maf0 var byte
maf1 var byte
outputval VAR WORD ' output value
tempval VAR WORD ' temporary
tablehigh VAR WORD ' high table value
tablelow VAR WORD ' low table value
tempval2 VAR WORD ' temporary #2
flow var word
inputtable con ext
mafscalar var word
hzout var word
flowinval var word
flowinval2 var word
flowinval3 var word
flowinval4 var word
flowfinal var word
' OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10
TRISC = %11000000
ADCON2 = %10000000
ANSELH = %00000010
USBInit ' Get USB going
startloop:
Adcin 9, mafin
READ 253, mafscalar
goto overdata
'0-5v hpx-e transfer function in 2.9 tube
asm
inputtable
DW 0, 0, 0, 0, 0, 7, 12, 16, 20, 24, 28, 33, 39, 45, 53, 62, 72, 83, 94, 107
DW 121, 136, 152, 169, 188, 208, 229, 252, 277, 304, 332, 363, 395, 430, 468
DW 507, 549, 594, 641, 691, 743, 798, 855, 915, 977, 1043, 1110, 1181, 1255
DW 1331, 1410, 1493, 1579, 1668, 1761, 1858, 1960, 2065, 2175, 2289, 2408, 2532
DW 2659, 2791, 2925, 2925
endasm
overdata:
usbservice
tempval = mafin >> 3 ' shift input for table lookup
tempval2 = tempval & %1111111111111110 ' clear last bit for WORD lookup
'get table high and low values
READcode (inputtable+tempval2+2),tablehigh.BYTE0
READcode (inputtable+tempval2+3),tablehigh.BYTE1
READcode (inputtable+tempval2),tablelow.BYTE0
READcode (inputtable+tempval2+1),tablelow.BYTE1
'Table Interpolation
tempval = mafin & %0000000000001111 ' get interpolation value
IF tablehigh >= tablelow THEN ' get space between table values
tempval2 = tablehigh - tablelow '
ELSE '
tempval2 = tablelow - tablehigh '
ENDIF '
tempval = tempval2 * tempval 'multiply high/low diff by interp value
flow = tempval >> 4 'divide by table spacing
IF tablehigh >= tablelow THEN ' offset table value by calculated
flow = flow + tablelow ' interpolation value
ELSE '
flow = tablelow - flow '
ENDIF '
flowsub:
usbservice
'mafscalar = mafscalar/100
' flow = flow*mafscalar 'multiply flow value by maf housing size scalar
flowfinal = flow
if flowfinal > 511 then goto mafouthighloop
mafoutlowloop:
flowinval = flowfinal /16 ' shift input for table lookup take 10 bit flow number change to 0-64 number of memory locations
flowinval2 = tempval & %1111111111111110 ' clear last bit for WORD lookup
'get table high and low values
READ flowinval2+2,tablehigh.BYTE0
READ flowinval2+3,tablehigh.BYTE1
READ flowinval2,tablelow.BYTE0
READ flowinval2+1,tablelow.BYTE1
'Table Interpolation
flowinval = flowfinal & %0000000000001111 ' get interpolation value add 15 to adval
IF tablehigh >= tablelow THEN ' get space between table values
flowinval2 = tablehigh - tablelow '
ELSE '
flowinval2 = tablelow - tablehigh '
ENDIF '
flowinval = flowinval2 * tempval 'multiply high/low diff by interp value
outputval = flowinval /16 'divide by table spacing 8
IF tablehigh >= tablelow THEN ' offset table value by calculated
outputval = outputval + tablelow ' interpolation value
ELSE '
outputval = tablelow - outputval '
goto outputsub
endif
mafouthighloop: '
usbservice
flowinval3 = flowfinal /128 ' shift input for table lookup take 14 bit mafin number change to 131-261 number of eeprom locations
flowinval4 = flowinval & %1111111111111110 ' clear last bit for WORD lookup
'get table high and low values
READ flowinval4+61+2,tablehigh.BYTE0
READ flowinval4+61+3,tablehigh.BYTE1
READ flowinval4+61,tablelow.BYTE0
READ flowinval4+61+1,tablelow.BYTE1
'Table Interpolation
flowinval3 = flowfinal & %0000000001111111 ' get interpolation value add 127 to adval
IF tablehigh >= tablelow THEN ' get space between table values
flowinval4 = tablehigh - tablelow '
ELSE '
flowinval4 = tablelow - tablehigh '
ENDIF '
outputval = flowinval4 * flowinval3 'multiply high/low diff by interp value
outputval = tempval /128 'divide by table spacing
IF tablehigh >= tablelow THEN ' offset table value by calculated
outputval = outputval + tablelow ' interpolation value
ELSE '
outputval = tablelow - outputval '
endif
outputsub:
usbservice
mafout[0] = outputval.byte1
mafout[1] = outputval.byte0
hzout = 10
HPWM 1,127,hzout
' Wait for USB input
idleloop:
high portc.3
USBService ' Must service USB regularly
cnt = 16 ' Specify input buffer size
USBIn 3, buffer, cnt, startloop
' Message received
outloop: