Shop OBEX P1 Docs P2 Docs Learn Events
Help - I've forgotten how to code PASM — Parallax Forums

Help - I've forgotten how to code PASM

Dr_AculaDr_Acula Posts: 5,484
edited 2012-03-04 05:18 in Propeller 1
This is a bit embarrassing to ask but I can't seem to get a pin to change state in pasm and I would be most appreciative if some kind soul could look over my (almost certainly incorrect) code. I've been working with some very complex code driving a touchscreen but a simple pin toggle has failed and so I've ended up simplifying the code right back to something very basic.

I'm sure it is something simple. Problem can be replicated on two boards. Pin 22 is not connected to anything else except a 10k pullup.

Spin seems to work fine.
  DIRA := %00000000_11111111_11111111_11111111          ' enable these pins for output
  OUTA := %00000000_01000000_00000000_00000000          ' set pin 22 high 

and set the pin low again
  OUTA := %00000000_10111111_11111111_11111111          '  set pin 22 low

So, port this over to pasm using a driver that cluso wrote years ago and which has always worked fine. Start the cog and initialise the routine. Send a command and it jumps to a line that does this
                        mov     outa,low22             ' always pin P22 is high no matter what you send out.   

low22                   long    %00000000_10111111_11111111_11111111     

There is a halt just after this which correctly halts the cog, and returns control to spin (correctly) if you remove the halt.

I tried swapping propeller chips. I also tried putting "zero" instead of "low22" and all the other pins go low. Just not pin 22.

There is a 10k pullup on this pin, but this is not enough to light the led when the pin is set low in spin.

I've tried swapping hardware to a different board though the fact that this works in spin does go against a hardware problem. But nothing is impossible!

Other pins seem to work ok.

Right now I need a sanity check - if the error is not obvious, would someone be kind enough to just run the code below and let me know if P22 is high or low? (I think that mov outa,low22 should make it low but it is not)

Many thanks in advance.
' Test pin 22 in a pasm routine
CON
  _clkmode      = xtal1 + pll16x                        ' use crystal x 16
  _xinfreq      = 5_000_000

VAR
   long  command, hubaddrs, ramaddrs, blocklen, errx, cog ' rendezvous between spin and assembly (can be used cog to cog)
   
PUB Main
  start_ram                                             ' start the cog driver
  DIRA := %00000000_11111111_11111111_11111111          ' enable these pins for output
  OUTA := %00000000_01000000_00000000_00000000          ' set pin 22 high prior to running cog code
  docmd("A",0,0,0)                                      ' send a command to the cog
  OUTA := %00000000_10111111_11111111_11111111          ' should never get here if pasm halts
  repeat
  
PUB start_ram : err_
  command := "I"
  cog := 1 + cognew(@tbp2_start, @command)
  if cog == 0
    err_ := $FF                 ' error = no cog
  else
    repeat while command        ' driver cog sets =0 when done
    err_ := errx                ' driver cog sets =0 if no error, else xx = error code

PUB stop_ram
   if cog
      cogstop(cog~ - 1)      

PUB DoCmd(command_, hub_address, ram_address, block_length) : err_
  hubaddrs := hub_address       ' hub address start
  ramaddrs := ram_address       ' ram address start
  blocklen := block_length      ' block length
  command  := command_          ' must be last !!
' Wait for command to complete and get status
  repeat while command          ' driver cog sets =0 when done
  err_ := errx                  ' driver cog sets =0 if no error, else xx = error code


DAT
                        org     0
tbp2_start    ' setup the pointers to the hub command interface (saves execution time later
                                      '  +-- These instructions are overwritten as variables after start
comptr                  mov     comptr, par     ' -|  hub pointer to command                
hubptr                  mov     hubptr, par     '  |  hub pointer to hub address            
ramptr                  add     hubptr, #4      '  |  hub pointer to ram address            
lenptr                  mov     ramptr, par     '  |  hub pointer to length                 
errptr                  add     ramptr, #8      '  |  hub pointer to error status           
cmd                     mov     lenptr, par     '  |  command  I/R/W/G/P/Q                  
hubaddr                 add     lenptr, #12     '  |  hub address                           
ramaddr                 mov     errptr, par     '  |  ram address                           
len                     add     errptr, #16     '  |  length                                
err                     nop                     ' -+  error status returned (=0=false=good) 

init                    mov     err, #0                  ' reset err=false=good

done                    wrlong  err, errptr             ' status  =0=false=good, else error x
                        wrlong  zero, comptr            ' command =0 (done)

pause
                        rdlong  cmd, comptr     wz      ' command ?
              if_z      jmp     #pause                  ' not yet
' decode command
                        cmp     cmd, #"A"       wz                ' move a block from ram to the display
              if_z      jmp     #moveblock
                        cmp     cmd, #"I"       wz      ' init
              if_z      jmp     #init     
                        mov     err, cmd                ' error = cmd (unknown command)
                        jmp     #done
' ------------------ Commands ----------------------------
Moveblock               mov     dira,dirpins
                        mov     outa,low22             ' always pin P22 is high no matter what you send out.
                        jmp     #halt

                        ' should never get here with the halt
                        jmp     #init
                        
halt                    jmp     #halt                        

zero                    long    %00000000_00000000_00000000_00000000
low22                   long    %00000000_10111111_11111111_11111111
dirpins                 long    %00000000_11111111_11111111_11111111
                        fit     496  

Comments

  • T ChapT Chap Posts: 4,223
    edited 2012-03-04 03:29
    I don't know PASM, but is command supposed to be a stack?
  • Miner_with_a_PICMiner_with_a_PIC Posts: 123
    edited 2012-03-04 03:48
    The contents of the OUTA register is the result of logically OR'ing all the OUTA values for all cogs. The cog running spin has set the P22 bit in OUTA high so no other cog can possibly change it state. Try setting the pin state of P22 to zero in the spin cog and see if that fixes the issue.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-03-04 03:57
    Thanks miner. Yes you are right, it is the logical OR thing of all the cogs. I was thinking of logical OR with all pasm code but I forgot about the spin cog as well.

    I was so close inside the pasm part that I forgot about looking at the spin part.

    I think that solves the problem!

    Thanks++
    ' Test pin 22 in a pasm routine
    CON
      _clkmode      = xtal1 + pll16x                        ' use crystal x 16
      _xinfreq      = 5_000_000
    
    VAR
       long  command, hubaddrs, ramaddrs, blocklen, errx, cog ' rendezvous between spin and assembly (can be used cog to cog)
       
    PUB Main
      start_ram                                             ' start the cog driver
      DIRA := %00000000_11111111_11111111_11111111          ' enable these pins for output
      'OUTA := %00000000_11111111_11111111_11111111          ' set pins P0-P23 high 
      docmd("A",0,0,0)                                      ' send a command to the cog
      OUTA := %00000000_00000000_00000000_00000000          ' should never get here if pasm halts
      repeat
      
    PUB start_ram : err_
      command := "I"
      cog := 1 + cognew(@tbp2_start, @command)
      if cog == 0
        err_ := $FF                 ' error = no cog
      else
        repeat while command        ' driver cog sets =0 when done
        err_ := errx                ' driver cog sets =0 if no error, else xx = error code
    
    PUB stop_ram
       if cog
          cogstop(cog~ - 1)      
    
    PUB DoCmd(command_, hub_address, ram_address, block_length) : err_
      hubaddrs := hub_address       ' hub address start
      ramaddrs := ram_address       ' ram address start
      blocklen := block_length      ' block length
      command  := command_          ' must be last !!
    ' Wait for command to complete and get status
      repeat while command          ' driver cog sets =0 when done
      err_ := errx                  ' driver cog sets =0 if no error, else xx = error code
    
    
    DAT
                            org     0
    tbp2_start    ' setup the pointers to the hub command interface (saves execution time later
                                          '  +-- These instructions are overwritten as variables after start
    comptr                  mov     comptr, par     ' -|  hub pointer to command                
    hubptr                  mov     hubptr, par     '  |  hub pointer to hub address            
    ramptr                  add     hubptr, #4      '  |  hub pointer to ram address            
    lenptr                  mov     ramptr, par     '  |  hub pointer to length                 
    errptr                  add     ramptr, #8      '  |  hub pointer to error status           
    cmd                     mov     lenptr, par     '  |  command  I/R/W/G/P/Q                  
    hubaddr                 add     lenptr, #12     '  |  hub address                           
    ramaddr                 mov     errptr, par     '  |  ram address                           
    len                     add     errptr, #16     '  |  length                                
    err                     nop                     ' -+  error status returned (=0=false=good) 
    
    init                    mov     err, #0                  ' reset err=false=good
    
    done                    wrlong  err, errptr             ' status  =0=false=good, else error x
                            wrlong  zero, comptr            ' command =0 (done)
    
    pause
                            rdlong  cmd, comptr     wz      ' command ?
                  if_z      jmp     #pause                  ' not yet
    ' decode command
                            cmp     cmd, #"A"       wz                ' move a block from ram to the display
                  if_z      jmp     #moveblock
                            cmp     cmd, #"I"       wz      ' init
                  if_z      jmp     #init     
                            mov     err, cmd                ' error = cmd (unknown command)
                            jmp     #done
    ' ------------------ Commands ----------------------------
    Moveblock               mov     outa,zero             ' always pin P22 is high no matter what you send out.
                            jmp     #halt
    
                            ' should never get here with the halt
                            jmp     #init
                            
    halt                    jmp     #halt                        
    
    zero                    long    %00000000_00000000_00000000_00000000
    
                            fit     496 
    
  • Miner_with_a_PICMiner_with_a_PIC Posts: 123
    edited 2012-03-04 05:10
    Bugs are always obvious in hindsight. The first time I experienced this same bug I must have scoured over the PASM section line by agonizing line for hours before giving up and sleeping on it. I finally found the issue a day later, second time it happened a much quicker debug until now its the first thing I look for when pin states become unresponsive.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-03-04 05:18
    I was kind of hoping someone would spot this one because they had seen it before.

    Well thanks to your help I've managed to speed up the refresh on the touchscreen from 9 seconds to 30 milliseconds.

    I am very grateful for your timely help - I was almost at the hair-pulling stage!
Sign In or Register to comment.