Shop OBEX P1 Docs P2 Docs Learn Events
Dallas DS2404 EconoRam Time Chip — Parallax Forums

Dallas DS2404 EconoRam Time Chip

ArchiverArchiver Posts: 46,084
edited 2001-12-19 00:41 in General Discussion
Jason-

IMHO, the '2404 is a reasonable choice with the BS2p. It provides
you a lot of capability for only one pin. If you can fit your data
storage requirements into its 512 bytes of nonvolatile ram it makes
a lot of sense. It's not the most convenient clock to use, but it
does the job and offers some nifty features.

One possible way to save space would be to store only the time
interval since the previous sample versus the complete time stamp
for each sample. You pick whether to use the 1/256 second units or
the more significant register values depending on your resolution
requirements. If you store 12 bits of ADC data and 12 bits of time
interval data for each sample, that gives you ~170 samples.

Here are some working DS2404 routines that may save you some
aspirin and hair-pulling.

Regards,

Steve

'{$STAMP BS2p}
'**************************************************************************
'
' DS2404 4 KBit RAM + Time Chip
' - for simplicity, SKIP ROM used throughout
'
'**************************************************************************

' Universal 1-Wire ROM commands (see Dallas Semiconductor documentation)
READ_ROM CON $33
SKIP_ROM CON $CC
MATCH_ROM CON $55
SEARCH_ROM CON $F0
SEARCH_FUNC CON $EC

' I/O pin constants
BUS CON 15 ' 1-Wire bus pin

' OWIN, OWOUT constants
RESET_NONE CON 0
RESET_PRE CON 1
RESET_POST CON 2
RESET_BOTH CON 3

' conventional variables
memory_address VAR WORD
CRC8 VAR BYTE
in_byte VAR BYTE(10)
i VAR BYTE
j VAR BYTE
this VAR BYTE


'**************************************************************************
' read ROM-based identifier...this will work with any 1-Wire device...
' also serves as means to determine identifier if unknown...must be
' only device on the bus or READ ROM will not work right...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> READ ROM
' <--- 8 Serial # identifier bytes
'**************************************************************************
OWOUT BUS,RESET_PRE,[noparse][[/noparse]READ_ROM] ' send READ ROM
OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\8] ' read 8-byte serial identifier
DEBUG CR,"Serial # "
FOR i = 7 TO 0 ' display identifier high order
DEBUG HEX2 in_byte(i) ' byte first
NEXT
FOR i = 0 TO 7 ' compare xmit'ed with calc CRC
this = in_byte(i): GOSUB addToCRC8
NEXT
IF crc8 > 0 THEN badCRC
DEBUG CR,"CRC for serial # valid"

'**************************************************************************
' turn oscillator on by writing $10 to the control register at $0201...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> WRITE SCRATCHPAD command
' ---> 2-byte starting address
' ---> 1 data byte = $10

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ SCRATCHPAD command
' <--- 2-byte address
' <--- ending offset/status

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> COPY SCRATCHPAD command
' ---> 2-byte starting address
' ---> ending offset/status
'**************************************************************************
memory_address = $0201
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$0F,memory_address.LOWBYTE,memory_address.HIGHBYTE,$10]
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$AA]
OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\3]
DEBUG CR,"DS2404 E/S register: ",HEX2 in_byte(2)
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$55,in_byte,in_byte(1),in_byte(2)]


'**************************************************************************
' read control register at $0201 to confirm realtime counter set to
' increment...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ MEMORY command
' ---> 2-byte starting address
' <--- 1 data byte
'**************************************************************************
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$F0,memory_address.LOWBYTE,memory_address.HIGHBYTE]
OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
DEBUG CR,CR,"DS2404 Control register: ",HEX2 in_byte



'**************************************************************************
' disable interrupts by clearing int enable bits in status register
' at $0201...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> WRITE SCRATCHPAD command
' ---> 2-byte starting address
' ---> 1 data byte = $38

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ SCRATCHPAD command
' <--- 2-byte address
' <--- ending offset/status

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> COPY SCRATCHPAD command
' ---> 2-byte starting address
' ---> ending offset/status
'**************************************************************************
memory_address = $0200
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$0F,memory_address.LOWBYTE,memory_address.HIGHBYTE,$38]
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$AA]
OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\3]
DEBUG CR,"DS2404 E/S register: ",HEX2 in_byte(2)
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$55,in_byte,in_byte(1),in_byte(2)]



'**************************************************************************
' read status register at $0200 to confirm interrupts disabled...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ MEMORY command
' ---> 2-byte starting address
' <--- 1 data byte
'**************************************************************************
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$F0,memory_address.LOWBYTE,memory_address.HIGHBYTE]
OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
DEBUG CR,CR,"DS2404 Status register: ",HEX2 in_byte


'**************************************************************************
' set alarm for 15 seconds from now by reading current realtime counter,
' setting this value + 15 seconds as alarm value...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ MEMORY command
' ---> 2-byte starting address (real time counter registers)
' <--- 4 data bytes

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> WRITE SCRATCHPAD command
' ---> 2-byte starting address
' ---> 4 data bytes (real time counter alarm registers)

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ SCRATCHPAD command
' <--- 2-byte address
' <--- ending offset/status

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> COPY SCRATCHPAD command
' ---> 2-byte starting address
' ---> ending offset/status
'**************************************************************************
memory_address = $0202 ' realtime counter register group
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$F0,memory_address.LOWBYTE,memory_address.HIGHBYTE]
OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\5]
in_byte(1) = in_byte(1) + 15 ' add 15 seconds
memory_address = $0210 ' realtime counter alarm register group
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$0F,memory_address.LOWBYTE,memory_address.HIGHBYTE,STR
in_byte\5]
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$AA]
OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\3]
DEBUG CR,"DS2404 E/S register: ",HEX2 in_byte(2)
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$55,in_byte,in_byte(1),in_byte(2)]



'**************************************************************************
' read status register at $0200 looking for realtime counter alarm
' condition...
'
' 1-Wire transactions summary:
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ MEMORY command
' ---> 2-byte starting address
' <--- 1 data byte
'**************************************************************************
memory_address = $0200
readStatus:
PAUSE 2000
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$F0,memory_address.LOWBYTE,memory_address.HIGHBYTE]
OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
DEBUG CR,CR,"DS2404 Status register: ",HEX2 in_byte
IF in_byte & $01 = 0 THEN readStatus


x:
'**************************************************************************
' fill all 512 bytes of general purpose memory with stuff...
'
' 1-Wire transactions summary (x's 16):
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> WRITE SCRATCHPAD command
' ---> 2-byte starting address
' ---> 32 data bytes

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ SCRATCHPAD command
' <--- 2-byte address
' <--- ending offset/status

' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> COPY SCRATCHPAD command
' ---> 2-byte starting address
' ---> ending offset/status
'**************************************************************************
memory_address = $0000
FOR i = 0 TO 15
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$0F,memory_address.LOWBYTE,memory_address.HIGHBYTE]
FOR j = 0 TO 31
OWOUT BUS,RESET_NONE,[noparse][[/noparse]i * j] ' write data to scratchpad
NEXT
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$AA] ' read scratchpad parameters
OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\3]
DEBUG CR,"DS2404 E/S register: ",HEX2 in_byte(2)
OWOUT BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$55,in_byte,in_byte(1),in_byte(2)]
memory_address = memory_address + 32
NEXT


'**************************************************************************
' read all 512 bytes of general purpose memory
'
' 1-Wire transactions summary (x's 16):
' ---> [noparse][[/noparse]reset]
' ---> SKIP ROM
' ---> READ MEMORY command
' ---> 2-byte starting address
' <--- 32 data bytes
'**************************************************************************
memory_address = $0000
FOR i = 0 TO 15
DEBUG CR,HEX4 memory_address,": "
OWOUT
BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$F0,memory_address.LOWBYTE,memory_address.HIGHBYTE]
FOR j = 0 TO 31
OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
DEBUG HEX2 in_byte," "
NEXT
memory_address = memory_address + 32
NEXT


DEBUG CR,"Program complete"
STOP

'**************************************************************************
addToCRC8:
FOR j = 1 TO 8
IF this.LOWBIT ^ crc8 & 1 THEN feedBack1_8
feedBack0_8:
crc8 = crc8 >> 1 & ~$80: GOTO nextBit_8
feedBack1_8:
crc8 = crc8 ^ $18 >> 1 | $80
nextBit_8:
this = this >> 1: NEXT: RETURN

badCRC:
DEBUG CR,"CRC mismatch--data invalid"
DEBUG CR,"CRC result: ",HEX2 crc8
STOP


On 18 Dec 01 at 22:55, jbirnsch wrote:

> Hi all,
>
> I am new to all of this so bear with me. I want to use the time
> function if this IC as well as the Sram to store data that will be
> collected by an ACD(MAX186)...

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-12-18 22:55
    Hi all,

    I am new to all of this so bear with me. I want to use the time
    function if this IC as well as the Sram to store data that will be
    collected by an ACD(MAX186). What I want to do is take the 12 bits
    from the ADC store that to an address in sram and then store the 4
    byte count of seconds from the Real time clock in the next 2 address
    locations as a time stamp from when the data was collected. I need
    the time stamp and I need to do this remotely without the PC
    connected. Am I going at this the wrong way. Should I use a serial
    E^2 with a seperate RTC connected to the BSP40?

    Jason
  • ArchiverArchiver Posts: 46,084
    edited 2001-12-19 00:41
    In a message dated 12/18/01 4:56:35 PM Central Standard Time,
    jbirnsch@v... writes:


    > I am new to all of this so bear with me. I want to use the time
    > function if this IC as well as the Sram to store data that will be
    > collected by an ACD(MAX186). What I want to do is take the 12 bits
    > from the ADC store that to an address in sram and then store the 4
    > byte count of seconds from the Real time clock in the next 2 address
    > locations as a time stamp from when the data was collected. I need
    > the time stamp and I need to do this remotely without the PC
    > connected. Am I going at this the wrong way. Should I use a serial
    >

    Personally, I wouldn't go with the DS2404. There are dozens of I2C EEPROMs
    and the PCF8538 RTC is a breeze to use (no decoding seconds to determine time
    -- you get everything as registers).

    There's code on the Parallax web site. GOTO the BS2p "Plus Pack" page:

    http://www.parallaxinc.com/html_files/products/BS_Accessories/plus_pack.asp

    -- Jon Williams
    -- Parallax


    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.