Shop OBEX P1 Docs P2 Docs Learn Events
nop question — Parallax Forums

nop question

waltsailingwaltsailing Posts: 40
edited 2011-01-25 07:17 in Propeller 1
Hi,

I have been experimenting with some assembly code on the prop, to explore timing. it is running on the propeller demo board. The board works just fine from what i can tell. I get nice output to the VGA, etc.

The program below is just a simple toggle of pin 0. It moves in assembly a 1, then 0, then it is suppose to delay 1 instruction (4 cycles) and toggle it again.

I was watching the pin 0 on the prop scope. It toggles as expected. Unless i add one extra nop into the end. I can add two more nop's it works again, add in yet anouther nop, program hangs.

So, i decided to slow things down. So i commented out the pll16x, it runs slower as expected. But the inserted nops seem to cause the output to not show up.

But why is the output not toggling for all inserts of nops? What is going on here.

On one test program, using a simple loop with an xor, the nop was 100 nsec. when i added in more nops, i got incremental delays of 100 nsec as expected. This is with a 5 Mhz clock, x 16 or 80 Mhz, then that is 12.5 nsec per clock. The hub is suppose to run at 1/2 the system clock or at 25 nsec, so 4 times that is 100. That seems ok. If i knock off the pll16x it slows down ok. But the same thing happens.

I thought I was going to get a 100 nsec delay in either the high or low that I was causing on the output.

I was wondering if someone can explain what is going on here. Is the program hanging or is there something about the timing which is blocking or not allowing the output to be on the pin?

Thank You,
Walt

con
_clkmode=xtal1 + pll16x
_xinfreq=5_000_000

pub x1
cognew(@toggle,0)
dat
org 0
toggle mov dira,pin

:loop mov outa,pin
mov outa, 0
mov outa,pin
nop
mov outa, 0
nop
mov outa,pin
nop
nop
nop
nop
mov outa, 0
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop ' add a new nop and it dies. add 2 nops and it runs again

jmp #:loop


pin long 1
960 x 720 - 67K

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-01-24 21:12
    Use
    mov outa, [COLOR="red"]#[/COLOR]0
    
    the version without # will copy register $000 into outa. From context not what you want (for every nop inserted bit 0 of register 0 toggles).
  • waltsailingwaltsailing Posts: 40
    edited 2011-01-24 21:37
    Thanks,

    Ok, from what you noted i think this is why...

    When i look at my code, assuming it is in the wrong way i wrote it, i see the first register (memory location 0) is allways the instruction for mov dira, pin1 which would have been what is written to the port, as if it were data. but adding in a NOP later should never have changed that. So, what is going on here? Reg 0, not the mov dira, pin1 instruction? The lsb of this instruction would have been the lsb of the location of Pin1... ahhh, that is it, it is an odd/even address for value I want for pin1, which would be a 0 for every other nop added. 1 otherwise. Got it. Thanks, Walt.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-01-24 22:03
    Nice cat. What brand is it? Looks quite similar to a Perry 43, or a Grainger design. Mine is a Tasman C35.
    Anyway Walt, welcome to the forum. You will find a lot of help here.

    Glad you have found the problem. A trap for beginners is the jmp/djnz/call type instructions and forgetting the "#", so just be aware of that too.
  • RS_JimRS_Jim Posts: 1,768
    edited 2011-01-25 06:34
    Hi Walt,
    Nice Boat! I haven't done any sailing since I left San Diego years ago. I see a potential problem with your code. Using mov outa,pin sets the desired pin but resets all others,whoops!
    Same thing mov outa,#0 resets all pins. Use or outa,pin to set. use andn outa,pin to reset and you only affect the pins inside your pin mask. The other thing you might try is use waitcnt instead of a bunch of nop's. Takes less code and you can preset variables to the on and off times that you want by using seperate variables.This way you can have delays as long or as short as you want.

    Welcome to the forum, I have found it a fantastic resource for answers!.
    RS_Jim
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-25 07:17
    @RS_Jim:
    He only uses one pin as output, so currently there is no problem in setting all pins to 0. But yes ... it's good advice to use or and andn for single pin manipulation instead.
Sign In or Register to comment.