Shop OBEX P1 Docs P2 Docs Learn Events
saving more than 255 to the eeprom — Parallax Forums

saving more than 255 to the eeprom

Brian SmithBrian Smith Posts: 44
edited 2005-06-16 10:26 in BASIC Stamp
i have been using my bs2 to log data to my laptop. I have a lot of space left in my eeprom. how can i save data in more than 255 eeprom spots? because I cant count any higher than 255.

edit: Well I can count higher than that but my BS2 cant···· turn.gif

Comments

  • dandreaedandreae Posts: 1,375
    edited 2005-06-08 19:42
    You can use a word size variable for larger values up to 65535.· If you need more EEPROM in the future you can use a XICOR 8K EEPROM. ·Here is a link for more information:· http://www.parallax.com/detail.asp?product_id=602-00008

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com



    Post Edited (Dave Andreae (Parallax)) : 6/8/2005 7:56:15 PM GMT
  • edited 2005-06-13 21:28
    I have been encountered same kind of problem with 8 bit long EEPROM memory size. Probably there is more to it about word size of address and then somehow limited in 8 bit length. Can someone comment on this further?
  • dandreaedandreae Posts: 1,375
    edited 2005-06-13 22:09
    Can you post your code?··This will help us determine the issue.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    [noparse][[/noparse]url]Http://www.parallax.com[noparse][[/noparse]/url]

    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-13 23:33
    Your EEPROM pointer (address) variable needs to be of type Word, then you can write to more than 256 (0 - 255) addresses.

    eePntr··· VAR··· Word

    Main:
    · FOR eePntr = 0 TO 1000
    ··· WRITE eePntr, eePntr.LOWBYTE
    ··NEXT
    Brian Smith said...
    i have been using my bs2 to log data to my laptop. I have a lot of space left in my eeprom. how can i save data in more than 255 eeprom spots? because I cant count any higher than 255.

    edit: Well I can count higher than that but my BS2 cant···· turn.gif
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Brian SmithBrian Smith Posts: 44
    edited 2005-06-14 16:50
    That worked, thanks. is there any simple way of expanding my BS2's eeprom size. Right now I can store about 1,800 pieces of info. I would like to store say 30,000.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-14 16:57
    If you're using a stock BS2 then the easiest route is to add an I2C EEPROM -- the 24LC256 will give you 32K of space.· I've attached a demo program. Note that this takes a little more work than just using WRITE and READ, but it let's you add a lot of storage (and I've already written hard code for you).· Since the 24LC256 has three address lines, you could add up to eight of these on the same two I/O pins (SDA and SCL) and get 256K of storage for you project.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • edited 2005-06-14 17:10
    Here is my program listing. This program is about 12 bit ADC to measure 8 bit DAC using PWM.

    There are two variables of word type, lee and song, as EEPROM addresses to store data in them.

    Problem is that somehow 12 bit ADC reading is going to be truncated by 8 bit when stored in

    EEPROM memory even though they looked good in DEBUG window.

    In my case, there was 8 bit limited space for each address, lee and song, in the EEPROM. Thanks much.


    DAC to ADC

    ' {$STAMP BS2}
    CS CON 0······················ ' Chip select; 0 = active
    CLK CON 1····················· ' Clock to ADC; out on rising edge.
    DIO_n CON 2··················· ' Data I/O pin _number_.
    config VAR Nib················ ' Configuration bits for ADC.
    AD VAR Word··················· ' Variable to hold 12-bit AD result.
    ''''''''''''''''''''''''''''''''''''''''''
    lee VAR Word
    song VAR Word
    ''''''''''''''''''''''''''''''''''''''''''
    startB VAR config.BIT0········ ' Start bit for comm with ADC.
    sglDif VAR config.BIT1········ ' Single-ended or differential mode.
    oddSign VAR config.BIT2······· ' Channel selection.
    msbf VAR config.BIT3·········· ' Output 0s after data xfer complete.
    HIGH CS······················· ' Deactivate ADC to begin.
    HIGH DIO_n···················· ' Set data pin for first start bit.
    song=0························ 'Initialize adrress.
    again:························ ' Main loop.
    FOR lee = 0 TO 29············· ' Increase Voltage by step 1, 20mV.
    song = song + 1··············· ' Increase Adrress by step 1.
    GOSUB DAC····················· ' Voltage out.
    GOSUB convert················· ' Get data from ADC.

    DEBUG DEC AD,CR··············· ' Display data.
    PAUSE 500····················· ' Wait a half second.
    NEXT·························· ' For loop.
    PAUSE 10000··················· ' Wait time interval, 10s.
    GOTO again ' Endless loop.
    'END·························· 'If only 1 loop needed.

    DAC:·························· ' Voltage out.
    PWM 8, lee, 20················ '1k, 10uF, RC dutycycle = 4RC = 40ms.
    RETURN
    convert:······················ ' ADC, 12 bits, LSB = 1.22 mV.
    config = config | %1011······· ' Set all bits except oddSign.
    LOW CS································ ' Activate the ADC.
    SHIFTOUT DIO_n,CLK,LSBFIRST,[noparse][[/noparse]config\4] ' Send config bits.
    SHIFTIN DIO_n,CLK,MSBPOST,[noparse][[/noparse]AD\12]····· ' Get data bits.
    WRITE song, AD························ ' Write to EEPROM.
    HIGH CS······························· ' Deactivate the ADC.
    RETURN································ ' Return to program.

    .·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-06-14 22:21
    That's clearly an older program and can be updated. In PBASIC 2.5, you can WRITE and READ Word variables from the EEPROM with this syntax:

    WRITE SomeAddress, Word bigValue

    Since a Word takes two bytes, you would simply add two to your address pointer between WRITEs and READs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • edited 2005-06-15 21:30
    Sorry, I don't quite get it. I tried very simple program and still confused even considering that program version issue. Could you take a look at the following listing? Thanks.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' This program writes a few bytes to EEPROM
    ' and then reads them back out and displays
    ' them on the screen.

    '{$STAMP BS2} 'STAMP directive (specifies a BS2)

    ValAddr VAR Word
    Value VAR Word
    ad VAR Word


    FOR ad=0 TO 3
    WRITE ad, 256 'Write some data to location 0 through 3
    NEXT


    FOR ValAddr = 0 TO 3 'Read all four locations and display the
    READ ValAddr, Value 'value on the screen
    DEBUG ? Value
    NEXT
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    DEBUG gives flat 0 values because of 8 bit trucation problem.
  • OrionOrion Posts: 236
    edited 2005-06-15 22:42
    try

    DEBUG DEC ? Value

    instead of

    DEBUG ? Value
  • GadgetmanGadgetman Posts: 2,436
    edited 2005-06-16 10:26
    Also, while you're writing 256 (10h) to EEPROM, you're only incrementing the counter by one, so you're overwriting half the stored data from the previous write.

    BTW: When testing things like this, it might be a good idea to pick a different value. CC33h is a nice one. (11001100 00110011 in binary)
    Anything containing '00' will only leave you wondering whether or not it actually wrote something.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
Sign In or Register to comment.