Procedure not working while activating using cognew()
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.
[indent] {{First Propeller Program To Test various features/command set for display}} CON _clkmode = xtal1 + pll8x _xinfreq = 5_000_000 rs= 4 'Register select en= 5 'Enable msb = 3 'Highest dataline lsb = 0 'Lowest dataline 'LCD Commands EightBitInit = 3 'Eight Bit mode FourBitInit = 2 'Four Bit mode ClearLcd = 1 'Clear the LCD CursorBlink = $0F 'Turn the cursor on and blink it NoCursor = $0C 'Turn the cursor off 'LCD constants lcdlines = 4 '# of lines on the LCD. Assumes the lines are a power of 2 (1,2,4,8,16,etc..) linelength = 20 'LCD line length Line1 = $80 'Address of the First Line Line2 = $C0 'Address of the Second Line Line3 = $94 'Address of the Third Line Line4 = $D4 'Address of the Fourth Line lf = $0A 'Line Feed code cr = $0D 'Carriage Return code esc = $1B 'Escape code eos = $FF 'End Of String code eog = $ff 'End of Custom Graphics Load command cgra = $40 'Address of the cgram off = 0 'Cursor State constant on = 1 'Cursor State constant space = $20 P0 = 1 ' Data0 (Output) P1 = 2 ' Data1 (Output) P2 = 3 ' Data2 (Output) P3 = 4 ' Data3 (Output) P4 = 5 ' Data4 (Output) P5 = 6 ' Data5 (Output) P6 = 7 ' Data6 (Output) P7 = 8 ' Data7 (Output) P8 = 13 ' RS (Output) P9 = 14 ' R/W (Output) P10 = 15 ' EN (Output) P11 = 16 ' Pulse (Input) P12 = 17 ' Backlight (Output) P13 = 18 ' Nz switch (Input) P14 = 19 ' Motor On/Off (Output) Pin = 20 i2cSCL = 28 i2cSDA = 29 Delay1 = 400 Delay2 = 400 finaldelay = 200 EEPROM_Addr = %1010_0000 VAR byte CurrentLine 'Current Line position Value 0-3 byte CurrentPos 'Current Column position Value 0-19 byte CursorState byte ddra 'Screen Data address byte _counterd,_counter0, _counter1, _counter2, _counter3, _counter4, _CNTR, _nzswitch, _Activestate, _FlDelFinish, _ReadyNewDely,_VARB byte _reset, aa, _pulsein, t, _Stop long _Sfactor, _Sfcounter, _Target, _ComCNTR long Stack[9], Stack1[20] OBJ DT : "displaytest" PUB _prog DT.SetPin dira[P11] := 0 dira[P12] := 1 dira[P13] := 0 dira[P14] := 1 _DisplayOn Clear _Initialize DT.SetPin _Target := 2500 _Sfactor := 2500 Clear repeat 1 _WriteEight($00) _WriteEight($04) _WriteEight($08) _WriteEight($0C) _WriteDecimal($23) _WriteEight($11) _Pause(1000) Clear _Pause(1000) Clear SetZero($00) _counter0 := 1 _counter1 := 0 _counter2 := 0 _counter3 := 0 _counter4 := 0 _Sfcounter := 0 _FlDelFinish := 0 _ComCNTR := 0 _CNTR := 0 cognew(_Toggle(Pin,400_000), @Stack) cognew(_Counterprocess(@_counter0), @Stack1) aa := 0 repeat outa[P14] := 1 repeat 100_000 _ComCNTR := _ComCNTR + 1 if (_nzswitch := ina[P13]) == 0 outa[P14] := 0 quit if (_pulsein := ina[P11]) == 1 _ComCNTR := 0 aa := 1 _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 'aa := 0 _pulsein := 0 _CNTR := 0 while(_CNTR <> 0) outa[P14] := 0 _DisplayOff _nzswitch := ina[P13] if _nzswitch == 0 _FlDelFinish := 1 _ReadyNewDely := 1 _VARB := 1 else if _nzswitch == 1 AND _ComCNTR == 100_000 _FlDelFinish := 1 _ReadyNewDely := 0 _VARB := 0 _Pause(1_000) repeat if (_nzswitch := ina[P13]) == 0 _VARB := 1 _ReadyNewDely := 1 _Pause(1_000) quit repeat _nzswitch := ina[P13] if _nzswitch == 1 AND _FlDelFinish == 1 AND _ReadyNewDely == 1 AND _VARB == 1 if (_nzswitch := ina[P13]) == 1 reboot dat char0 byte $05,$05,$0D,$15,$0F,$05,$05,$05 'CG Ram data PUB _Toggle(P,_Delay) dira[P]~~ repeat 1000 !outa[P] waitcnt(_Delay + cnt) '(@_counter0,P13,@_Sfcounter,@_ComCNTR, @_Stop) PUB _Counterprocess(_counter00) 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) PUB _Initialize |_row, _col _row := 0 _col := 0 repeat 105 _SetDDRAmaddr(_col+$80) _WriteDDRAM($06) _col++ _Pause(5000) PUB _DisplayOff _Pause(20_000) outa[P12] := 0 PUB _DisplayOn outa[P12] := 1 PUB _Setfirst if _counter1 == 9 _counter1 := 0 _SetSecond else _counter1 := _counter1 + 1 _Blank($0C) CASE _counter1 0: _WriteZero($0C) 1: _WriteOne($0C) 2: _WriteTwo($0C) 3: _WriteThree($0C) 4: _WriteFour($0C) 5: _WriteFive($0C) 6: _WriteSix($0C) 7: _WriteSeven($0C) 8: _WriteEight($0C) 9: _WriteNine($0C) OTHER: _Pause(20) PUB _SetSecond if _counter2 == 9 _counter2 := 0 _SetThird else _counter2 := _counter2 + 1 _Blank($08) CASE _counter2 0: _WriteZero($08) 1: _WriteOne($08) 2: _WriteTwo($08) 3: _WriteThree($08) 4: _WriteFour($08) 5: _WriteFive($08) 6: _WriteSix($08) 7: _WriteSeven($08) 8: _WriteEight($08) 9: _WriteNine($08) OTHER: _Pause(20) PUB _SetThird if _counter3 == 9 _counter3 := 0 _SetFourth else _counter3 := _counter3 + 1 _Blank($04) CASE _counter3 0: _WriteZero($04) 1: _WriteOne($04) 2: _WriteTwo($04) 3: _WriteThree($04) 4: _WriteFour($04) 5: _WriteFive($04) 6: _WriteSix($04) 7: _WriteSeven($04) 8: _WriteEight($04) 9: _WriteNine($04) OTHER: _Pause(20) PUB _SetFourth if _counter4 == 9 _counter4 := 0 else _counter4 := _counter4 + 1 _Blank($00) CASE _counter4 0: _WriteZero($00) 1: _WriteOne($00) 2: _WriteTwo($00) 3: _WriteThree($00) 4: _WriteFour($00) 5: _WriteFive($00) 6: _WriteSix($00) 7: _WriteSeven($00) 8: _WriteEight($00) 9: _WriteNine($00) OTHER: _Pause(20) PUB SetZero(a) _WriteZero(a) _WriteZero(a+$04) _WriteZero(a+$08) _WriteZero(a+$0C) _WriteDecimal($23) _WriteZero(a+$11) _Pause(1000) PUB _Blank(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($20) _SetDDRAmaddr(a+$81) _WriteDDRAM($20) _SetDDRAmaddr(a+$82) _WriteDDRAM($20) _SetDDRAmaddr(a+$C0) _WriteDDRAM($20) _SetDDRAmaddr(a+$C1) _WriteDDRAM($20) _SetDDRAmaddr(a+$C2) _WriteDDRAM($20) _SetDDRAmaddr(a+$94) _WriteDDRAM($20) _SetDDRAmaddr(a+$95) _WriteDDRAM($20) _SetDDRAmaddr(a+$96) _WriteDDRAM($20) _SetDDRAmaddr(a+$D4) _WriteDDRAM($20) _SetDDRAmaddr(a+$D5) _WriteDDRAM($20) _SetDDRAmaddr(a+$D6) _WriteDDRAM($20) _ReadDDRAM($20) PUB _WriteZero(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($00) _SetDDRAmaddr(a+$C0) _WriteDDRAM($06) _SetDDRAmaddr(a+$94) _WriteDDRAM($06) _SetDDRAmaddr(a+$D4) _WriteDDRAM($04) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteOne(a) _SetDDRAmaddr(a+$81) _WriteDDRAM($02) _SetDDRAmaddr(a+$D5) _WriteDDRAM($07) _SetDDRAmaddr(a+$C1) _WriteDDRAM($06) _SetDDRAmaddr(a+$95) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteTwo(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($00) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$C2) _WriteDDRAM($07) _SetDDRAmaddr(a+$95) _WriteDDRAM($07) _SetDDRAmaddr(a+$94) '''' _WriteDDRAM($03) _SetDDRAmaddr(a+$D4) _WriteDDRAM($05) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$D6) _WriteDDRAM($05) _ReadDDRAM($07) PUB _WriteThree(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($00) _SetDDRAmaddr(a+$D4) _WriteDDRAM($04) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$C1) _WriteDDRAM($03) _SetDDRAmaddr(a+$95) _WriteDDRAM($01) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteFour(a) {_SetDDRAmaddr(a+$82) _WriteDDRAM($00) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _SetDDRAmaddr(a+$D6) _WriteDDRAM($05) _SetDDRAmaddr(a+$94) _WriteDDRAM($00) _SetDDRAmaddr(a+$C1) _WriteDDRAM($00) _SetDDRAmaddr(a+$95) _WriteDDRAM($03) _ReadDDRAM($07)} _SetDDRAmaddr(a+$80) _WriteDDRAM($0) _SetDDRAmaddr(a+$C0) _WriteDDRAM($06) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$95) _WriteDDRAM($01) _SetDDRAmaddr(a+$C1) _WriteDDRAM($03) _SetDDRAmaddr(a+$94) _WriteDDRAM($01) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteFive(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($0) _SetDDRAmaddr(a+$C0) _WriteDDRAM($06) _SetDDRAmaddr(a+$D4) _WriteDDRAM($04) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$C1) 'C1 _WriteDDRAM($03) _SetDDRAmaddr(a+$95) 'C1 _WriteDDRAM($01)'3 _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$82) _WriteDDRAM($05)'5 _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteSix(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($0) _SetDDRAmaddr(a+$C0) _WriteDDRAM($06) _SetDDRAmaddr(a+$94) _WriteDDRAM($06) _SetDDRAmaddr(a+$D4) _WriteDDRAM($04) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$C1) _WriteDDRAM($03) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteSeven(a) {_SetDDRAmaddr(a+$80) _WriteDDRAM($05) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$82) _WriteDDRAM($05) _SetDDRAmaddr(a+$C2) _WriteDDRAM($07) _SetDDRAmaddr(a+$95) _WriteDDRAM($06) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _ReadDDRAM($06)} _SetDDRAmaddr(a+$80) _WriteDDRAM($0) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteEight(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($0) _SetDDRAmaddr(a+$C0) _WriteDDRAM($06) _SetDDRAmaddr(a+$94) _WriteDDRAM($06) _SetDDRAmaddr(a+$D4) _WriteDDRAM($04) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$C1) _WriteDDRAM($03) _SetDDRAmaddr(a+$95) _WriteDDRAM($01) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteNine(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($0) _SetDDRAmaddr(a+$C0) _WriteDDRAM($06) _SetDDRAmaddr(a+$D4) _WriteDDRAM($04) _SetDDRAmaddr(a+$81) _WriteDDRAM($05) _SetDDRAmaddr(a+$D5) _WriteDDRAM($05) _SetDDRAmaddr(a+$C1) _WriteDDRAM($03) _SetDDRAmaddr(a+$95) _WriteDDRAM($01) _SetDDRAmaddr(a+$82) _WriteDDRAM($02) _SetDDRAmaddr(a+$D6) _WriteDDRAM($07) _SetDDRAmaddr(a+$C2) _WriteDDRAM($06) _SetDDRAmaddr(a+$96) _WriteDDRAM($06) _ReadDDRAM($06) PUB _WriteDecimal(a) _SetDDRAmaddr(a+$80) _WriteDDRAM($03) _SetDDRAmaddr(a+$80+$40) _WriteDDRAM($01) _ReadDDRAM($01) PUB _SetCGRAMaddr(a) outa[P10] := 0 'Set CGRAM ADRESS adrress P7..P0 (DDRAM address) waitcnt(Delay1 + cnt) ' outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P8] := 0 'DB6 RS outa[P9] := 0 'DB7 R/W outa[P7..P0] := a PUB _WriteCGRAM(a) outa[P10] := 0 'Write CGRAM adrress P7..P0 (CGRAM DATA) waitcnt(Delay1 + cnt) ' outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P8] := 1 'DB6 RS outa[P9] := 0 'DB7 R/W outa[P7..P0] := a PUB _SetDDRAmaddr(a) outa[P10] := 0 'Set DDRAM ADRESS adrress P7..P0 (DDRAM address) waitcnt(Delay1 + cnt) ' outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P8] := 0 'DB6 RS outa[P9] := 0 'DB7 R/W outa[P7..P0] := a PUB _WriteDDRAM(a) outa[P10] := 0 waitcnt(Delay1 + cnt) ' SET DDRAM FOR WRITE with address at P7...P0 (CGROM address) outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P8] := 1 'DB6 RS outa[P9] := 0 'DB7 R/W outa[P7..P0] := a PUB _ReadDDRAM(a) outa[P10] := 0 waitcnt(Delay1 + cnt) ' SET DDRAM FOR READ at adrress P7..P0 (DDRAM address) outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P8] := 1 'DB6 RS outa[P9] := 1 'DB7 R/W outa[P7..P0] := a PUB Clear waitcnt(Delay1 + cnt) outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P9..P0] := %0000000001 outa[P10] := 0 _Pause(100) {PUB DisplayOFF waitcnt(Delay1 + cnt) outa[P10] := 1 waitcnt(Delay2 + cnt) outa[P9..P0] := %0000001001 } outa[P10] := 0 PUB _Pause(msec)| _t _t := cnt repeat until (cnt - _t) / (clkfreq / 1000) > msec [/indent]