12-bit Variables
Leo Sorkin
Posts: 3
Hello to everyone. I am new to the Stamp and to this forum.
Working on a project using parallel 12-bit DACs.· There is some way to directly define 12-bit variables or have to either define them as Word (which will waste·4 bits) or as 1 Byte + 1 Nibble· or 3 Nibbles (which will require two or three·program·instructions respectively to·update).
Searched the forums but not able to find a similar question. Sorry if I am asking an already replied question.·
Thanks in advance for your comments/suggestions.
Regards,· Leo
Working on a project using parallel 12-bit DACs.· There is some way to directly define 12-bit variables or have to either define them as Word (which will waste·4 bits) or as 1 Byte + 1 Nibble· or 3 Nibbles (which will require two or three·program·instructions respectively to·update).
Searched the forums but not able to find a similar question. Sorry if I am asking an already replied question.·
Thanks in advance for your comments/suggestions.
Regards,· Leo
Comments
·· You will have to use a WORD variable or a BYTE and a NIB, although it will be hard to get the reading into that without it being in a WORD variable first anyway.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Regards, Leo
·· If you were short of variable space it would be possible to use the WORD variable for double duty.· To have the lower 12 bits used for your ADC and the upper 4 for something else.· Port status perhaps.· It's all in the masking of the reads/writes from/to the variable.· It depends on whether the extra code space (not much) would justify the variable savings.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
There are two approaches.
One, is to try to save RAM.
If you have a lot of 12-bit data that you need to store or later re-use, you may have to compact it into One and a half bytes to conserve RAM. You loose some speed to gain compactness.
Two, is to try to maintain high speed.
If you take the 12-bit data and immediately process it into useful 8-bit data or recode it into some other format [noparse][[/noparse]ASCII or BDC], just use a word [noparse][[/noparse]two bytes] to handle the inital 12=bit data as a temporary WORD buffer and ignore 4 bits.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan