Shop OBEX P1 Docs P2 Docs Learn Events
Odd program crash — Parallax Forums

Odd program crash

John KJohn K Posts: 9
edited 2006-04-20 04:47 in BASIC Stamp
Hello,

I am using an LTC1298 to read a rotary pot. I have found that my program crashes in the subroutine that reads the ADC. After some troubleshooting, I found that the program is crashing only when the returned value is 0. Why is this? As the adc value is between 0-4075, too big a number for my needs, I convert the number to byte size by dividing it by 16. You will see this in the last line of the code below. This·code line is what is in question. I have tried a number of things, but whenever the ADresult is 0, the program stops.

LOW CLK
HIGH DIO_n
LOW CS
PULSOUT CLK,5
LET DIO_p = sglDif
PULSOUT CLK,5
LET DIO_p = oddSign
PULSOUT CLK,5
LET DIO_p = msbf
PULSOUT CLK,5
INPUT DIO_n
LET AD = 0
FOR ADbits = 1 TO 13
· LET AD = AD*2+DIO_p
· PULSOUT CLK,5
· NEXT
HIGH CS
ADresult = AD/16

Thank you,
John

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-19 21:22
    John -

    Regardless of the results of: ADresult = AD/16, the program is going to STOP! You've reached the end of the program, and provided no facility for it to loop back, presuming you've listed the entire program in your message.

    You can save yourself some time and effort by leaving out "LET". It is not a required part of the assignment syntax, which absence is true of many Basic variants.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • John KJohn K Posts: 9
    edited 2006-04-20 04:35
    Hello Bruce,

    Oh, I should have mentioned that the code I listed was just cut from the complete program. The rest of the code works fine, it's just that line (ADresult = AD/16) that is in question. When ADresult is 0, the program stops right on this line, why? I have ruled the LTC1298 out, as I was thinking that maybe the analog inputs cannot be connected directly to ground or power, which is basically what happens at both extremes of the potentiometer. This was ruled out because if you don't divide AD by 16, then only the first byte of AD is stored in ADresult, as ADresult is a byte size variable, and AD is a word. Then the returned value will pass 0 a few times, which if you get the potentiometer set to that, the program halts.

    What about the fact that I'm converting a word to a byte, is that a problem?

    Alex
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-20 04:47
    John (or is it Alex?) you should DEBUG the final value.· If you have a value less than 16 being returned, what do you think you will get for a result?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.