Shop OBEX P1 Docs P2 Docs Learn Events
Set Port problem — Parallax Forums

Set Port problem

aeae Posts: 7
edited 2009-12-07 13:15 in Propeller 1
Hi All,

I will use a tmr spin in a serate cog·which is blinking a led.
The Led is not blinking but the TmrTick· is working ! How can I correct this code?

{{··Main Program }}
CON
· _clkmode = xtal1 + pll16x······ ' use crystal x 16
· _xinfreq = 5_000_000··········· ' 5 MHz cyrstal (sys clock = 80 MHz)
OBJ
· Tmr··· : "LedTmr.spin"
PUB main | i
· tmr.Start
·
'The main loop
·repeat
····i:=1·· 'Wait Idle
{{ End Of Main Program }}


{{ LedTmr.spin }}
CON
· LED·· = 27 'P27
· Ms500 = 50
VAR
· long· Stack[noparse][[/noparse]16]·················· 'Stack space for new cog
· byte· Cog·························· 'Hold ID of cog in use, if any
· byte· LEDCntr

PUB Start: Success
{{Start new blinking process in new cog; return TRUE if successful}}
· Stop
· LEDCntr := 0
· OUTA[noparse][[/noparse]LED]:=0·
· DIRA[noparse][[/noparse]LED]~~· 'Output for Led·
· Success := (Cog := cognew(PauseMs(10), @Stack) + 1) '10 ms·timer
··
PUB Stop
{{Stop toggling process, if any.}}
· if Cog
··· cogstop(Cog~ - 1)

PRI TmrTick·
· if LEDCntr>0···
··· LEDCntr--
· else
··· !OUTA[noparse][[/noparse]LED]· '500 ms LED togle
··· LEDCntr:=Ms500
···

PUB PauseMs(Period)|ClkCycles
{{Pause execution for Period (in units of 1 ms).}}
· ClkCycles := ((clkfreq / 1000 * Period) - 4296) #> 381···· 'Calculate 1 ms time unit
· repeat
··· waitcnt(ClkCycles + cnt)·································· 'Wait for designated time·············
··· TmrTick
{{ End Of·LedTmr.spin Program }}

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2009-12-07 12:57
    Each cog has it's own set of dira/outa registers. In the start method you manipulate them in the context of the caller cog (not the one you subsequently start and which toggles the LED). What you have to do is move the two lines relating to dira/outa handling into the PauseMs() method. Actually, dira setup will be sufficient.

    Post Edited (kuroneko) : 12/7/2009 1:04:55 PM GMT
  • aeae Posts: 7
    edited 2009-12-07 13:15
    Thank you very much your quick reply.
Sign In or Register to comment.