Shop OBEX P1 Docs P2 Docs Learn Events
Basic cog operation — Parallax Forums

Basic cog operation

fingeraefingerae Posts: 15
edited 2008-12-22 16:52 in Propeller 1
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)
···

Comments

  • BradCBradC Posts: 2,601
    edited 2008-12-22 16:38
    Easy.. You have not set the DIR register in the cog you are using to flash the LED.
    You need to put that in testcogs()

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cardinal Fang! Fetch the comfy chair.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-22 16:44
    1) For most simple programs, 20 to 50 stack levels should be enough. The requirements depend so much on the total depth of calls and the use of local variables that it's hard to estimate further without looking at the code in detail. Things like the floating point package and FullDuplexSerial actually use little stack space because the Spin routines are just interfaces to the assembly program(s) running in another cog.

    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.
  • fingeraefingerae Posts: 15
    edited 2008-12-22 16:52
    Thanks to you both. That helped a great deal. Any comments on the "clear screen" syntax?
Sign In or Register to comment.