Shop OBEX P1 Docs P2 Docs Learn Events
Help with my first PASM code — Parallax Forums

Help with my first PASM code

DRMorrisonDRMorrison Posts: 81
edited 2014-07-25 09:14 in Propeller 1
Hello,
I'm attempting to write some PASM and need help. This is my first attempt at using PASM, so be gentle.

This is what I'm trying to convert:
PUB MoveCCW(num, spd)


 outa[10..11]~~                  'enable L293D
 repeat num
   outa[14..15] :=                 'output ON
   waitcnt(clkfreq/clkspd + cnt)   'wait
   outa[14..15] :=                'output OFF
   waitcnt(clkfreq/spd + cnt)
   outa[12..13] := 
   waitcnt(clkfreq/clkspd + cnt)
   outa[12..13] := 
   waitcnt(clkfreq/spd + cnt)
   outa[14..15] := 
   waitcnt(clkfreq/clkspd + cnt)
   outa[14..15] := 
   waitcnt(clkfreq/spd + cnt)
   outa[12..13] := 
   waitcnt(clkfreq/clkspd + cnt)
   outa[12..13] := 
   waitcnt(clkfreq/spd + cnt)
 outa[10..11]~                     'disable L293D

This code works as written, and represents one iteration thru the motor's wire combos. My oscilloscope shows the pulse width of the ON
time to be 1.48ms.

This is a method to move a 4-wire stepper in reverse. I have attempted to put something together, but am embarased to show it here.
I've played around with the timing of the 2 vars clkspd and spd, and this seems to be as fast as I can run this motor using SPIN, and
thought PASM might speed things up. Perhaps not?

THanks, Daniel

Comments

  • franksanderdofranksanderdo Posts: 14
    edited 2014-07-24 22:29
    Hi Daniel

    Don't be embarrassed and show what you have.
    It is easier for us here to help you on the first steps of learning curve if we can explain on your code snippet where the traps are hidden.
    PASM can be some what confusing in the beginning (I am at the moment just one step ahead of you and got my first routines working)
    Actually I am unsung the same approach: First a SPIN routine to test the Idea and after transferring that in PASM.

    One question to your SPIN:
    what is the difference between spd and clkspd and is that distinction required?

    All the Best
    Frank
  • DRMorrisonDRMorrison Posts: 81
    edited 2014-07-24 23:08
    Thanks for the encouraging words.

    spd is the value sent to the method and used as the on-time for the output to the L293D.
    clkspd is the constant value used for the off-time of the output.

    Pins 14 ,15 are set hi for the waitcnt(clkfreq/clkspd) period, advancing the stepper, and then are turned off. I found that laving these on for too long causes the current to go sky high.
    The next waitcnt w/spd is how the user can set a speed for the motor without having the current on during the delay.
    Turn on a switch, wait a little, turn off the switch, wait as much as required to achieve the desired speed.

    That's a long answer, hope it makes sense.

    As far as PASM, I was only able to get one waitcnt. I couldn't figure how to turn on only the 14 & 15 pins, wait, and then turn them off again.
    mov          dira, #C00
     mov          outa, #C00
    
    
     mov          time, cnt
     add          time, #100
     waitcnt      time, #200
     waitcnt      time, #0
    

    I'm not sure, but I think that this will result in a shorter on time than off. 100-ON, and 200-OFF?
    Embarrassing effort.

    Daniel
  • Mark_TMark_T Posts: 1,981
    edited 2014-07-25 04:19
    DRMorrison wrote: »
    Hello,


    This code works as written

    The code you've posted however is not legal Spin... Assignments need a RHS...

    The basic elements of PASM you need are easy, something like:
                    or      DIRA, pinmask    ' set up some pins as outputs
                    mov     time, cnt
                    add     time, delay   ' setup for initial waitcnt
    
                    ' delay like this:
                    waitcnt time, delay    ' where time is already set up, delay is the _next_ delay
                    ' manipulate pins like this, where xxxx are bit masks defined later
                    or      OUTA, xxxx    ' force pins high
                    andn    OUTA, xxxx    ' force pins low
                    xor     OUTA, xxxx     ' toggle pins
    
                    ...
    delay           long  clkfreq/clkspd
    pinmask         long    $0000F000   ' bits 12 to 15 set in the mask
    
    time            res     1
    
  • BeanBean Posts: 8,129
    edited 2014-07-25 05:32
    Mark_T wrote: »
    The code you've posted however is not legal Spin... Assignments need a RHS...

    I think there is an issue with the forum when you use a % where it doesn't show characters.

    Bean
  • BeanBean Posts: 8,129
    edited 2014-07-25 05:53
    I hope this helps...
      or outa,enable ' [10..11]~~                  'enable L293D
      mov count,num ' repeat num
    
    again
      'outa[14..15] :=                 'output ON
      mov temp,ina
      andn temp,mask1415
      or temp,outputOn
      mov outa,temp
      
      'waitcnt(clkfreq/clkspd + cnt)   'wait
      mov temp,clkspd
      add temp,cnt
      waitcnt temp,#0
    
      'outa[14..15] :=                'output OFF
      mov temp,ina
      andn temp,mask1415
      or temp,outputOff
      mov outa,temp
    
      'rest of code
    
      djnz count,#again
      andn outa,enable '  outa[10..11]~                     'disable L293D
    
    
    num       LONG 1000
    enable    LONG %1100_00000000  ' Enable L293D
    mask1415  LONG %11000000_00000000
    outputOn  LONG %11000000_00000000
    outputOff LONG 0
    clkspd    LONG 80_000 ' 1mSec * clock
    
    temp  res 1
    count res 1
    
    

    Bean
  • DRMorrisonDRMorrison Posts: 81
    edited 2014-07-25 09:14
    The spin code works, and the variables listed are brought in through the method call, or are a con set outside the method.
    I'm not sure what an RHS is. Could you explain?
    I see that the percent sign and numbers that I placed in the original code block didn't make it.
    It is suppose to be:

    outa[14..15] := *10 'replace percent sign with the * char
    here is the MoveCW method as seen in my editor:
    Screen Shot 2014-07-25 at 9.28.00 AM.png


    Bean, I like the way that you have written that code; it's easy for me to understand.
    Also, do I call this just like a spin method? like this?
    DAT MoveCCW(num, spd)
    
      code here
      etc
    
    

    Thanks, Daniel
Sign In or Register to comment.