Shop OBEX P1 Docs P2 Docs Learn Events
a subrutine question — Parallax Forums

a subrutine question

Mike WMike W Posts: 105
edited 2008-06-07 01:06 in General Discussion
I have a questions about this routine.·
It is SX/B and it is suppose to get the temperature from a DS1620. The 1620 is configures for CPU, ONE SHOT
·
My question is, does my DO/LOOP - Loop until tmpB1.7 = 1.··Or have I made an error in that section?
·
The reason I ask is because I have observed that when the temperature gets to zero.
In two’s compliment the ninth bit (signC) goes positive to indicate negative numbers and all the bits in degC turn to 1’s.
Except all 8 bits of degC turn to 1’s before signC turns to 1 and gives a false reading of 255, that is why I suspect that the program is exiting the Loop before the conversion is complete.
·
Am I correct or have I done something else wrong? If not ·is there something I can do to avoid this
·
'

GET_TEMP:········· ······························· ······························· ··············· ················ '
·· DS_Reset = 1······································ ······························· ··············· ··············· '
··· SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, StartConvert········· ··············· ' start conversion
·· DS_Reset = 0······································ ······························· ··············· ··············· '
· WAIT_MS 10···· ······························· ······························· ··············· ················ ·' pause before next shiftout
·
·DO····· ························································· ······························· ··············· ··············· '
·· DS_Reset = 1······································ ······························· ··············· ··············· ' command read configuration register
··· SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, ReadConfig··········· ··············· ' watch bit 7 Wait for conversion to
··· SHIFTIN DS_I_O, DS_Clock, LSBPRE, tmpB1············ ··············· ··············· ‘ complete
·· DS_Reset = 0······································ ······························· ··············· ··············· ' 0 = still converting
·LOOP UNTIL tmpB1.7 = 1·········· ······························· ··············· ······················ ' 1 = conversion complete
·
·· DS_Reset = 1········································ ······························· ··············· ··············· '
··· SHIFTOUT DS_I_O, DS_Clock, LSBFIRST, ReadTemp········· ··············· ' command read converted temperature
··· SHIFTIN DS_I_O, DS_Clock, LSBPRE, degC······· ··············· ··············· ' get celsius temp 8 bits
··· SHIFTIN DS_I_O, DS_Clock, LSBPRE, signC\1······· ··············· ··············· ' get celsius sign 1 bit
·· DS_Reset = 0···· ······························· ······························· ··············· ··············· '
·
··· IF signC = 1 THEN···················· ······························· ··············· ··············· ' when degrees celsius goes negative you
···· degC = ~degC· ······························· ······························· ··············· ··············· ' need to convert degC from 2's compliment
····· degC = degC + 1·························· ······························· ··············· ··············· ' invert degC and add 1
··· ENDIF··············· ······························· ······························· ··············· ··············· '
·
···· degC = degC >> 1······················· ······························· ··············· ··············· ' remove half bit
······ tmpW1 = degC */ $01CC····· ······························· ··············· ···················· ·' temp x 1.8 (9/5)
······· degF = tmpW1_LSB········ ······························· ······························· ··············· '
·
·RETURN
'

·
·
Thanks
·
Mike

Comments

  • BeanBean Posts: 8,129
    edited 2008-06-06 12:25
    Mike,
    I think the problem might be that the DS_Reset only stays at zero for very short time within the loop.
    Try adding a 1 millisecond delay just before the "LOOP UNTIL" command.
    Also you can just do "degC = -degC" instead of inverting and adding 1.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • Mike WMike W Posts: 105
    edited 2008-06-07 01:06
    Bean

    I tried all thoes things.

    eliminating degC = degC· + 1 caused no problems

    when I added a WAIT_MS 1, the program guit responding, but when I replaced it with a PAUSE 1 the program still ran. odd!

    However a pause did not make a difference. I took it out.

    I added this·IF THEN·statment

    · ·· if degC = $FF then
    ······ degC = $00
    ···· endif

    just before I do my degF conversion, and it quit displaying 255 instead of zero·the rest of the program still seams to run OK

    ··· IF signC = 1 THEN···················· ······························· ··············· ··············· ' when degrees celsius goes negative you
    ···· degC = ~degC· ······························· ······························· ··············· ··············· ' need to convert degC from 2's compliment
    ····· degC = degC + 1·························· ······························· ··············· ··············· ' invert degC and add 1
    ··· ENDIF··············· ······························· ······························· ··············· ··············· '
    ·
    ···· if degC = $FF then
    ······ degC = $00
    ···· endif

    ··· degC = degC >> 1······················· ······························· ··············· ··············· ' remove half bit
    ······ tmpW1 = degC */ $01CC····· ······························· ··············· ···················· ·' temp x 1.8 (9/5)
    ······· degF = tmpW1_LSB········ ······························· ······························· ··············· '
    ·
    ·RETURN



    Mike
Sign In or Register to comment.