Shop OBEX P1 Docs P2 Docs Learn Events
multiple cogs and simple serial ... ??? — Parallax Forums

multiple cogs and simple serial ... ???

Brian RileyBrian Riley Posts: 626
edited 2007-01-30 01:25 in Propeller 1
I took a copy of Jon Williams' "Serial_LCD" and used it to create a driver object (K107_LCD.spin - see below attachment) for my K107 LCD Controller board using the Anderson chip. It works just fine using, additionally the "simple_serial" and "simple_numbers" objects.

I then created a K107_LCD_Demo3.spin. In it I created a generalized display demo, which instantiated a K107_LCD obejct , initialized for port, baudrate, display geometry, etc and then runs it.. As a simple "call" it works fine. I have three displays I am playing with now a 2x16 and a4x20 backlits displays and a 2x24 non-backlit display. Any of them by themselves works. If I instatiate 3 different objects and make three copies of the routines one using each object that works for all three too.

However my goal is to use the PRC baord to drive several of these displays simultaneously as a demo. I wanted to make a generalized routine, pass parameters and start, in this case each of three in a separate cog. I hav attaced the whole code file below (K107_LCD_Demo3.spin) but here is a snippet ...

The code as shown produces no output to the displays. HOWEVER, if I comment out any two of the COGNEW calls the one that is there works like a champ. I know I am missing something obvious here. Can someone please put me out of my misery and tell me what it is that I missed?

PUB main

   waitcnt(clkfreq + cnt)
                                                                                    
   cognew(displayLCD(0, 9600, 216, 9, $10, 0), @stack1)

   cognew(displayLCD(2, 9600, 420, 9, -$10, $80), @stack2)

   cognew(displayLCD(4, 9600, 224, 0, 0, 0), @stack3)
  

PRI displayLCD ( pin, baud, geometry, iCount, iStep, iStart) | i, idx, rpt, ccnt

  if lcd.start(pin, baud, geometry)
    lcd.cursor(0)                                      ' cursor off
    lcd.intoBigNum(3)
    lcd.outofBigNum
    lcd.cls

  ..... details extraneous to the issue deleted ....

        repeat idx from $40 to ccnt                ' loop to display 15 chars 1ms pacing                      
          lcd.putc (idx)                                                                                                                                  
          waitcnt(clkfreq / 1000 + cnt)                      ' pad with 1 ms                                    
                                                                                                                  
        waitcnt(clkfreq + cnt)                                                                                  
        i += iStep
                                                                    
      waitcnt(2*clkfreq + cnt)
   




thanks ...

p.s. Chip, I LOVE SPIN, the more I work with it, the more other languages annoy me! Its simple elegance is incredible. It lets me get down to the business of producing working code without having to deal with the arcane minutia prevalent in so many languages, even PBASIC comes off looking like Perl in comparison! <grin>

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
cheers ... brian riley, n1bq, underhill center, vermont
See the K107 Serial LCD Controller at
www.wulfden.org/k107/

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-29 20:10
    Part of the problem is that you've got only one copy of the LCD driver that you're trying to use for 3 separate things. When the second cog starts, it reinitializes the LCD/Serial driver for the new pin and all 3 cogs are trying to access the same (last) serial pin. Only one of them can do it.

    Easiest thing to do is to declare an array of LCD drivers like: 'OBJ lcd : "K107_LCD"' and in your displayLCD routine, use an additional parameter to specify which LCD driver copy to use. Only the VARs are duplicated for each array element. Only one copy of the methods is used. There should also be duplicates of any VARs used by objects referenced by "K107_LCD".
  • Brian RileyBrian Riley Posts: 626
    edited 2007-01-29 20:36
    Mike Green said...
    Part of the problem is that you've got only one copy of the LCD driver that you're trying to use for 3 separate things. When the second cog starts, it reinitializes the LCD/Serial driver for the new pin and all 3 cogs are trying to access the same (last) serial pin. Only one of them can do it.

    Easiest thing to do is to declare an array of LCD drivers like: 'OBJ lcd : "K107_LCD"' and in your displayLCD routine, use an additional parameter to specify which LCD driver copy to use. Only the VARs are duplicated for each array element. Only one copy of the methods is used. There should also be duplicates of any VARs used by objects referenced by "K107_LCD".

    I specifying different pins for each call, I suspected as much about the objects. B

    So ... somethiing like this

    
    OBJ
    
         lcd : "K107_LCD" ' I have square brackets and a 4 to the right of the 'lcd' but the forum software won't print it
    
    PUB main
    
    
       cognew(displayLCD(0,0,9600,216,9 $10,0), @stack0)
    
       cognew(displayLCD(1,2,9600,420,9 -$10,$80), @stack1)
    
       cognew(displayLCD(2,4,9600,224,0 0,0), @stack2)
    
    
    PRI displayLCD ( objno, pin, baud, geometry, iCount, iStep, iStart) | i, idx, rpt, ccnt
    
      if lcd[noparse][[/noparse]objno].start(pin, baud, geometry)
        lcd[noparse][[/noparse]objno].cursor(0)                                      ' cursor off
        lcd[noparse][[/noparse]objno].intoBigNum(3)
        lcd[noparse][[/noparse]objno].outofBigNum
    
     ...
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    See the K107 Serial LCD Controller at
    www.wulfden.org/k107/
  • Brian RileyBrian Riley Posts: 626
    edited 2007-01-30 01:25
    OK ... that works just fine ... thanks Mike ... I have re-uploaded the corrected demo code and K107_LCD object in case anyone wants to take a look at it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    See the K107 Serial LCD Controller at
    www.wulfden.org/k107/
Sign In or Register to comment.