output pulsewidth value doesn't equal to converted input value
sipp4
Posts: 4
My code is attached (also copied at the end of this message), I'm using a BS2pe motherboard, Prototyping daughterboard (in socket B of the motherboard), and the Parallax 433 MHz RF Transceiver Package. Here's my problem:
I'm providing an input pulse with a period of 20 ms, and a high pulsewidth of 1.6ms to C on the daughterboard. I've converted the measured pulsewidth (measured via PULSIN) by multiplying by 2, as per page 343 of the PBASIC User's Manual (I've done this successfully in the past on my BS2). I get an output value of 1024 - why is this not 1600 and how can I fix it?
I've tried converting to decimal values before transmission, which gives output values of 8740...much longer than the 1600 I should be getting.
Thanks for your help,
Amy
Transmitter code:
' {$STAMP BS2pe}
' {$PBASIC 2.5}
' {$PORT COM5}
time VAR Word 'following color sensor example for daughterboard B
width VAR Word
DO
'PULSOUT 5, 1200 'Mobo pin 5 = ProtoDbB D
PULSIN 7,1,time 'Mobo pin 7 = ProtoDbB C
width=time*2 'Convert to microseconds
SEROUT 5, 16468, [noparse][[/noparse]width.HIGHBYTE, width.LOWBYTE]
LOOP
Receiver code:
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}
width VAR Word
DO
SERIN 1, 16468, [noparse][[/noparse] width.HIGHBYTE, width.LOWBYTE] 'BOE pin 1
DEBUG DEC width, CR
LOOP
I'm providing an input pulse with a period of 20 ms, and a high pulsewidth of 1.6ms to C on the daughterboard. I've converted the measured pulsewidth (measured via PULSIN) by multiplying by 2, as per page 343 of the PBASIC User's Manual (I've done this successfully in the past on my BS2). I get an output value of 1024 - why is this not 1600 and how can I fix it?
I've tried converting to decimal values before transmission, which gives output values of 8740...much longer than the 1600 I should be getting.
Thanks for your help,
Amy
Transmitter code:
' {$STAMP BS2pe}
' {$PBASIC 2.5}
' {$PORT COM5}
time VAR Word 'following color sensor example for daughterboard B
width VAR Word
DO
'PULSOUT 5, 1200 'Mobo pin 5 = ProtoDbB D
PULSIN 7,1,time 'Mobo pin 7 = ProtoDbB C
width=time*2 'Convert to microseconds
SEROUT 5, 16468, [noparse][[/noparse]width.HIGHBYTE, width.LOWBYTE]
LOOP
Receiver code:
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}
width VAR Word
DO
SERIN 1, 16468, [noparse][[/noparse] width.HIGHBYTE, width.LOWBYTE] 'BOE pin 1
DEBUG DEC width, CR
LOOP
bpe
240B
Comments
Amy
Transmitter code:
' {$STAMP BS2pe}
' {$PBASIC 2.5}
time VAR Word
width VAR Word
DO
'PULSOUT 5, 1200 'Mobo pin 5 = ProtoDbB D
PULSIN 7,1,time 'Mobo pin 7 = ProtoDbB C
width=time*2 'Convert to microseconds
SEROUT 5, 16468, [noparse][[/noparse]DEC width.HIGHBYTE, DEC width.LOWBYTE]
DEBUG DEC width, CR
LOOP
Receiver code:
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}
width VAR Word
DO
SERIN 1, 16468, [noparse][[/noparse] width.HIGHBYTE, width.LOWBYTE] 'BOE pin 1
DEBUG DEC width, CR
LOOP
While you are sending the Sync Pulse, you’re sending it too early. This may not entirely be your problem but it is a problem, nonetheless…The Sync Pulse should be sent just prior to the SEROUT. Also in the second message you’re sending the lowbyte and highbyte formatted to ASCII using the DEC formatter, which is not appropriate in this situation. On the receiver you’re not using formatters, so you can expect data to be received differently than sent. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thanks! I tried formating the received info to decimal format, but that canceled out my signal all together. I ended going back to the sample code (same thing I started with in the first place), changed as little as absolutely possible, and got it running. What I can't figure out is the purpose of the "!" and the WAIT"!" in the serin/serout command lines? They don't seem to do anything, but the code doesn't work without them. I've used wait with them before, but had to type the characters into the debug window to get the data to print out...that isn't the case with the transmitter/receiver sample code - it runs without the ! typed in the debug window. Is ! a special character to keep the synch pulse from printing in the debug window?
Amy
The “!” and the WAIT command help to ensure that the SERIN command waits for the start of the data and doesn’t get some garbage character, throwing off the alignment of your data. Picture this…You send out 4 bytes and expect to receive them on the other side. But the receiver might get a garbage byte which will now go into the first variable. Then your first variable will go into the second byte and so on with the last byte being discarded. Now all of your data is corrupt…every byte.
By waiting for a known header string the SERIN command doesn’t start storing variables until it gets what it was waiting for which should be the start of the packet. Now, optionally you can implement CRC checking to be sure the data was received correctly and if not you can ignore it.
BTW, in the previous reply perhaps I wasn’t clear on what I meant. You should not have used the formatters while sending a value (word variable) as two bytes..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support