Basic cog operation
fingerae
Posts: 15
I have a few questions about cogs.· For the StackPointer, what are some reasonable size values for PUB's such as 0831 input, a few floating point computations, or Parallax Serial Terminal output?· i.e. values for x for the code:·
VAR
· long Stack[noparse][[/noparse]x]
· cognew(PUB,@Stack)
What are some practical upper limits for x?
For the following code, everything seems to work properly except that the LED (PUB testcogs) does not light.· If testcogs is·referenced in·Cogtest, the LED lights as directed.· The number of cogs is not exceeded.· What am I doing incorrectly?· And, is this the most appropriate syntax for a "clear screen" command for the Parallax Serial Terminal?· Is there a reference for these types of Parallax Serial Terminal commands?
{{Cogtest.spin
}}
CON
· _clkmode = xtal1 + pll16x·· ' The code works at any frequency, but the serial line requires the crystal
· _xinfreq = 5_000_000·······
· 'Pin defenitions
· Mouse_CLK_PIN············ = 11········ 'Mouse clock pin for rotation sensing
· Mouse_Data_PIN··········· = 12········ 'Mouse data pin for rotation sensing
· PIN······················ = 15········ 'Tool heater
· RX_PIN··················· = 31········ 'Serial receive pin
· TX_PIN··················· = 30········ 'Serial transmit pin
· BAUD_RATE················ = 19200····· 'Serial baud rate
VAR
· long encoder, X_Position, cogvar[noparse][[/noparse]51]
· long temp1, cogvars[noparse][[/noparse]9], cog
OBJ
··· SER··· : "FullDuplexSerial"··· ' Object from the standard Propeller Tool library
··· MOUSE· : "Mouse"·············· ' Object from the standard Propeller Tool library
··· MATH·· : "Float32Full"········ ' Decimal math
··· PRINTFLOAT: "FloatString"·····
PUB Cogtest
· DIRA[noparse][[/noparse]PIN]~~································ 'LED
· SER.start(RX_PIN, TX_PIN, 0, BAUD_RATE)·············· 'Connect to serial line to display data
· MATH.start··········································· 'Initializes pin directions
· MOUSE.start(Mouse_Data_PIN,Mouse_CLK_PIN)············ 'Starts mouse driver on a new cog
· cognew(testcog, @cogvar)
· cog:=cognew(testcogs, @cogvars)
·
· repeat······
··· waitcnt(200000000 + cnt)····························· 'Wait 5000000 clock ticks
··· SER.tx($00)········································ 'Clear the screen
··· encoder := MOUSE.abs_x····························· 'Gets the encoder location
··· SER.str(string("Encoder value = "))················ 'Display string··
··· SER.dec(encoder)··································· 'Display decimal
··· SER.str(string($0D))······························· 'Display carriage return
··· SER.str(string("Cog value = "))···················· 'Display string··
··· SER.dec(cog)······································· 'Display decimal
··· SER.str(string($0D))······························· 'Display carriage return
···
· return X_Position
PUB testcog
· repeat
··· temp1:=MATH.FAdd(5.2,7.6)
··· SER.str(PRINTFLOAT.FloatToString(temp1)) 'Display temp1 as a decimal (floating point) number
··· SER.str(string($0D))···················
··· waitcnt(50000000 + cnt)
···
PUB testcogs
· repeat
··· OUTA[noparse][[/noparse]PIN]~~
··· waitcnt(500000000 + cnt)
··· OUTA[noparse][[/noparse]PIN]~
··· waitcnt(500000000 + cnt)
···
VAR
· long Stack[noparse][[/noparse]x]
· cognew(PUB,@Stack)
What are some practical upper limits for x?
For the following code, everything seems to work properly except that the LED (PUB testcogs) does not light.· If testcogs is·referenced in·Cogtest, the LED lights as directed.· The number of cogs is not exceeded.· What am I doing incorrectly?· And, is this the most appropriate syntax for a "clear screen" command for the Parallax Serial Terminal?· Is there a reference for these types of Parallax Serial Terminal commands?
{{Cogtest.spin
}}
CON
· _clkmode = xtal1 + pll16x·· ' The code works at any frequency, but the serial line requires the crystal
· _xinfreq = 5_000_000·······
· 'Pin defenitions
· Mouse_CLK_PIN············ = 11········ 'Mouse clock pin for rotation sensing
· Mouse_Data_PIN··········· = 12········ 'Mouse data pin for rotation sensing
· PIN······················ = 15········ 'Tool heater
· RX_PIN··················· = 31········ 'Serial receive pin
· TX_PIN··················· = 30········ 'Serial transmit pin
· BAUD_RATE················ = 19200····· 'Serial baud rate
VAR
· long encoder, X_Position, cogvar[noparse][[/noparse]51]
· long temp1, cogvars[noparse][[/noparse]9], cog
OBJ
··· SER··· : "FullDuplexSerial"··· ' Object from the standard Propeller Tool library
··· MOUSE· : "Mouse"·············· ' Object from the standard Propeller Tool library
··· MATH·· : "Float32Full"········ ' Decimal math
··· PRINTFLOAT: "FloatString"·····
PUB Cogtest
· DIRA[noparse][[/noparse]PIN]~~································ 'LED
· SER.start(RX_PIN, TX_PIN, 0, BAUD_RATE)·············· 'Connect to serial line to display data
· MATH.start··········································· 'Initializes pin directions
· MOUSE.start(Mouse_Data_PIN,Mouse_CLK_PIN)············ 'Starts mouse driver on a new cog
· cognew(testcog, @cogvar)
· cog:=cognew(testcogs, @cogvars)
·
· repeat······
··· waitcnt(200000000 + cnt)····························· 'Wait 5000000 clock ticks
··· SER.tx($00)········································ 'Clear the screen
··· encoder := MOUSE.abs_x····························· 'Gets the encoder location
··· SER.str(string("Encoder value = "))················ 'Display string··
··· SER.dec(encoder)··································· 'Display decimal
··· SER.str(string($0D))······························· 'Display carriage return
··· SER.str(string("Cog value = "))···················· 'Display string··
··· SER.dec(cog)······································· 'Display decimal
··· SER.str(string($0D))······························· 'Display carriage return
···
· return X_Position
PUB testcog
· repeat
··· temp1:=MATH.FAdd(5.2,7.6)
··· SER.str(PRINTFLOAT.FloatToString(temp1)) 'Display temp1 as a decimal (floating point) number
··· SER.str(string($0D))···················
··· waitcnt(50000000 + cnt)
···
PUB testcogs
· repeat
··· OUTA[noparse][[/noparse]PIN]~~
··· waitcnt(500000000 + cnt)
··· OUTA[noparse][[/noparse]PIN]~
··· waitcnt(500000000 + cnt)
···
Comments
You need to put that in testcogs()
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cardinal Fang! Fetch the comfy chair.
2) You can't use FullDuplexSerial from two different cogs at the same time. You could use the LOCKxx statements to make sure only one cog calls FullDuplexSerial at a time. Read the sections in the Propeller Manual on these statements for examples.