Shop OBEX P1 Docs P2 Docs Learn Events
parallel LCD and 2 cogs — Parallax Forums

parallel LCD and 2 cogs

wolphiwolphi Posts: 8
edited 2008-05-04 01:48 in Propeller 1
I just started programming the propeller chip and I run into a problem which I can't solve.
I am displaying text or numbers on my 8bit 16x2 display using the LCD driver from Simon Ampleman which I found in the Object exchange. Everything works fine until I stated playing with the cogs.

I am using the following 2 files:
' test.spin
OBJ

LCD : "LCD_16x2_8bit"
t : "test1"

PUB main | a
LCD.START
repeat a from 99 to 1
LCD.MOVE(5,1)
LCD.DEC(a)
t.test123
'test123.spin
VAR
LONG stack[noparse][[/noparse]90]
OBJ
LCD : "LCD_16X2_8BIT"

PUB test123 |a
coginit(2,print,@stack) 'start new cog for display
repeat 'count endless
PUB print | a ' count from 1 to 10000 and display on LCD
LCD.START
repeat a from 1 to 10000
LCD.MOVE(5,1)
LCD.DEC(a)

When I start test.spin the propeller counts from 99 back to 1 and it shows the number on the LCD. Then I call the method test123 which starts a new cog and runs the method print. At this point the LCD shows weird symbols. When I call method print without starting a new cog the display shows the correct number.

VAR
LONG stack[noparse][[/noparse]90]
OBJ
LCD : "LCD_16X2_8BIT"

PUB test123 |a
print

PUB print | a ' count from 1 to 10000 and display on LCD
LCD.START
repeat a from 1 to 10000
LCD.MOVE(5,1)
LCD.DEC(a)

I need to run the LCD in a different cog because I need to display a variable at the same time when another cog is doing something else.
Any help would be appreciated !!

Thanks,

Wolfgang

Comments

  • SeariderSearider Posts: 290
    edited 2008-05-03 15:19
    I have not looked at the LCD_16X2_Bit driver but I am using the 4x20 LCD and a driver from Object exchage so our experience is likely similar.· It looks to me that you have two different cogs trying to write to the LCD at the same time. This is likely corupting the output stream from the Propeller to the LCD module. I solved this problem by dedicating a COG to LCD comunications. It is in a·loop and repeatedly displays the value of several variables. The variables being loaded and refreshed by other Cogs that have something to display. There are, of course, other ways to do this but I think the concept of a Display COG is key or failing that, some sort of semifore so that COGs take turns writing to the LCD.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Searider
  • wolphiwolphi Posts: 8
    edited 2008-05-03 15:48
    Thanks for your fast replay. I think you are right. The first cog does still something related to the LCD when I start the second cog.· I would like to display a menu on the LCD·at the beginning where the user can choose a function.·After the user selected a function it will·start a new cog to display variables from other methods in the same spin file.When the function is finished I would like to go back to the menu.

    When I call the START method·from LCD driver in the second cog the LCD is getting inizialized and the first cog has finshed sending data to the display. I think I am missing something but what?
  • simonlsimonl Posts: 866
    edited 2008-05-03 16:31
    @wolphi: I've not used that object, but if there's a 'stop' method it might be worth calling LCD.stop just before you call t.test123?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • wolphiwolphi Posts: 8
    edited 2008-05-03 17:56
    Well there is no stop method in the driver. I can maybe write one but how? There is a bit which I can set on the display controller·to switch the display off but I don't think it resets the display contoller.·Well I guess ·I use your way and use one cog for the display. There more programming involved for that but a least it works. I·wasted already 2 days on this problem.
  • SapiehaSapieha Posts: 2,964
    edited 2008-05-03 19:37
    Hi All.

    If it is not Stop.
    It is not ned to start it 2 times.

    Only Call its funktions in program

    [noparse][[/noparse]code]

    ·· PUB test123 |a
    ··· coginit(2,print,@stack) 'start new cog for display
    ··· repeat 'count endless
    ··· PUB print | a ' count from 1 to 10000 and display on LCD
    ··· LCD.START ................................................................... Repeat starts ... ned only one time
    ··· repeat a from 1 to 10000
    ·· LCD.MOVE(5,1)
    ·· LCD.DEC(a)


    [noparse][[/noparse]/code]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha

    Post Edited (Sapieha) : 5/3/2008 7:49:21 PM GMT
  • wolphiwolphi Posts: 8
    edited 2008-05-03 20:33
    Thanks Sapieha for your reply. If I don't call the LCD.START in my second cog the LCD stays blank
  • SapiehaSapieha Posts: 2,964
    edited 2008-05-03 22:13
    Hi wolphi.

    But

    
       PUB test123 |a
        coginit(2,print,@stack) 'start new cog for display
        LCD.START ........................ MOVE IT........................................... Repeat starts ... ned only one time 
    
       repeat 'count endless
        PUB print | a ' count from 1 to 10000 and display on LCD
    
        repeat a from 1 to 10000 
       LCD.MOVE(5,1)
       LCD.DEC(a)
    
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.

    Sapieha
  • wolphiwolphi Posts: 8
    edited 2008-05-04 01:48
    Problem solved.
    After lots of coffee I solved the problem. Its is very simple. When I used LCD.START all the DB0 to DB10 are set to 1. When I try to display something with the second cog DB0 to DB10 are still used by the first cog and only some weird character will appear on the LCD
    Solution: I added a function STOP into the driver (thanks Sapieha) which sets all the pins related to the display to 0. Before I call the second cog to display something I call the method STOP in my first cog and everything works fine.
Sign In or Register to comment.