Shop OBEX P1 Docs P2 Docs Learn Events
what am I doing wrong??? — Parallax Forums

what am I doing wrong???

propshaftpropshaft Posts: 3
edited 2012-02-15 08:47 in Propeller 1
Greetings. I am a new to the Propeller, but not new to microcontrollers and assembler.

I have looked at a lot of code examples and done a lot of reading, but I am hung up on a piece of code that does not do what I expect. I'm sure I am doing something stupid, but I can't see it... help please? I seem to not be able to pre-load the value of "Delay" in my assembler code.

I should get a 2.5MHz square wave on pin 7 with this code, but I do not. What seems to be happening is that Delay is set to some unknown value and waitcnt is take a VERY long time (expected of course).
CON
    _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
    _xinfreq = 5_000_000
            
PUB public_method_name
  cognew(@entry,0)


DAT
              org 0


entry         mov       dira, #$80              ' P7 as output
              mov       Time, cnt
              add       Time, Delay
loop          waitcnt   Time, Delay
              xor       outa, #$80              ' toggle P7
              jmp #loop


Time          res       1
Delay         long      16

If I change the code like this, it works fine.
CON
    _clkmode = xtal1 + pll16x                                               'Standard clock mode * crystal frequency = 80 MHz
    _xinfreq = 5_000_000
            
PUB public_method_name
  cognew(@entry,0)


DAT
              org 0


entry         mov       dira, #$80              ' P7 as output
              mov       Time, cnt
              add       Time, #16
loop          waitcnt   Time, #16
              xor       outa, #$80              ' toggle P7
              jmp #loop


Time          res       1
Delay         long      16

What newbie mistake am I making? :)

Comments

  • propshaftpropshaft Posts: 3
    edited 2012-02-15 07:49
    Well, after my initial post went back to the code examples and I suddenly noticed that the RES statements were AFTER the LONGS... well if it isn't spelled out in black in white in the Propeller Manual on pages 340 and 341. I feel embarrassed now. :lol:
  • tonyp12tonyp12 Posts: 1,951
    edited 2012-02-15 07:51
    >Time res 1
    >Delay long 16

    reserved space (will be of unkown value) should always be listed last.
  • LeonLeon Posts: 7,620
    edited 2012-02-15 08:47
    Out of curiosity, I used the SPAD debugger to see what value was actually being loaded. It was 16909825!
Sign In or Register to comment.