Shop OBEX P1 Docs P2 Docs Learn Events
assembly code problems — Parallax Forums

assembly code problems

Jon87Jon87 Posts: 14
edited 2010-04-28 15:31 in Propeller 1
Hi everyone. I've been trying to learn some assembly lately but i'm having a few problems. I thought i understood all the tutorials i've done and examples i've looked at.

I'm trying to write an object to read remote control codes. I know the hardware is working. At the moment, I'm just trying to time the period when the receiver pin goes low at the start of the code and displaying that on a tv to see that its working. To be honest, i'm not sure if the problem is passing variables to and from DAT or if its something much bigger. Any pointers would be greatly appreciated, thanks

CON
 _clkmode = xtal1 + pll16x
 _xinfreq = 5_000_000

OBJ

  tv  :  "tv_text"
  
VAR
  long  rc5  
 
PUB Main
  tv.start(12)
  IRrx(1)
  repeat    
    tv.str(string($A,7,$B,3))
    tv.dec(rc5)

PUB IRrx (pin)
{{Launch cog to detect RC5 codes}}
  _pin := pin
  dira[noparse][[/noparse]pin]~
  cognew(@detect, @rc5)
  
DAT              

        org 0
detect  mov addr, PAR         
        waitpeq space, _pin               'Wait for start bit
        mov start, cnt                  'time start bit pulse
        waitpeq mark, _pin
        mov half, cnt
        sub half, start                 'half - start = start pulse length, should be about 71120 (80MHz * 889us)
        wrlong half, addr
        mov t, cnt
        waitcnt t, delay            
        jmp #detect

_pin    long 0                         'IR input pin
space   long 0
mark    long 2
delay   long 10_000_000
t       res 1
start   res 1
half    res 1                           'timed half period
addr    res 1                           'PAR address



EDIT - ignore 'space' and 'mark', this isn't the way i'll be doing it when its finished

Post Edited (Jon87) : 4/27/2010 5:45:50 PM GMT

Comments

  • Jon87Jon87 Posts: 14
    edited 2010-04-27 18:13
    Here's basically the same thing in spin, so you can see what i'm trying to do

    CON
            _clkmode        = xtal1 + pll16x
            _xinfreq        = 5_000_000
    
    VAR
      long count
      long delay
    
    OBJ
    
      tv : "tv_text"
      
    PUB main
      dira~
      tv.start(12)
      repeat
        if ina
        waitpeq (%00, |<1, 0)
        count := cnt
        waitpeq (%10, |<1, 0)
        delay := cnt - count
        tv.str(string($A,7,$B,3))
        tv.dec(delay)
        waitcnt(20_000_000 + cnt)
    
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-04-27 18:35
    Do you use a IR diode or a receiver which already filters the carrier frequency?

    You need to put |<pin into the _pin variable. waitpeq and waitpne expect a bitmask but you gave it the pin number. At least if the SPIN code is really a 1 to 1 copy.

    I think writing a IR receiver is already a sophisticated goal ... because I did it myself and know what a challange it is ;o)
    ( If you wanna see my code somewhen, drop a note )
  • Christof Eb.Christof Eb. Posts: 1,245
    edited 2010-04-27 18:39
    Hi,
    I think, you will need 3 waits.
    waitpeq
    waitpne 'Wait for the start
    waitpeq 'Wait for the end

    PASD is a debugger for Propeller assembler, which can help you to develop assembler routines.
    Good luck,
    Christof
  • Jon87Jon87 Posts: 14
    edited 2010-04-27 18:56
    MagIO2 said...
    Do you use a IR diode or a receiver which already filters the carrier frequency?

    You need to put |<pin into the _pin variable. waitpeq and waitpne expect a bitmask but you gave it the pin number. At least if the SPIN code is really a 1 to 1 copy.

    I think writing a IR receiver is already a sophisticated goal ... because I did it myself and know what a challange it is ;o)
    ( If you wanna see my code somewhen, drop a note )

    Well i thought i'd tried everything. it works now with the mask. thanks. i also had to add a little bit onto 't' for the delay.

    I'll get on with the rest now, thanks
  • Jon87Jon87 Posts: 14
    edited 2010-04-27 19:00
    Christof Eb. said...
    Hi,
    I think, you will need 3 waits.
    waitpeq
    waitpne 'Wait for the start
    waitpeq 'Wait for the end

    PASD is a debugger for Propeller assembler, which can help you to develop assembler routines.
    Good luck,
    Christof

    You've gave me an idea to use waitpne but i'm not sure what the 1st wait is for. The IR receiver pin is idle high, when a burst of IR signals at the right frequency is detected, it goes low. I'm just timing the low part

    EDIT - I'm also going to check out PASD, thanks
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-04-27 22:56
    I explained how I coded my PASM SIRCS decoder in this article -- it may help you out.

    www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp4.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • Jon87Jon87 Posts: 14
    edited 2010-04-28 12:27
    JonnyMac, thanks for the link, i scanned through your article. its interesting. At the minute, i just want to receive Phillips RC5 codes but if i get this working and have some free time, i'd like it to be able to detect other codes.

    The link i've got for PASD isn't working, http://forums.parallax.com/showpost.php?p=0

    I've written a bit more now and i'm receiving a code but the values seem to be all over the place. I beleive the problem is inside the loop in DAT.

    To find out what's going on, i want to toggle pin 6 (or any other pin, i'm not bothered) every time the input on the rx pin is sampled so i can see it on a scope but its not toggling at all. the output is constantly low (i'm using a 10K pull-up resistor). I tested the hardware setup in spin and i was able to toggle

    EDIT - Nevermind, i put "or dira, _opin" at the top of DAT and it toggles now. Why was this needed in DAT when i already had "dira[noparse][[/noparse]6]~~" in PUB IRrx?

    CON
     _clkmode = xtal1 + pll16x
     _xinfreq = 5_000_000
    
    OBJ
    
      pst  :  "parallax serial terminal"
      
    VAR
      long  rc5  
     
    PUB Main
      pst.start(115200)
      IRrx(1)
      repeat    
        pst.clear
        pst.dec(rc5)
        pst.tab
        pst.str(string("::"))
        pst.tab
        pst.bin(rc5, 12)
        waitcnt(20_000_000 + cnt)
    
    PUB IRrx (pin)
    {{Launch cog to detect RC5 codes}}
      _pin := |< pin
      _l := 11
      dira[noparse][[/noparse]pin]~
      dira[noparse][[/noparse]6]~~
      cognew(@go, @rc5)
      
    DAT              
    
            org 0
    go      mov addr, PAR
    detect  mov rxcode, #0
            mov count, cnt
            add count, delay
            waitcnt count, 0
            waitpne _pin, _pin              'Wait for start bit
            mov start, cnt                  'time start bit pulse
            waitpeq _pin, _pin
            mov half, cnt
            sub half, start                 'half - start = start pulse length, should be about 71120 (80MHz * 889us)
            cmp lh, half            wz, wc  'check that the half value is between the upper and lower limits
    if_nc   jmp #detect
            cmp uh, half            wz, wc
    if_z_or_c jmp #detect
            
            mov quart, half
            shr quart, #1                    'divide half by 2 to calculate T/4
            mov full, half
            shl full, #1                     'multiply half by 2 to calculate T
            mov tquart, half
            add tquart, quart                'add quart to half to calculate 3T/4
     
    
    Sb2     mov count, cnt                   'wait 3T/4 to detect second start bit
            add count, tquart
            waitcnt count, 0
            test _pin, ina          wz       'check second start bit
    if_nz   jmp #detect                      'jump to detect if zero not detected
    
            mov _l, #12                      'set up loop iteration
            mov count, cnt                   'begin receiving rc5 code
            add count, full                  'wait full time period
    
    
    loop    xor outa, _opin
            waitcnt count, full              'wait full time period
            test _pin, ina          wc       'test rx
    if_nc   add rxcode, #1                   'add 1 if rx is low
            shl rxcode, #1                   'shift rxcode left
            djnz _l, #loop                   'loop until full code is received
            wrlong rxcode, addr              'write rxcode to hub
            mov time, cnt
    
            add time, delay
            waitcnt time, 0                  'wait a bit
            jmp #detect                      'go back to detect next code
    
    
    _opin   long |<6
    _pin    long 0                         'IR input pin
    lh      long 70000
    uh      long 75000
    _l      long 0
    delay   long 5_000_000
    time    res 1
    t       res 1
    start   res 1
    half    res 1                           'timed half period
    quart   res 1
    tquart  res 1
    full    res 1
    addr    res 1                           'PAR address
    rxcode  res 1
    count   res 1
    frame   res 1
    

    Post Edited (Jon87) : 4/28/2010 12:39:50 PM GMT
  • kuronekokuroneko Posts: 3,623
    edited 2010-04-28 12:54
    Jon87 said...
    Why was this needed in DAT when i already had "dira[noparse][[/noparse]6]~~" in PUB IRrx?
    Each cog has its own set of dira/outa. Your SPIN method runs in cog N and starts another (PASM) cog M.
  • Jon87Jon87 Posts: 14
    edited 2010-04-28 13:09
    kuroneko said...
    Jon87 said...
    Why was this needed in DAT when i already had "dira[noparse][[/noparse]6]~~" in PUB IRrx?
    Each cog has its own set of dira/outa. Your SPIN method runs in cog N and starts another (PASM) cog M.

    Oh right, so i guess the "dira[noparse][[/noparse]pin]~" doesn't do anything either, i was just lucky that all pins are inputs as default?

    The code's finished now and its working well. thanks everyone
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-04-28 15:31
    Sorry, I missed that you're working with RC-5.· I've attached my RC-5 project for you to compare notes with.

    Yes, pins default to inputs but it doesn't hurt to be specific, especially in your objects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.