Help with two lookup tables?


Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jun 2011
    Posts
    19

    Default Help with two lookup tables?

    I'm at a loss. I have figured out how to make a lookup table with eeprom, but i need to impliment a table with the program memory and can't quite figure out how to do this. Any help would be greatly appreciated.
    Code:
    Define osc 20  'use 20 Mhz clock
    Define adc_bits 10
    Define ADC_CLOCK 3
    Define ADC_SAMPLEUS 24
    EEPROM [216, 0, 217, 0, 219, 0, 223, 0, 229, 0, 237, 0, 246, 0, 0, 1, 12, 1, _
    22, 1, 30, 1, 42, 1, 55, 1, 69, 1, 86, 1, 104, 1, _
    124, 1, 143, 1, 163, 1, 184, 1, 202, 1, 219, 1, 237, 1, 254, 1, 15, 2, _
    32, 2, 49, 2, 66, 2, 82, 2, 98, 2, 114, 2, 130, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5_
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5_
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ,5 ,5 ,5 ,5 ,5 ,5 ,5 ,5 ,5]
    EEPROM 128, [146, 2, 161, 2, 177, 2, 192, 2, 207, 2, 222, 2, 237, 2, 252, 2, 11, 3, _
    26, 3, 40, 3, 55, 3, 70, 3, 84, 3, 99, 3, 113, 3, _
    128, 3, 142, 3, 156, 3, 170, 3, 183, 3, 197, 3, 210, 3, 223, 3, 236, 3, _
    249, 3, 255, 3, 255, 3, 255, 3, 255, 3, 255, 3, 255, 3, 0, 4]
    adval var Word  'analog input value
    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
    avgarray var Word[32]  'array for averaging input samples
    countnum var Byte  'integer for counting sample array
    arraysum var Word  'summing variable for average
    TRISA = 255  'portA => input
    ADCON1 = 000010  'Set PORTA to analog and PORTE to digital
    TRISB = 000000  'Port B set for output
    High PORTB.2  'Serial D-A chip select off
    countnum = 0
    clearloop:  'zero out array
    DOloop:  'start of main loop
    Adcin 0, adval
    arraysum = arraysum - avgarray[countnum]  'subtract value at countnum
    avgarray[countnum] = adval  'store new value in array
    arraysum = arraysum + adval  'add to sum value
    adval = arraysum > > 5  'divide by 32
    countnum = countnum + 1
    If countnum = 32 Then
    countnum = 0
    Endif
     'program memory 65 point lookup table goes here
      
     ' take adval ,use interpolation, convert adval into number that could be from 
      ' 0-8000 and call it flow.
      ' do some math to the flow variable..
       ' call it flowfinal
     
        'below my code should be correct to take flowfinal and convert it
        'back to a voltage thru the DAC with a lookup table in the eeprom.
     
     
    
    tempval = flowfinal > > 3  'shift input for table lookup
    tempval2 = tempval & 11111111111110  'clear last bit for WORD lookup
    Read tempval2 + 2, tablehigh.byte0
    Read tempval2 + 3, tablehigh.byte1
    Read tempval2, tablelow.byte0
    Read tempval2 + 1, tablelow.byte1
    tempval = adval & 00000000001111  '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
    outputval = tempval > > 4  'divide by table spacing
    If tablehigh >= tablelow Then  'offset table value by calculated
    outputval = outputval + tablelow  'interpolation value
    Else
    outputval = tablelow - outputval
    Endif
    tempval = outputval < < 2  'shift output left 2 bits(LTC1661 DtoA)
    tempval = tempval + 01000000000000  'add control code(load DAC A)
    Low PORTB.2  'Enable DtoA chip
    shiftout PORTB.0, PORTB.1, 1, [tempval\16]  'Serial output to DtoA conv
    High PORTB.2  'Deselect DtoA chip
    Goto loop  'repeat main loop "forever"
    End
    Last edited by ScaleRobotics; - 10th February 2012 at 00:14. Reason: code tags fixed?

Members who have read this thread : 2

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