Odd program crash
John K
Posts: 9
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
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
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 -->
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 Savage
Parallax Tech Support
csavage@parallax.com