Shop Learn
[PASM2] Reading & Validating an SIRCS Bit -- Looking for Input/Suggestions — Parallax Forums

[PASM2] Reading & Validating an SIRCS Bit -- Looking for Input/Suggestions

JonnyMacJonnyMac Posts: 8,057
edited 2022-02-26 17:48 in PASM2/Spin2 (P2)

I'm working on a project that uses SIRCS bits to send data, so I want to measure and validate the incoming SIRCS data stream. External sources can foul the input, and if a sensor fails the line will stay low all the time. A standard SIRCS bit can be 2400, 1200, or 600 microseconds (low from sensor), followed by a 600 microsecond idle period (high).

My goal is to call a subroutine that will measure the low-going pulse and the idle time after. The pulse can be anything up to 250ms at which point I assume the input is bad. The idle time is nominally 600us between pulses, so 550us is my check value. The routine has a timeout function so that I can wait longer for the first (start) bit than for the next bit in a stream.

If the input is held low too long (sensor failure), the routine returns -2. If another bit shows up too early (interference), the routine returns -1.

This is what I have sketched out so far. I have tested the measurement portion using an inline method and that seems to work. Thanks for any suggestions you care to offer.

get_pulse       mov       pulsewidth, #0
                mov       idletime, #0

gp_wait         testp     rxp                           wc      ' sample rx
    if_nc       jmp       #gp_lo                                ' if bit detected, measure

                waitx     ##US_001                              ' hold 1us
                sub       timeout, #1                   wz      ' decrement timeout 
    if_z        ret                                             '  if done, abrt
                jmp       #gp_wait                              ' keep waiting

gp_lo           waitx     ##US_001                              ' hold 1us
                incmod    pulsewidth, ##250_000         wc      ' inc width; check for failure
    if_c        neg       pulsewidth, #2                        ' if fail, mark
    if_c        ret                                             '  and abort
                testp     rxp                           wc      ' resample
    if_nc       jmp       #gp_lo                                ' if low, keep measuring

gp_idle         waitx     ##US_001                              ' hold 1us
                incmod    idletime, ##550               wc      ' increment idle timing                        
    if_c        ret                                             ' if 500us, we're done
                testp     rxp                           wc      ' resample
    if_c        jmp       #gp_idle                              ' if early pulse, interference
                neg       pulsewidth, #1                        ' mark
                ret                                             '  and abort

The calling code will validate the legal SIRCS bit widths.

Sign In or Register to comment.