Set Port problem
ae
Posts: 7
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 }}
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
Post Edited (kuroneko) : 12/7/2009 1:04:55 PM GMT