Shop OBEX P1 Docs P2 Docs Learn Events
Need help with cogs and stack assignment — Parallax Forums

Need help with cogs and stack assignment

eagletalontimeagletalontim Posts: 1,399
edited 2012-01-14 11:53 in Propeller 1
I guess people are scared to post in my other topic, but I need to get something working as soon as possible so I can test it out before it gets dark if at all possible. What I am attempting to do is start a new cog to update my LCD display while also running the main loop.

Here is a basic version of what I am doing :

[PHP]
VAR
LONG LCDstack[15]
BYTE gear
LONG rpm

OBJ
lcd : "Serial_Lcd"
getrpm : "jm_freqin"
num : "simple_numbers"

PUB Main
rpm := 0
gear := 1
getrpm.init(15)
lcd.init(8, 9600, 2)
lcd.displayOn
lcd.backLight(false)
lcd.gotoxy(0,0)
lcd.str(string("Testing Version "))
waitcnt(200_000_000 + cnt)
lcd.cls
lcd.str(string("Gear: "))
lcd.gotoxy(0,1)
lcd.str(string("RPM : "))
gear := 1

cognew(LCDupdate, @LCDstack)

shiftgear(gear)


repeat
rpm := getrpm.freq * 3
if ina[upbutton] == 1
gear++
gear := shiftgear(gear)
if ina[downbutton] == 1
gear--
gear := shiftgear(gear)
repeat while ina[downbutton] == 1 or ina[upbutton] == 1
waitcnt(3_000_000 + cnt)
waitcnt(10_000_000 + cnt)

PUB LCDupdate
repeat
lcd.gotoxy(5,0)
lcd.str(num.dec(gear))
lcd.str(string("um"))
lcd.gotoxy(5,1)
lcd.str(num.dec(rpm))
waitcnt(clkfreq / 1000 + cnt)

PUB shiftgear(tmp)
if tmp > 4
tmp := 4
if tmp < 1
tmp := 1

dira[solenoida]~~
dira[solenoidb]~~
outa[16..23]~
dira[16..23]~~

if tmp == 1
outa[solenoida] := 1
outa[solenoidb] := 1
if tmp == 2
outa[solenoida] := 0
outa[solenoidb] := 1
if tmp == 3
outa[solenoida] := 0
outa[solenoidb] := 0
if tmp == 4
outa[solenoida] := 1
outa[solenoidb] := 0
outa[16..23] := numbers[tmp]
return tmp[/PHP]

For some reason if I start the program without nulling out the cognew command, it starts in first gear, but as soon as I hit a button, it goes to 4th gear according to the 7 segment LED display. If I null it out, it works fine. Also, the LCD does not get updated as needed. Can someone help me get this fixed? The LCD only shows Gear: and RPM: Nothing else shows on the screen. It is like the LCDupdate is not working at all.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 11:20
    15 longs is a bit on the small size for a stack. I usually use 100 when first starting, just to make sure the stack size isn't a problem. I adjust it lower after I know things are working correctly.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2012-01-14 11:24
    Just updated that and it is still doing the same thing :( The LCD is not being updated at all by the LCDupdate function. Am I missing something simple?
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-14 11:33
    Simple_LCD is using Simple_Serial. The problem here is, that Simple_Serial is NOT starting a PASM-driver in another COG for driving the I/O-pins. Simple_Serial really runs completely in the COG which calls the function.
    In your case you called init in COG0 and used it for some output.
    Then you call cognew and want to use the display from COG1. But here you did not initialize the LCD which leaves the I/O pins in input-mode. No transfer possible.

    So, I'd change the code to do the whole LCD-stuff in your LCDupdate-function.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 11:37
    This is just the type of thing that gave me the most trouble when starting to use the Prop. I've since made it a habit of always starting drivers and setting IO pins from within the cog using them.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2012-01-14 11:47
    Ok, I think that got it :) Thank you soooo much! One more quick question though. Does the rpm variable update as a global variable which can be read in the main loop?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-01-14 11:53
    Ok, I think that got it :) Thank you soooo much! One more quick question though. Does the rpm variable update as a global variable which can be read in the main loop?

    Yes, it looks like the main loop updates rpm (a global variable) so the LCD should be displaying the updated value with each loop in the display cog.
Sign In or Register to comment.