Shop OBEX P1 Docs P2 Docs Learn Events
help with pwm code — Parallax Forums

help with pwm code

agfaagfa Posts: 295
edited 2008-08-26 17:03 in Propeller 1
i'm trying to troubleshoot a problem with some code and can't seem to pin point the source of the problem. i've posted the code. i know the code is sloppy, but please bear with me. i now know there are better ways to pass variables to assembly, but as an exercise i still wanted to make this work.

i'm trying to combine two 16 bit values to one 32 bit value "pass" to pass to the assembly routine. i believe the problem is with the assembly line "shr left, #16". the problem occures when the variable "left " exceeds decimal 511, or 9 bits. the instruction table on page 350 of the PM shows that the source and destination are 9 bit values but i thought that these could be used as pointers to long variables

edit: oops!·the code is·posted now.

Post Edited (agfa) : 8/23/2008 3:00:18 PM GMT

Comments

  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-23 16:11
    your l and r variables are bytes.

    I would do something like this
    PUB go | x
      cognew(@entry, @pass)  
      repeat
        repeat x from 0 to 125     'linearly advance x from 0 to 125
          pass.word := x + 406         'left speed increments from 0 to 100%
          pass.word[noparse][[/noparse]0] := 531 - x            'right speed decrements from 100 to 0%
          'pass:=l<<16'+r            'combines the speed values to one variable            
          waitcnt(5_000_000 + cnt)   'wait a little while before next update
    
    DAT
    'for audio PWM, fundamental freq which must be out of auditory range (period < 50µS)
            org
    
    entry   mov dira, diraval              'set pins 12 and 13 to output               
            mov ctra, ctraval              'establish counter A mode's  APIN
            mov ctrb, ctrbval              '  "            "  b   "     Apin
            mov frqa, #1                   
            mov frqb, #1                   'set counter to increment 1 each cycle 
            mov time, cnt                 'record current time
            add time, period              'establish next period
    
    :loop   rdword left, par              'set "value" to the address of pass
            mov    value,right
            add    value,#2
            rdword right,value
            waitcnt time, period           'wait until next period
    
    

    Post Edited (Erik Friesen) : 8/23/2008 4:17:58 PM GMT
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-23 16:16
    I have no clue why but the above example does not include the pass.word in the first line even though my edited post shows it.
  • agfaagfa Posts: 295
    edited 2008-08-23 16:22
    duh.·

    thanks for looking at it, and for the suggestion.

    agfa

    edit: could you clarify what the edit problem was?

    Post Edited (agfa) : 8/23/2008 4:41:21 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-26 17:03
    The forums interprets [noparse][[/noparse] 1 ] without spaces between as selecting font size 1, it's so that people who don't use internet explorer can format thier posts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.