Shop OBEX P1 Docs P2 Docs Learn Events
output pulsewidth value doesn't equal to converted input value — Parallax Forums

output pulsewidth value doesn't equal to converted input value

sipp4sipp4 Posts: 4
edited 2007-08-17 17:23 in BASIC Stamp
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

Comments

  • sipp4sipp4 Posts: 4
    edited 2007-08-17 14:04
    I've just isolated this problem a little further - when I send the pulsewidth value to Debug via the transmitter I get 1480, which is correct. However, the value that gets to the Debug via the RF modules and the BS2 is 8224....what gives? Also if I use the command line to synch the receiver (as shown in the sample code), I get values of 32 via the receiver. Has anyone successfully used these RF modules?
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-17 14:09
    Amy,

    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
  • sipp4sipp4 Posts: 4
    edited 2007-08-17 16:03
    Chris -
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-17 17:23
    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
Sign In or Register to comment.