Procedure not working while activating using cognew()
att_jay
Posts: 10
Hi
I have written a basic spin code that uses two cogs cog1 and cog2, of which one is used to generate a stream of pulse (square wave) and other be used to see the Active high condition of the pulse to increment a counter. The cog0 (main cog) is then used to update the display based on the cog1 incremented value.
Following code I have written to do this...
ISSUE:
1. I cannot be able to run the _Counterprocess procedure while using cognew(), however if i declare _Counterprocess in main cog0 then it runs.
2. Please suggest any change in the code that helps in running cog1 independent of cog0 etc.
CON
_clkmode = xtal1 + pll8x
_xinfreq = 5_000_000
VAR
long Stack[9], Stack1[20]
PUB main
cognew(_Toggle(Pin,400_000), @Stack)
cognew(_Counterprocess(@_counter0), @Stack1)
repeat 100_000
_ComCNTR := _ComCNTR + 1
if (_switch := ina[P13]) == 0
outa[P14] := 0
quit
if (_pulsein := ina[P11]) == 1
_ComCNTR := 0
_Sfcounter := _Sfcounter + _Sfactor
if _Sfcounter => _Target
repeat
if _counter0 == 9
_counter0 := 0
_Setfirst
else
_counter0 := _counter0 + 1
'_Counterprocess(@_counter0)
_Sfcounter := _Sfcounter - _Target
while(_Sfcounter => _Target)
_CNTR := 1
_Pause(5)
repeat until (_pulsein := ina[P11]) == 0
quit
else
_pulsein := 0
_CNTR := 0
while(_CNTR <> 0)
PUB _Toggle(P,_Delay) ' pulse generation
dira[P]~~
repeat 1000
!outa[P]
waitcnt(_Delay + cnt)
PUB _Counterprocess(_counter00) ' to see the count value and display on LCD
repeat
_Blank($11)
_DisplayOn
CASE byte[_counter00]
0: _WriteZero($11)
1: _WriteOne($11)
2: _WriteTwo($11)
3: _WriteThree($11)
4: _WriteFour($11)
5: _WriteFive($11)
6: _WriteSix($11)
7: _WriteSeven($11)
8: _WriteEight($11)
9: _WriteNine($11)
OTHER:
_Pause(1)
I have written a basic spin code that uses two cogs cog1 and cog2, of which one is used to generate a stream of pulse (square wave) and other be used to see the Active high condition of the pulse to increment a counter. The cog0 (main cog) is then used to update the display based on the cog1 incremented value.
Following code I have written to do this...
ISSUE:
1. I cannot be able to run the _Counterprocess procedure while using cognew(), however if i declare _Counterprocess in main cog0 then it runs.
2. Please suggest any change in the code that helps in running cog1 independent of cog0 etc.
CON
_clkmode = xtal1 + pll8x
_xinfreq = 5_000_000
VAR
long Stack[9], Stack1[20]
PUB main
cognew(_Toggle(Pin,400_000), @Stack)
cognew(_Counterprocess(@_counter0), @Stack1)
repeat 100_000
_ComCNTR := _ComCNTR + 1
if (_switch := ina[P13]) == 0
outa[P14] := 0
quit
if (_pulsein := ina[P11]) == 1
_ComCNTR := 0
_Sfcounter := _Sfcounter + _Sfactor
if _Sfcounter => _Target
repeat
if _counter0 == 9
_counter0 := 0
_Setfirst
else
_counter0 := _counter0 + 1
'_Counterprocess(@_counter0)
_Sfcounter := _Sfcounter - _Target
while(_Sfcounter => _Target)
_CNTR := 1
_Pause(5)
repeat until (_pulsein := ina[P11]) == 0
quit
else
_pulsein := 0
_CNTR := 0
while(_CNTR <> 0)
PUB _Toggle(P,_Delay) ' pulse generation
dira[P]~~
repeat 1000
!outa[P]
waitcnt(_Delay + cnt)
PUB _Counterprocess(_counter00) ' to see the count value and display on LCD
repeat
_Blank($11)
_DisplayOn
CASE byte[_counter00]
0: _WriteZero($11)
1: _WriteOne($11)
2: _WriteTwo($11)
3: _WriteThree($11)
4: _WriteFour($11)
5: _WriteFive($11)
6: _WriteSix($11)
7: _WriteSeven($11)
8: _WriteEight($11)
9: _WriteNine($11)
OTHER:
_Pause(1)
Comments
Forum Tag Reference
http://forums.parallax.com/misc.php?do=bbcode
For sanity sake, don't start a method with the underscore character. The underscore style is used to identify private variable members of an object.