Shop OBEX P1 Docs P2 Docs Learn Events
Throb — Parallax Forums

Throb

cavelambcavelamb Posts: 720
edited 2012-02-18 11:41 in Propeller 1
Spin is seriously strange...
But it's what w have to play with so I'm trying to learn more.

Playing wit the Repeat loop...
I'm trying to give the blinky LED a bit more expressiveness.
It works going UP, the LED ramps up nicely.
But I can't seem to make it go back down smoothly.

I'm guessing the step value can not be negative?
Although SPIN didn't whine about it.

Or maybe it's something I did???


OOPS! Fixed...
so that both loops count uo,
(Thanks Mark)

{ Feb 16, 2012 Throb1.spin }

CON
_CLKMODE=XTAL1 
_XINFREQ =5_000_000

MSec   = _XINFREQ / 5_000
USec   = _XINFREQ / 5_000_000
Tsec   = MSec *2                ' time for each step
Tstp   = 50                     ' number of steps per cycle

HI = 1
LO = 0
LED = 07                     

VAR
Long X

PUB  MAIN 
 
dira [LED] := 1              ' output bit for LED
outa [LED] := 0              ' start low


Repeat
 
    Repeat X from 1 to Tstp step 1
        outa[LED] := Hi                                 ' high period
        waitCNT ((X * Tsec) +Cnt)
        outa[LED] := LO                                  ' low period
        waitCNT (( Tstp - X+1 )*Tsec +cnt)

   Repeat X from 1 to Tstp step 1
        outa[LED] := Hi                                 ' high period
        waitCNT (( Tstp - X+1 )*Tsec +cnt)
        outa[LED] := LO                                  ' low period
        waitCNT ((X * Tsec) +Cnt)

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2012-02-18 04:11
    You reversed the logic of the repeat statement, but also reversed the meaning of X inside the loop - these cancel each other out.
  • cavelambcavelamb Posts: 720
    edited 2012-02-18 08:16
    I messed with it for so long trying to get the lingo working that I didn't catch that.
    Thanks, Mark.
  • cavelambcavelamb Posts: 720
    edited 2012-02-18 08:53
    Cleaning up a bit.

    The other thing that doesn't seem quite right is the timing.
    What I intended to do is set 5 MHz clock speed, then calculate microsec and
    millisec values (in Usec and Msec, respectively)

    But those milliseconds seem to be kinda short.

    Tdel is a short delay at the ends of each ramp - a pause for effect.
    But to make it show up at all I'm using 3500 * Milliseconds,
    which should be 3.5 seconds, right?

    Seems to be off by about a factor of 10?
    { Feb 18, 2012 Throb1.spin }
    
    CON
    _CLKMODE=XTAL1 
    _XINFREQ =5_000_000
    
    MSec   = _XINFREQ / 5_000
    USec   = _XINFREQ / 5_000_000
    
    Tstp   = 60                     ' number of steps per cycle
    Tdel = Msec * 3500               'short delay between  
    
    HI = 1
    LO = 0
    LED = 07                     
    
    VAR
    Long X
    
    PUB  MAIN 
     
    dira [LED] := 1              ' output bit for LED
    outa [LED] := 0              ' start low
    
    Repeat
        Repeat X from 1 to Tstp step 1
            outa[LED] := Hi                                 ''Ramp up
            waitCNT ((X * Msec) +Cnt)
            outa[LED] := LO                                  
            waitCNT (( Tstp - X+1 )*Msec +cnt)
    
      outa[LED] := Hi   
      waitcnt(Tdel +cnt)
    
        Repeat X from 1 to Tstp step 1     
            outa[LED] := Hi                                 ' 'Ramp Down
            waitCNT (( Tstp - X+1 )*Msec +cnt)
            outa[LED] := LO                                 
            waitCNT ((X * Msec) +Cnt)
    
      outa[LED] := LO
      waitcnt (Tdel +Cnt)
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-18 08:58
    I think you're off by a factor of 5.

    Divide the frequency by 1,000 for ms and 1,000,000 for us. (In this case, I think it would work.)
  • cavelambcavelamb Posts: 720
    edited 2012-02-18 11:41
    Duane Degn wrote: »
    I think you're off by a factor of 5.

    Divide the frequency by 1,000 for ms and 1,000,000 for us. (In this case, I think it would work.)

    debug.GildaVoice(string("Nevermind..."))
Sign In or Register to comment.