Shop OBEX P1 Docs P2 Docs Learn Events
COGNEW help — Parallax Forums

COGNEW help

TCTC Posts: 1,019
edited 2015-02-06 20:19 in Propeller 1
Hello all,

I am making a simple 7-segment display driver. I have a running prototype, but now I want to put the display driver code in a new cog, and just update the buffer array. here is my working prototype code...
CON
        _clkmode = xtal1 + pll16x                                               
        _xinfreq = 6_000_000

CON 'PINS

  DIG0  =       0
  DIG1  =       1
  DIG2  =       2
  DIG3  =       3
  DIG4  =       4
  DIG5  =       5
  DIG6  =       6
  DIG7  =       7

  SEG_A =       8
  SEG_B =       9
  SEG_C =       10
  SEG_D =       11
  SEG_E =       12
  SEG_F =       13
  SEG_G =       14
  DP    =       15

  CLR   =       16
  CLK   =       17
         
VAR
  BYTE  BUFF[8]
  
PUB MAIN

  DIRA[CLR] := %1
  OUTA[CLR] := %1

  LOAD_BUFFER(0,2)
  LOAD_BUFFER(1,4)
  LOAD_BUFFER(2,1)
  LOAD_BUFFER(3,9)
  LOAD_BUFFER(4,10)
  LOAD_BUFFER(5,3)
  LOAD_BUFFER(6,8)
  LOAD_BUFFER(7,5)

  LOAD_DISPLAY

PUB LOAD_BUFFER(DIGIT_NUMBER, VALUE)

  BUFF[DIGIT_NUMBER] := VALUE    

PUB LOAD_DISPLAY | DIGIT

  DIRA[CLK] := %1
  OUTA[CLK] := %0
  
  DIRA[DIG0..DP] := %11111111_11111111
  
    REPEAT
      REPEAT DIGIT FROM 0 TO 7
       
        OUTA[DIG0..DIG7] := BYTE[@DIG + DIGIT]
        OUTA[SEG_A..DP]  := BYTE[@CHAR + BUFF[DIGIT]]
       
        OUTA[CLK] := %1
        OUTA[CLK] := %0

DAT

        CHAR  BYTE      %11111100  '0
              BYTE      %01100000  '1
              BYTE      %11011010  '2
              BYTE      %11110010  '3
              BYTE      %01100110  '4
              BYTE      %10110110  '5
              BYTE      %10111110  '6
              BYTE      %11100000  '7
              BYTE      %11111110  '8
              BYTE      %11110110  '9
              BYTE      %00000000  'BLANK

        DIG   BYTE      %10000000
              BYTE      %01000000
              BYTE      %00100000
              BYTE      %00010000
              BYTE      %00001000
              BYTE      %00000100
              BYTE      %00000010
              BYTE      %00000001        


Here is an attempt I did to make the driver code be in another cog. (I know the stack is large, it is just a first run)

CON
        _clkmode = xtal1 + pll16x                                               
        _xinfreq = 6_000_000

CON 'PINS

  DIG0  =       0
  DIG1  =       1
  DIG2  =       2
  DIG3  =       3
  DIG4  =       4
  DIG5  =       5
  DIG6  =       6
  DIG7  =       7

  SEG_A =       8
  SEG_B =       9
  SEG_C =       10
  SEG_D =       11
  SEG_E =       12
  SEG_F =       13
  SEG_G =       14
  DP    =       15

  CLR   =       16
  CLK   =       17
         
VAR
  BYTE  BUFF[8]
  BYTE  COG_ID

  LONG  DISPLAY_STACK[100]
  
PUB MAIN

  DIRA[CLR] := %1
  OUTA[CLR] := %1

  LOAD_BUFFER(0,2)
  LOAD_BUFFER(1,4)
  LOAD_BUFFER(2,1)
  LOAD_BUFFER(3,9)
  LOAD_BUFFER(4,10)
  LOAD_BUFFER(5,3)
  LOAD_BUFFER(6,8)
  LOAD_BUFFER(7,5)

  'LOAD_DISPLAY

  COG_ID := COGNEW(LOAD_DISPLAY(@BUFF, @DIG, @CHAR, DIG0, SEG_A, CLK), DISPLAY_STACK) 

PUB EXTRACT (VALUE) | DIGIT, DIVISOR

  DIVISOR := 10_000_000

  REPEAT DIGIT FROM 7 TO 0
    BYTE[BUFF][DIGIT] := VALUE / DIVISOR                        ' extract digit
    VALUE //= DIVISOR                                           ' remove digit from value
    DIVISOR /= 10                                               ' fix divisor for next digit
    

PUB LOAD_BUFFER(DIGIT_NUMBER, VALUE)

  BUFF[DIGIT_NUMBER] := VALUE    

PUB LOAD_DISPLAY(BUFF_ADDR, DIG_ADDR, CHAR_ADDR, DIG_PIN, SEG_PIN, CLK_PIN) | DIGIT

  DIRA[CLK_PIN] := %1
  OUTA[CLK_PIN] := %0
  
  DIRA[DIG_PIN..(DIG_PIN + 16)] := %11111111_11111111
  
    REPEAT
      REPEAT DIGIT FROM 0 TO 7
       
        OUTA[DIG_PIN..(DIG_PIN + 8)] := BYTE[DIG_ADDR + DIGIT]
        OUTA[SEG_PIN..(SEG_PIN + 8)]  := BYTE[CHAR_ADDR + BUFF_ADDR[DIGIT]]
       
        OUTA[CLK_PIN] := %1
        OUTA[CLK_PIN] := %0

DAT

        CHAR  BYTE      %11111100  '0
              BYTE      %01100000  '1
              BYTE      %11011010  '2
              BYTE      %11110010  '3
              BYTE      %01100110  '4
              BYTE      %10110110  '5
              BYTE      %10111110  '6
              BYTE      %11100000  '7
              BYTE      %11111110  '8
              BYTE      %11110110  '9
              BYTE      %00000000  'BLANK

        DIG   BYTE      %10000000
              BYTE      %01000000
              BYTE      %00100000
              BYTE      %00010000
              BYTE      %00001000
              BYTE      %00000100
              BYTE      %00000010
              BYTE      %00000001        


I know it has to be something simple, but I just cant see it. Does anyone have any ideas?

Thanks
TC

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-02-06 19:04
    In your cognew call, it should be @display_stack.

    Egad, man! Do you enter code with caps-lock on? Code is much easier to read with lower/mixed case.

    -Phil
  • TCTC Posts: 1,019
    edited 2015-02-06 19:12
    In your cognew call, it should be @display_stack.

    Egad, man! Do you enter code with caps-lock on? Code is much easier to read with lower/mixed case.

    -Phil

    Thank you Phil for the reply.

    I added @display_stack, and it still does not work.

    Sorry about the caps lock thing. I only use it to try out code. I have been known to put caps in places where they should not be, and I get lost looking for a problem. After I have a working idea. I then take my time to lay out the code better.
  • TCTC Posts: 1,019
    edited 2015-02-06 19:30
    I added "repeat" in the main method, and I now have something, but nothing understandable. Still trying to figure out what I am missing.

    I am only trying out the caps-lock thing. It has its ups and downs.
  • TCTC Posts: 1,019
    edited 2015-02-06 19:58
    Here is the updated code I have so far. Still trying to figure out what I am missing. ( and fixed the caps-lock)
    CON 'PINS
    
      Dig0  =       0
      Dig1  =       1
      Dig2  =       2
      Dig3  =       3
      Dig4  =       4
      Dig5  =       5
      Dig6  =       6
      Dig7  =       7
    
      Seg_A =       8
      Seg_B =       9
      Seg_C =       10
      Seg_D =       11
      Seg_E =       12
      Seg_F =       13
      Seg_G =       14
      DP    =       15
    
      clr   =       16
      clk   =       17
             
    VAR
      BYTE  buff[8]
      BYTE  cog_ID
    
      LONG  Display_stack[100]
      
    PUB main
    
      dira[clr] := %1
      outa[clr] := %1
    
      Load_Buffer(0,2)
      Load_Buffer(1,4)
      Load_Buffer(2,1)
      Load_Buffer(3,9)
      Load_Buffer(4,10)
      Load_Buffer(5,3)
      Load_Buffer(6,8)
      Load_Buffer(7,5)
    
      cog_ID := cognew(Load_Display(@buff), @Display_stack)
    
      REPEAT
    
    PUB Load_Buffer(Digit_Number, value)
    
      buff[Digit_Number] := value     
    
    PUB Load_Display(Buff_Addr) | digit
    
      dira[clk] := %1
      dira[clk] := %0
      
      dira[Dig0..DP] := %11111111_11111111
      
        REPEAT
          REPEAT digit FROM 0 TO 7
           
            outa[Dig0..Dig7] := BYTE[@dig + digit]
            outa[Seg_A..DP] := BYTE[@char + Buff_Addr[digit]]
           
            outa[clk] := %1
            outa[clk] := %0
    
    DAT
    
            char  BYTE      %11111100  '0
                  BYTE      %01100000  '1
                  BYTE      %11011010  '2
                  BYTE      %11110010  '3
                  BYTE      %01100110  '4
                  BYTE      %10110110  '5
                  BYTE      %10111110  '6
                  BYTE      %11100000  '7
                  BYTE      %11111110  '8
                  BYTE      %11110110  '9
                  BYTE      %00000000  'BLANK
    
            dig   BYTE      %10000000
                  BYTE      %01000000
                  BYTE      %00100000
                  BYTE      %00010000
                  BYTE      %00001000
                  BYTE      %00000100
                  BYTE      %00000010
                  BYTE      %00000001        
    

    Thanks
    TC
  • ozpropdevozpropdev Posts: 2,792
    edited 2015-02-06 20:15
    Try this
            outa[Seg_A..DP] := BYTE[@char + byte[Buff_Addr+digit]]
    
    
  • TCTC Posts: 1,019
    edited 2015-02-06 20:19
    ozpropdev wrote: »
    Try this
            outa[Seg_A..DP] := BYTE[@char + byte[Buff_Addr+digit]]
    
    

    That did it. Thank you so much. Now to understand what I was missing.
Sign In or Register to comment.