Shop OBEX P1 Docs P2 Docs Learn Events
please help debug a simple piece of code (one pin following another) — Parallax Forums

please help debug a simple piece of code (one pin following another)

iammegatroniammegatron Posts: 40
edited 2015-05-13 09:30 in Propeller 1
I know it must be my error somewhere. Please help me to find the problem.

The idea is to have PIN_13 following PIN_14 going high and low. PIN_14 is toggling all right. But PIN_13 is stuck at low.

CON
        _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
        _xinfreq = 5_000_000

        TOGGLE_PIN = 14
        FOLLOW_PIN = 13
PUB Main

 outa[TOGGLE_PIN] := 0
 dira[TOGGLE_PIN] := 1
 
 cognew(@entry, 0)
 
 repeat
   outa[TOGGLE_PIN]:=!outa[TOGGLE_PIN] 





DAT
   org
   
entry
      mov outa, #0
      or dira, output_pin
      
zero  test ina, input_pin wz        'wait to go high
 if_z jmp #zero
      or outa, output_pin

one   test ina, input_pin wc         'wait to go low
if_c  jmp #one
      andn outa, output_pin
      jmp #zero      
      
         
output_pin long %1<<FOLLOW_PIN        
input_pin  long %1<<TOGGLE_PIN        




So without knowing what goes wrong, I trial and error again with this code:


CON
        _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
        _xinfreq = 5_000_000

        TOGGLE_PIN = 14
        FOLLOW_PIN = 13
PUB Main

 outa[TOGGLE_PIN] := 0
 dira[TOGGLE_PIN] := 1
 
 cognew(@entry, 0)
 
 repeat
   outa[TOGGLE_PIN]:=!outa[TOGGLE_PIN] 





DAT
   org
   
entry
      mov outa, #0
      or dira, output_pin
      
{      
zero  test ina, input_pin wz        'wait to go high
 if_z jmp #zero
      or outa, output_pin

one   test ina, input_pin wc         'wait to go low
if_c  jmp #one
      andn outa, output_pin
      jmp #zero      
}


zero   test ina, input_pin wz
  if_z waitpeq input_pin, input_pin    'wait to go high
       or outa, output_pin
       
one    test ina, input_pin wc        'wait to go low
   if_c waitpne input_pin, input_pin
        andn outa, output_pin
        jmp #zero        


      
         
output_pin long %1<<FOLLOW_PIN        
input_pin  long %1<<TOGGLE_PIN        



Now when TOGGLE_PIN is low, FOLLOW_PIN stays low. But when TOGGLE_PIN is high, FOLLOW_PIN jumps up and down many times. Why is that?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2015-05-13 08:25
    So without knowing what goes wrong, I trial and error again with this code:
    When you want to access the input pins it has to be in the form of test mask, ina wc, IOW ina must be used as the source operand.
  • BeanBean Posts: 8,129
    edited 2015-05-13 08:28
    If I remember correctly. ina cannot be the first parameter.
    Try changing all the "TEST ina, xxx" to "TEST xxx,ina" so ina is the second parameter.
    This is because ina is a read-only register.

    Bean
  • iammegatroniammegatron Posts: 40
    edited 2015-05-13 09:30
    Yes, now it's working, after I change
    test ina, input_pin wz
    

    to
    test input_pin, ina wz
    

    thanks a lot for the help. Is this mentioned anywhere in the manual?

    I read the propeller manual about "TEST", which states "TEST is similar to AND except it doesn’t write a result to Value1; it performs a bitwise AND of the values in Value1 and Value2 and optionally stores the zero-result and parity of the result in the Z and C flags"
Sign In or Register to comment.