serrial ADC shiftin/shiftout problems
Archiver
Posts: 46,084
Hello again!
I'm attempting to interface an LTC1298CN8 12-bit serial ADC converter to a
BS2. For a test, I simply have a 50k pot as a voltage divider from +5 to
ground, with the slider attached to the + input of the ADC. PIN0 is my CLK
pin, PIN1 is Dout, PIN2 is Din, and PIN15 is !CS on my stamp. I read the
data into variables called SampleLow and SampleHigh, then debug them to the
PC. The code is below. I always get a result of "0:0", so the variables do
not seem to be getting chnaged during the SHIFTIN function.
Any ideas?
Steve
'{$STAMP BS2}
'{$PBASIC 2.5}
SampleLow VAR byte
SampleHigh VAR Byte
DEBUG "Startup", Cr
high 15
PAUSE 1000
DEBUG "Entering Main", cr
Main:
LOW 15
SHIFTOUT OUT1, OUT0, LSBFIRST, [noparse][[/noparse]%00011\4]
SHIFTIN IN2, OUT0, LSBFIRST, [noparse][[/noparse]SampleLow\8, SampleHigh\4]
HIGH 15
DEBUG DEC SampleHigh, ":", DEC SampleLow, CR
PAUSE 5
GOTO Main
end
I'm attempting to interface an LTC1298CN8 12-bit serial ADC converter to a
BS2. For a test, I simply have a 50k pot as a voltage divider from +5 to
ground, with the slider attached to the + input of the ADC. PIN0 is my CLK
pin, PIN1 is Dout, PIN2 is Din, and PIN15 is !CS on my stamp. I read the
data into variables called SampleLow and SampleHigh, then debug them to the
PC. The code is below. I always get a result of "0:0", so the variables do
not seem to be getting chnaged during the SHIFTIN function.
Any ideas?
Steve
'{$STAMP BS2}
'{$PBASIC 2.5}
SampleLow VAR byte
SampleHigh VAR Byte
DEBUG "Startup", Cr
high 15
PAUSE 1000
DEBUG "Entering Main", cr
Main:
LOW 15
SHIFTOUT OUT1, OUT0, LSBFIRST, [noparse][[/noparse]%00011\4]
SHIFTIN IN2, OUT0, LSBFIRST, [noparse][[/noparse]SampleLow\8, SampleHigh\4]
HIGH 15
DEBUG DEC SampleHigh, ":", DEC SampleLow, CR
PAUSE 5
GOTO Main
end
Comments
You probably need this:
SHIFTOUT 1, 0, LSBFIRST, [noparse][[/noparse]%00011\4]
SHIFTIN 2, 0, LSBFIRST, [noparse][[/noparse]Sample\12]
Look at what you have:
> SHIFTOUT OUT1, OUT0, LSBFIRST, [noparse][[/noparse]%00011\4]
> SHIFTIN IN2, OUT0, LSBFIRST, [noparse][[/noparse]SampleLow\8, SampleHigh\4]
What happens? SHIFTIN reads the value (0 or 1) currently present on
p2 and uses that as the data pin, and it reads the state of the OUT0
register( 0 or 1) and uses that value as the clock pin. Not what you
want!
In PBASIC 2.5 there is a new variable type:
'{$PBASIC 2.5}
LT1298do pin 2
LT1298di pin 1
LT1298ck pin 0
The interpreter figures out from context whether it needs to be used
directly as a constant or indirectly as a variable.
LT1298ck=0 ' sets (out0=0)
input LT1298do ' makes p2 an input (input 2)
debug ? LT1298di ' shows the current status of p1 (debug ? in1)
SHIFTIN LT1298do, LT1298ck, LSBfirst, [noparse][[/noparse]sample\12} ' old way
SHIFTIN 2,0,...
In the first and third cases, the compiler substitutes the reference
to a variable into the tokenized code, but in the second and fourth
cases, it subs the constant values. It used to be that you would
have to define two things, for example, you might have to define both
a constant and a variable:
pin_as_constant con 2
pin_as_variable in2 ' reference as variable
if pin_as_variable=0 then skipaction ' reference as constant
pulsout 2, 1000
skipaction:
Now it can be one thing:
what_a_pin pin 2
if what_a_pin=0 then pulseout what_a_pin,1000
' the compiler sorts it out!
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
>Hello again!
>
>I'm attempting to interface an LTC1298CN8 12-bit serial ADC converter to a
>BS2. For a test, I simply have a 50k pot as a voltage divider from +5 to
>ground, with the slider attached to the + input of the ADC. PIN0 is my CLK
>pin, PIN1 is Dout, PIN2 is Din, and PIN15 is !CS on my stamp. I read the
>data into variables called SampleLow and SampleHigh, then debug them to the
>PC. The code is below. I always get a result of "0:0", so the variables do
>not seem to be getting chnaged during the SHIFTIN function.
>
>Any ideas?
>
>Steve
>
>
>'{$STAMP BS2}
>'{$PBASIC 2.5}
>
>SampleLow VAR byte
>SampleHigh VAR Byte
>
>DEBUG "Startup", Cr
>high 15
>PAUSE 1000
>DEBUG "Entering Main", cr
>Main:
> LOW 15
> SHIFTOUT OUT1, OUT0, LSBFIRST, [noparse][[/noparse]%00011\4]
> SHIFTIN IN2, OUT0, LSBFIRST, [noparse][[/noparse]SampleLow\8, SampleHigh\4]
> HIGH 15
> DEBUG DEC SampleHigh, ":", DEC SampleLow, CR
> PAUSE 5
>GOTO Main
>end
>
I made these simple changes, and it works flawlessly!
Thank you!
Steve
Original Message
From: "Tracy Allen" <tracy@e...>
To: <basicstamps@yahoogroups.com>
Sent: Saturday, June 21, 2003 8:59 PM
Subject: Re: [noparse][[/noparse]basicstamps] serrial ADC shiftin/shiftout problems
> Hi Steve,
>
> You probably need this:
>
> SHIFTOUT 1, 0, LSBFIRST, [noparse][[/noparse]%00011\4]
> SHIFTIN 2, 0, LSBFIRST, [noparse][[/noparse]Sample\12]
>
> Look at what you have:
>
> > SHIFTOUT OUT1, OUT0, LSBFIRST, [noparse][[/noparse]%00011\4]
> > SHIFTIN IN2, OUT0, LSBFIRST, [noparse][[/noparse]SampleLow\8, SampleHigh\4]
>
> What happens? SHIFTIN reads the value (0 or 1) currently present on
> p2 and uses that as the data pin, and it reads the state of the OUT0
> register( 0 or 1) and uses that value as the clock pin. Not what you
> want!
>
> In PBASIC 2.5 there is a new variable type:
>
>
> '{$PBASIC 2.5}
> LT1298do pin 2
> LT1298di pin 1
> LT1298ck pin 0
>
> The interpreter figures out from context whether it needs to be used
> directly as a constant or indirectly as a variable.
>
> LT1298ck=0 ' sets (out0=0)
> input LT1298do ' makes p2 an input (input 2)
> debug ? LT1298di ' shows the current status of p1 (debug ? in1)
> SHIFTIN LT1298do, LT1298ck, LSBfirst, [noparse][[/noparse]sample\12} ' old way
> SHIFTIN 2,0,...
>
> In the first and third cases, the compiler substitutes the reference
> to a variable into the tokenized code, but in the second and fourth
> cases, it subs the constant values. It used to be that you would
> have to define two things, for example, you might have to define both
> a constant and a variable:
>
> pin_as_constant con 2
> pin_as_variable in2 ' reference as variable
> if pin_as_variable=0 then skipaction ' reference as constant
> pulsout 2, 1000
> skipaction:
>
> Now it can be one thing:
>
> what_a_pin pin 2
> if what_a_pin=0 then pulseout what_a_pin,1000
> ' the compiler sorts it out!
>
> -- regards,
> Tracy Allen
> electronically monitored ecosystems
> mailto:tracy@e...
> http://www.emesystems.com
>
>
>
>
> >Hello again!
> >
> >I'm attempting to interface an LTC1298CN8 12-bit serial ADC converter to
a
> >BS2. For a test, I simply have a 50k pot as a voltage divider from +5 to
> >ground, with the slider attached to the + input of the ADC. PIN0 is my
CLK
> >pin, PIN1 is Dout, PIN2 is Din, and PIN15 is !CS on my stamp. I read the
> >data into variables called SampleLow and SampleHigh, then debug them to
the
> >PC. The code is below. I always get a result of "0:0", so the variables
do
> >not seem to be getting chnaged during the SHIFTIN function.
> >
> >Any ideas?
> >
> >Steve
> >
> >
> >'{$STAMP BS2}
> >'{$PBASIC 2.5}
> >
> >SampleLow VAR byte
> >SampleHigh VAR Byte
> >
> >DEBUG "Startup", Cr
> >high 15
> >PAUSE 1000
> >DEBUG "Entering Main", cr
> >Main:
> > LOW 15
> > SHIFTOUT OUT1, OUT0, LSBFIRST, [noparse][[/noparse]%00011\4]
> > SHIFTIN IN2, OUT0, LSBFIRST, [noparse][[/noparse]SampleLow\8, SampleHigh\4]
> > HIGH 15
> > DEBUG DEC SampleHigh, ":", DEC SampleLow, CR
> > PAUSE 5
> >GOTO Main
> >end
> >
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>