please help debug a simple piece of code (one pin following another)
iammegatron
Posts: 40
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.
So without knowing what goes wrong, I trial and error again with this code:
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?
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
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
to
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"