Shop OBEX P1 Docs P2 Docs Learn Events
How do you set up Constans in PASM? — Parallax Forums

How do you set up Constans in PASM?

PhilldapillPhilldapill Posts: 1,283
edited 2008-07-01 15:36 in Propeller 1
I'm learning PASM and my first project is a modified PWM. In this, I need to have a table of duty cycle constants that will only be a byte. What I need to do, is somehow access this table each loop, set the duty cycle to whats stored in the address, increment the address pointer(or whatever it's called in PASM) and access the next variable on the next loop... etc... then go back to the start of the table, and repeat.

How do you store constants in PASM?

Comments

  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 20:47
    I was thinking something like this in the DAT section after my routines...
    Duty1   byte 0
    Duty2   byte 3
    Duty3   byte 6
    Duty4   byte 8
    ...
    Duty255 byte 99
    Duty256 byte 100
    

    This will be used to quickly access an 8-bit approximation of a sinewave. I'm guessing this would be ok, but how do you get the address of Duty1? Where is this stored? How do I access these based on addresses?
  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-30 21:19
    look at movs/movd instructions, e.g.

    mov update,#Duty1
    nop
    update mov t0,0-0
    add update,#1
    jmp update

    The first line, writes the source address for the 3rd instruction to read from. the 4th instruction increments the address by 1.
    Note, COG addressing is longs not bytes, either change you table to longs or you will need a bunch of long to byte fiddling
    If you want a full working example, let me know and I can post some
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 21:28
    Well, longs would be fine, that is, if I can still consolidate my bytes into the long. i.e. store four table entries in one long. I suppose, I would have to read a long, then shiftout 8 bits into a temporary byte variable to get the first entry, shift again for the second, and so on?

    I thought spin was pretty cool how easy it was to use, but now that I'm learning PASM, wow... so fast and powerful.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 21:29
    by the way, what is "nop"?
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2008-06-30 21:34
    NOP = no operation . It elapses 4 clocks. Used as a delay.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Aka: CosmicBob
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 21:36
    Hmmm, cool. But why is it used in your code, Timmoore??
  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-30 22:14
    becuase of the way the prop pipelines you need a 1 instruction delay between changing an instruction and executing that intruction. i.e. between the movs and the instruction needs 1 instruction delay. I put in a nop but almost always you can move your code around to put an instruction there.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-30 22:21
    Thanks Timmoore. Could you explain the third line? I don't quite understand that.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-06-30 22:41
    A good example is often you do a copy loop

    mov t1,#10
    movs update,#duty1
    nop
    update mov t0,0-0
    add update,#1
    djnz t1,#update

    in this case you can put the mov t1,#10 in place of the nop. Also note the add update,#1 is also changing the instruction and the djnz is the 1 instruction delay
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-07-01 15:36
    Phil: The Propeller doesn't directly support indexed addressing in PASM. Therefore you have to accomplish it with self-modifying code (this is one of the more tricky aspects of PASM). The "movs update, #duty1" instruction changes the value of the source field in the instruction itself located at the "update" label. You have to put an instruction in between modifying instruction and the instruction being modified, otherwise the unmodified version would already be in the instruction pipeline. The 0-0 convention helps to document in the code which field is being modified.

    DeSilva's machine language tutorial has more information. I suggest you read it if you are getting started with PASM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.