managing DS1603 32 bit elapsed time counter
ellizard
Posts: 106
HI everybody
I'm having trouble estracting informations from a DS1603 elapsed time counter of the Maxim/Dallas.
the point is: after a shiftout for telling it what i want, (read or write or clear a register), i must read or write a sequence 32 bit long.
i tried first with·4 shiftin/shiftout instructions with byte variables...........
and then with 2 shiftin/shiftout instructions with·word variables...........
it seems to me that even the smallest gap between the action of reading/writing that 32 bit let the data to be garbled.
I tried to work with an array of 4 byte, but does'nt work (it seems to me).
I tried to have a read of the array with the debug command but the modifier dec works only with 5 digits, so i tried to define aliases of the array, but i'm not able to·create an alias of the bytes 2 and 3
example:
CCC············ VAR Byte(4)
CCC_01······· VAR CCC.BYTE0
CCC_02······· VAR CCC.BYTE1
CCC_03······· VAR CCC.byte2 ·· when i do syntax check,·the editor give me the (expected variable modifier)
CCC_04······· VAR CCC.byte3· and the same for this line
i'm i particularly dumb or i'm trying to do in the wrong way???
thanks for the help
·
I'm having trouble estracting informations from a DS1603 elapsed time counter of the Maxim/Dallas.
the point is: after a shiftout for telling it what i want, (read or write or clear a register), i must read or write a sequence 32 bit long.
i tried first with·4 shiftin/shiftout instructions with byte variables...........
and then with 2 shiftin/shiftout instructions with·word variables...........
it seems to me that even the smallest gap between the action of reading/writing that 32 bit let the data to be garbled.
I tried to work with an array of 4 byte, but does'nt work (it seems to me).
I tried to have a read of the array with the debug command but the modifier dec works only with 5 digits, so i tried to define aliases of the array, but i'm not able to·create an alias of the bytes 2 and 3
example:
CCC············ VAR Byte(4)
CCC_01······· VAR CCC.BYTE0
CCC_02······· VAR CCC.BYTE1
CCC_03······· VAR CCC.byte2 ·· when i do syntax check,·the editor give me the (expected variable modifier)
CCC_04······· VAR CCC.byte3· and the same for this line
i'm i particularly dumb or i'm trying to do in the wrong way???
thanks for the help
·
Comments
·This is a common question for Tech support, unfortunately the answer is not what you might·expect (it wasn’t for me anyways). The way I have done this is:
CCC··var·Byte(4)
‘points to the memory address in the stamp directly
CCC_01·var·b0
CCC_02·var·b1
CCC_03·var·b2
CCC_04·var·b3
NOTE: For this to work you will need to state your array first before any other variables in your code if not you will be pointing to the wrong variable.
Also you can not use WORD size variables in the code this will throw off the pointers. This can be adjusted but it gets tricky.
CCC· VAR Byte(4)
Temp· VAR Word 'Takes up two bytes offset addresses by 2
'Points to the memory address in the stamp directly
CCC_01 VAR B2
CCC_02 VAR B3
CCC_03 VAR B4
CCC_04 VAR B5
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Stephen Swanson
Technical Support
Parallax, Inc.
sswanson@parallax.com
many many thanks to you all
Stefano
First the question of the alias. Say you define two words:
lowN VAR Word ' to hold least significant 16 bits from DS1603 counter
highN VAR Word ' to hold most significant 16 bits from DS1603
in that order. Now, you can define alias into those words:
lowN0 VAR lowN.byte0 ' this is an alias name for the low byte of the low word
The BASIC Stamp will now allow you to do things like the following:
FOR idx=0 TO 3
DEBUG DEC lowN0(idx)
NEXT
That is, without declaring an array explicityly, the Stamp knows that it is supposed to address 4 bytes in sequence that make up the two words. These implicit arrays are verrrrrrrrrry useful in Stamp programming! I rarely declare arrays explicitly, and I almost never use the absolute names (b0, b1.. etc).
Second, the question of the DS1603. You don't need any array or alias, I think.
HIGH rst
SHIFTOUT dpin,cpin,lsbfirst,[noparse][[/noparse]$80] ' command to read the continuous counter
SHIFTIN dpin,cpin,lsbpost,[noparse][[/noparse]lowN\16,highN\16] ' not sure if lsbpost or lsbpre, note \16
LOW rst
DEBUG DEC highN, 32, DEC lowN, CR
That should transfer the counter data smoothly into the two words. It is a 32 bit counter, so, if you want to display it as a decimal number out to 16+ million, you will need to use a double precision math routine to extract the decimal digits. There is a routine to do that on my math pages.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com