Shop OBEX P1 Docs P2 Docs Learn Events
Trying to READ a data table — Parallax Forums

Trying to READ a data table

skynuggetskynugget Posts: 172
edited 2010-05-15 01:28 in General Discussion
hey all, im trying to populate a 4 bytes of a 12 byte array from a data table as follows. my current method doenst seem to be indexing proper. it seems straight forward, am i doing this write?

thanks in advance.

' -------------------------------------------------------------------------
' Use: DTMF_OUT number (10 = *, 11 = #)
'
SUB DTMF_OUT
    tmpB1 = __PARAM1
    
    tmpb1 = tmpb1 * 4                        '0 = 0 ,1 = 4, 2 = 8 etc...
    
    FOR idx = 1 to 4
        READ DTMF_Table + tmpB1, ToneGen(idx) ' populatte byets 1 thru 4
        INC tmpb1    
    NEXT        


  
  DTMFen = yes                                    ' go tone    
  DELAY_MS ToneDelay               ' hold for tones timing
  DTMF_OFF                         ' stop the tones

ENDSUB




DTMF_Table:
                '  LO        ''   HI        '
    DATA    $1E, $92, $2B, $67 '0
    DATA    $16, $A4, $27, $46 '1
    DATA    $16, $A4, $2B, $67 '2
    DATA    $16, $A4, $2F, $FB '3
    DATA    $19, $03, $27, $46 '4
    DATA    $19, $03, $2B, $67 '5
    DATA    $19, $03, $2F, $FB '6
    DATA     $1B, $AD, $27, $46 '7
    DATA     $1B, $AD, $2B, $67 '8
    DATA     $1B, $AD, $2F, $FB '9
    DATA    $1E, $92, $27, $46 '*
    DATA    $1E, $92, $2F, $FB '#


Post Edited (skynugget) : 5/13/2010 3:50:48 PM GMT

Comments

  • ZootZoot Posts: 2,227
    edited 2010-05-14 06:02
    Seems like it should work. Are you really populating ToneGen(1) through ToneGen(4) but meaning to populate ToneGen(0) - ToneGen(3)?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • skynuggetskynugget Posts: 172
    edited 2010-05-14 11:51
    thanks zoot,
    im trying to skip byte zero and populate bytes 1 - 4.

    sort of like this statement.

    put tonegen(1), $1E, $92, $2B, $67

    it seems like my offset value is getting locked up in the for next loop somehow? example: for number 3

    SUB DTMF_OUT
        offset var __PARAM1
      watch offset, 8 ,udec 
        'break here offset = 3 good!
        
        DTMFen = yes
      offset = offset * 4                        '0 = 0 ,1 = 4, 2 = 8 etc...
     'break here offset = 12 good!
     
      FOR idx = 1 to 4
          READ DTMF_Table + offset, ToneGen(idx) ' populate byets 1 thru 4
        INC offset
        NEXT        
        'break here and offset goes to 19 and doesnt change nextime through -NOTGOOD
        DELAY_MS ToneDelay           ' hold for tones timing
      DTMF_OFF
        DELAY_MS pausedelay          ' stop the tones
    
    ENDSUB
    
    

    Post Edited (skynugget) : 5/14/2010 12:13:05 PM GMT
  • YendorYendor Posts: 288
    edited 2010-05-14 18:53
    I believe what you're doing will work, if you didn't do the '*4'.

    To read 4 bytes at once,·you can do this, but without the loop.
    READ·DTMF_Table·+·offset,·ToneGen(1), ToneGen(2),ToneGen(3),ToneGen(4)

    Or do a byte at a time

    ··offset·=·offset·*·1························'0·=·0·,1·=·4,·2·=·8·etc...
    ··FOR·idx·=·1·to·4
    ······READ·DTMF_Table·+·offset,·ToneGen(idx)
    ····INC·offset
    ····NEXT

    ·
  • ZootZoot Posts: 2,227
    edited 2010-05-14 19:36
    He needs the offset * 4 because he has 4 byte blocks and needs to set up the address.

    skynugget -- what values are you passing to offset? > 15 ?

    You could try this:

    
    addr VAR Word 
    
    SUB DTMF_OUT
        addr = __PARAM1
        addr = addr << 2 ' * 4    
        addr = addr + DTMF_Table
        DTMFen = yes
        READ addr, ToneGen(1), ToneGen(2), ToneGen(3), ToneGen(4) ' populate byets 1 thru 4
        'break here and offset goes to 19 and doesnt change nextime through -NOTGOOD
        DELAY_MS ToneDelay           ' hold for tones timing
        DTMF_OFF
        DELAY_MS pausedelay          ' stop the tones
    
    ENDSUB
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • YendorYendor Posts: 288
    edited 2010-05-14 20:59
    Agreed Zoot, the *4 would have to be necessary, then.

    Another thought, he can do is:

    offset = offset * 4 '0 = 0 ,1 = 4, 2 = 8 etc...

    FOR idx = 1 to 4
    READ DTMF_Table + offset, ToneGen1(idx), ToneGen2(idx),ToneGen3(idx),ToneGen4(idx)
    INC offset
    next

    skynugget, when you say array, do you mean in Ram or Rom? It really does't make sense to do it that way, as the data is in ROM, and can just address it from there, instead of reading all into an array. Then there's the >15 issue that zoot brought up.

    Remember SXSim is your friend (with the updated revision!), and there's a nice memory map when you do a 'view list' at the bottom .

    Anyhoo, not sure if this helps or not, but always a pleasure to chat! [noparse]:o[/noparse])
  • skynuggetskynugget Posts: 172
    edited 2010-05-14 21:08
    hah, i didnt think about the >15 trap! and i dint know your could read more then one byte... cool!
    the tonegen array is a memory bank for a dtmf generator running in the isr.

    it turns out it has something to do with my variables, i cleared some out and now all the ideas get the job done... im not sure why that fixes it. im only using 17 bytes of ram total so far. im not sure what problem ill have as i add features.

    heres what im working with so far...
  • ZootZoot Posts: 2,227
    edited 2010-05-15 00:07
    Always helps to post the whole program. Your array is not set to be in a single bank, and some of the array you are populating is "global", and some is in bank $10. Define it like this:

    toneGen VAR Byte (14) BANK ' keep in single bank

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • skynuggetskynugget Posts: 172
    edited 2010-05-15 01:28
    yeah, once i knew what the problem was, i was abel to clean it up enough for public consumption. [noparse]:)[/noparse]

    thank bank definition hasn't fixed the problem. if i define anything before my offset (tmpb1) variable, its a non go. if i define that var within. so far though any variable i define after that work for everything ive tried so far... odd.
Sign In or Register to comment.