Shop OBEX P1 Docs P2 Docs Learn Events
PASM code not working — Parallax Forums

PASM code not working

O.A.A.O.A.A. Posts: 25
edited 2014-02-07 02:43 in Propeller 1
Hello All,
The following code is intended for recording the CNT of the positive edge of 18 pulses. The first 12 pulses are 39 kHz , the following phase continious 6 pulses are 41 kHz . The purpose is to determine the CNT of the frequency change point. The code starts but PHSA counter never becomes 1 and it is stuck in the loop.
DAT
                     ORG 0
'---------------------------------Receive_CTRA--------------------------------------------
'Records cnt of the positive edge of 18 pulses     
'------------------------------------------------------------------------------------  
Receive_CTRA         mov ctra, CTRArx_        ' set up counter, pos edge trigger  
                     mov frqa, #1             ' 1 count/trigger                     
                     mov p4, par
                     add p4, #16              ' initilize p4 --> T[4}
                     mov idx, last
:repeat              add p4, #4               ' increment p4                     
                     mov phsa, #0             ' clear phsa - holds accumulated count               
:loop                mov timeP, cnt           ' renew time_  
                     tjz phsa, #:loop         ' repeat until pulse received            
                     wrlong timeP, p4         ' write cnt for pulse idx to T[idx+4]
                     mov phsa, #0
                     sub idx, #1  WZ          ' Z flag is set if valee = 0            
                     if_NZ jmp #:repeat       ' repeat until idx = 0
:exit                wrlong last, par
                     mov ctra, #0
                     cogid  cog_rx
                     cogstop cog_rx           ' stop the cog
                     
CTRArx_              long  (%01010 << 26 ) | (0 << 9) | (pin)                                                  
RXpin                long  |< pin
last                 long  18 
idx                  res  1
timeP                res  1
cog_rx               res  1

The pulses are there, verified by osciloscope and also the following PASM code counts them:
DAT
                     ORG 0
{---------------------------------CountPulse----------------------------------------
   Counts pulses by using CTRA on pin for 1 milisecs and stops the cog
 -----------------------------------------------------------------------------------}  
Count                mov ctra, CTRArx         ' set up counter, pos edge trigger 
                     mov frqa, #1             ' 1 count/trigger                                     
                     mov phsa, #0             ' clear phsa - holds accumulated count
                     mov wait2, cnt           ' Set cnt0                        
                     add wait2, dur_                      
                     waitcnt wait2, #0        ' wait for 1 milisec                            
                     mov value, phsa                         
                     mov p2, par
                     add p2, #20
                     wrlong value, p2         ' write value to T[5]                      
                     mov ctrb, #0
                     wrlong last, par
                     cogid  cog_
                     cogstop cog_             ' stop the cog                                             

CTRArx               long  (%01010 << 26 ) | (0 << 9) | (pin)
dur_                 long  80_000
last                 long  19
p2                   res  1
wait2                res  1
value                res  1
cog_                 res  1


Alternatively I have written the following code using INA register instead of the CTRA counter and it works fine.
But what is the problem with the first code.
DAT
                     ORG 0
'---------------------------------Receive--------------------------------------------
'Records cnt for the positive edge of 18 pulses
'------------------------------------------------------------------------------------
Receive_INA             
                    
                     mov p3, par                     
                     add p3, #16              ' initilize p3 --> T[4]
                     mov idx, last_
:repeat              add p3, #4               ' increment p3                                                      
:loop                mov time_, cnt           ' renew time_ 
                     test RXpin, ina  WC      ' C flag is set if ina is high (1)    
                     if_NC jmp #:loop                  
                     wrlong time_, p3         ' write cnt for pulse idx to T[idx+4]                      
                     waitpeq null_, RXpin     ' Wait for low signal                
                     sub idx, #1  WZ          ' Z flag is set if value = 0            
                     if_NZ jmp #:repeat       ' repeat until idx = 0
:exit                wrlong last_, par                     
                     cogid  cog_rx
                     cogstop cog_rx           ' stop the cog
                     
RXpin                long  |< pin                           
CTRArx               long  (%01010 << 26 ) | (0 << 9) | (pin)
last_                long  18
null_                long  0
p3                   res  1
idx                  res  1
time_                res  1
cog_rx               res  1


I am also attaching the spin object.
Thank you

O.A.Ardali

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-02-06 14:33
    I think your problem is with this statement:
    tjz phsa, #:loop ' repeat until pulse received

    When phsa is read as a destination register, its shadow register is used instead which, in your case was set to zero when you initialized phsa. The solution is to mov phsa into another register with a wz, then jump on the zero-flag condition.

    -Phil
  • O.A.A.O.A.A. Posts: 25
    edited 2014-02-07 02:43
    Thank you Phil,
    I suspected tjz statement is the problem but I didn't know the reason.
    Thanks again.
    O.A.Ardali
Sign In or Register to comment.