Understanding SERin/SERout commands, need help bad!
Archiver
Posts: 46,084
I was reading a articl on how to send serial communications between
stamp's , i have a appilicaton where i want to have one stamp running
its own loop based on a trigger, and the second stamp gather sensor
data and serial out the gather information into the other stamp to be
used.... hear is a program i writen, tell me if there is any flaw's
on it, currently i have not tried it on two stamp 2's because i only
have access to one right now.... i want to be able to send the serial
data as fast as poosible with the lowest latency...
program 1 **** this program runs the senor gathering and performs a
lookup to get the correct value for the serial inofmration that will
be outputed to the other stamp...
'{$STAMP BS2}
'{$PBASIC 2.5}
TB_POS VAR NIB
PULSE_WIDTH VAR WORD
X0 CON 1000
X1 CON 1100
X2 CON 1200
X3 CON 1300
X4 CON 1400
X5 CON 1500
X6 CON 1600
X7 CON 1700
MAIN:
HIGH 1 'used for ADC
LOW 1 'used for ADC
SHIFTIN 2,0,MSBPOST,[noparse][[/noparse]TB_POS\3] 'ADC value updated...
LOOKUP TB_POS ,[noparse][[/noparse]x0,x1,x2,x3,x4,x5,x6,x7],PULSE_WIDTH 'the
pulse_width variable is updated...
SEROUT 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] ' send updated pulse_width value
to second stamp..
GOTO MAIN: ' loop over and over...
program 2 ****
'{$STAMP BS2}
'{$PBASIC 2.5}
PULSE_WIDTH VAR WORD
INPUT 14
INPUT 13
INPUT 10
OUTPUT 12
OUTPUT 11
BOOTUP:
IF IN14 = 0 THEN STUCK
GOTO MAIN
STUCK:
IF IN14 = 0 THEN STUCK
GOTO MAIN
INJECT1:
PULSOUT 12, PULSE_WIDTH
IF IN14 = 0 THEN MAIN2
GOTO MAIN3
INJECT2:
PULSOUT 11, PULSE_WIDTH
IF IN13 = 0 THEN MAIN4
GOTO MAIN
MAIN: '*** main program area
SERIN 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] 'receave pulse_width value from
the first stamp 2
IF IN14 = 0 THEN INJECT1 ' in condition is true, perform rest of
the program, if false, loop over agian to receave the pulse_width
from first stamp...
GOTO MAIN ' loop over agian and agian....
MAIN2:
IF IN14 = 0 THEN MAIN2
GOTO MAIN3
MAIN3:
IF IN13 = 0 THEN INJECT2
GOTO MAIN3
MAIN4:
IF IN13 = 0 THEN MAIN4
GOTO MAIN
***** end of program... as you see in theory it looks nice and
fruity, but my application is time critical, with the inputs on the
second stamp being triggered around 80~120 cycles a second , i cant
have the serin command take long and not beable to reconize the
input's are being triggered while its reading the serial data....
Sean...
stamp's , i have a appilicaton where i want to have one stamp running
its own loop based on a trigger, and the second stamp gather sensor
data and serial out the gather information into the other stamp to be
used.... hear is a program i writen, tell me if there is any flaw's
on it, currently i have not tried it on two stamp 2's because i only
have access to one right now.... i want to be able to send the serial
data as fast as poosible with the lowest latency...
program 1 **** this program runs the senor gathering and performs a
lookup to get the correct value for the serial inofmration that will
be outputed to the other stamp...
'{$STAMP BS2}
'{$PBASIC 2.5}
TB_POS VAR NIB
PULSE_WIDTH VAR WORD
X0 CON 1000
X1 CON 1100
X2 CON 1200
X3 CON 1300
X4 CON 1400
X5 CON 1500
X6 CON 1600
X7 CON 1700
MAIN:
HIGH 1 'used for ADC
LOW 1 'used for ADC
SHIFTIN 2,0,MSBPOST,[noparse][[/noparse]TB_POS\3] 'ADC value updated...
LOOKUP TB_POS ,[noparse][[/noparse]x0,x1,x2,x3,x4,x5,x6,x7],PULSE_WIDTH 'the
pulse_width variable is updated...
SEROUT 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] ' send updated pulse_width value
to second stamp..
GOTO MAIN: ' loop over and over...
program 2 ****
'{$STAMP BS2}
'{$PBASIC 2.5}
PULSE_WIDTH VAR WORD
INPUT 14
INPUT 13
INPUT 10
OUTPUT 12
OUTPUT 11
BOOTUP:
IF IN14 = 0 THEN STUCK
GOTO MAIN
STUCK:
IF IN14 = 0 THEN STUCK
GOTO MAIN
INJECT1:
PULSOUT 12, PULSE_WIDTH
IF IN14 = 0 THEN MAIN2
GOTO MAIN3
INJECT2:
PULSOUT 11, PULSE_WIDTH
IF IN13 = 0 THEN MAIN4
GOTO MAIN
MAIN: '*** main program area
SERIN 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] 'receave pulse_width value from
the first stamp 2
IF IN14 = 0 THEN INJECT1 ' in condition is true, perform rest of
the program, if false, loop over agian to receave the pulse_width
from first stamp...
GOTO MAIN ' loop over agian and agian....
MAIN2:
IF IN14 = 0 THEN MAIN2
GOTO MAIN3
MAIN3:
IF IN13 = 0 THEN INJECT2
GOTO MAIN3
MAIN4:
IF IN13 = 0 THEN MAIN4
GOTO MAIN
***** end of program... as you see in theory it looks nice and
fruity, but my application is time critical, with the inputs on the
second stamp being triggered around 80~120 cycles a second , i cant
have the serin command take long and not beable to reconize the
input's are being triggered while its reading the serial data....
Sean...
Comments
The syntax you posted for master/slave connection with handshake
between two stamps is correct.
> SEROUT 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] ' send updated pulse_width value
to
> SERIN 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] 'receave pulse_width value from
>the first stamp 2
You might think about a timeout on the SERIN side. That would let
the time-critical task continue even if the SEROUT measurement is not
ready for any reason whatsoever, such as being out of sync, or for
more malignant reasons such as a broken cable or broken sensor.
SERIN 1\0, 16468, 2, continue, [noparse][[/noparse]PULSE_WIDTH] 'receive pulse_width
value from the first stamp 2
With that, if the SEROUT side is not there waiting when the SERIN
side hits that command, the SERIN side will only wait around for 1
millisecond before it jumps to the label "continue". (Note there is
a off-by-one "bug" in the SERIN timeout parameter, so you have to put
a 2 there to get a one millisecond delay).
-- Tracy
http://www.emesystems.com
>I was reading a articl on how to send serial communications between
>stamp's , i have a appilicaton where i want to have one stamp running
>its own loop based on a trigger, and the second stamp gather sensor
>data and serial out the gather information into the other stamp to be
>used.... hear is a program i writen, tell me if there is any flaw's
>on it, currently i have not tried it on two stamp 2's because i only
>have access to one right now.... i want to be able to send the serial
>data as fast as poosible with the lowest latency...
>
>
>program 1 **** this program runs the senor gathering and performs a
>lookup to get the correct value for the serial inofmration that will
>be outputed to the other stamp...
>
>'{$STAMP BS2}
>'{$PBASIC 2.5}
>TB_POS VAR NIB
>PULSE_WIDTH VAR WORD
>X0 CON 1000
>X1 CON 1100
>X2 CON 1200
>X3 CON 1300
>X4 CON 1400
>X5 CON 1500
>X6 CON 1600
>X7 CON 1700
>
>
>MAIN:
> HIGH 1 'used for ADC
> LOW 1 'used for ADC
> SHIFTIN 2,0,MSBPOST,[noparse][[/noparse]TB_POS\3] 'ADC value updated...
> LOOKUP TB_POS ,[noparse][[/noparse]x0,x1,x2,x3,x4,x5,x6,x7],PULSE_WIDTH 'the
>pulse_width variable is updated...
> SEROUT 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] ' send updated pulse_width value
>to second stamp..
>GOTO MAIN: ' loop over and over...
>
>
>
>program 2 ****
>
>'{$STAMP BS2}
>'{$PBASIC 2.5}
>PULSE_WIDTH VAR WORD
>INPUT 14
>INPUT 13
>INPUT 10
>OUTPUT 12
>OUTPUT 11
>
>BOOTUP:
> IF IN14 = 0 THEN STUCK
> GOTO MAIN
>STUCK:
> IF IN14 = 0 THEN STUCK
> GOTO MAIN
>INJECT1:
> PULSOUT 12, PULSE_WIDTH
> IF IN14 = 0 THEN MAIN2
> GOTO MAIN3
>INJECT2:
> PULSOUT 11, PULSE_WIDTH
> IF IN13 = 0 THEN MAIN4
> GOTO MAIN
>
>
>MAIN: '*** main program area
> SERIN 1\0, 16468, [noparse][[/noparse]PULSE_WIDTH] 'receave pulse_width value from
>the first stamp 2
> IF IN14 = 0 THEN INJECT1 ' in condition is true, perform rest of
>the program, if false, loop over agian to receave the pulse_width
>from first stamp...
> GOTO MAIN ' loop over agian and agian....
>
>
>MAIN2:
> IF IN14 = 0 THEN MAIN2
> GOTO MAIN3
>MAIN3:
> IF IN13 = 0 THEN INJECT2
> GOTO MAIN3
>MAIN4:
> IF IN13 = 0 THEN MAIN4
> GOTO MAIN
>
>***** end of program... as you see in theory it looks nice and
>fruity, but my application is time critical, with the inputs on the
>second stamp being triggered around 80~120 cycles a second , i cant
>have the serin command take long and not beable to reconize the
>input's are being triggered while its reading the serial data....
>
>Sean...