saving more than 255 to the eeprom
Brian Smith
Posts: 44
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····
edit: Well I can count higher than that but my BS2 cant····
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
www.parallax.com
Post Edited (Dave Andreae (Parallax)) : 6/8/2005 7:56:15 PM GMT
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
[noparse][[/noparse]url]Http://www.parallax.com[noparse][[/noparse]/url]
·
eePntr··· VAR··· Word
Main:
· FOR eePntr = 0 TO 1000
··· WRITE eePntr, eePntr.LOWBYTE
··NEXT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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.
.·
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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 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.
DEBUG DEC ? Value
instead of
DEBUG ? Value
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...