Shop OBEX P1 Docs P2 Docs Learn Events
Having trouble with the VGA Text driver — Parallax Forums

Having trouble with the VGA Text driver

CopperCopper Posts: 48
edited 2012-07-15 17:05 in Propeller 1
This is only my second post, and while I know quite a bit more than I did when I made my first post, I'd still say I'm "new to programming." Just FYI.

Currently I'm working on writing a simple "debug terminal" for some synth code I found, using the VGA_Text driver that came with the Propeller Tool v1.3. Unfortunately, I'm having some trouble configuring the counter modules on my various cogs.

IMAG0099.jpg

this (above) is what I get with the "synth cog" commented out.

IMAG0100.jpg

and this is what I get with the "synth cog" left in.

I imagine there is something more I need to be doing to correctly configure my counter modules. But my "potentiometer cog" works fine (with two counters configured for pos detection on an RC Decay circuit).
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000




OBJ


  text : "vga_text"
  
VAR


  long stack[20]


DAT


  pot1        long 0
  pot2        long 0
  frequency   long 0
  cogA        byte 0
  cogB        byte 0


PUB Main 


  cogA:= cognew(get_pot, @stack[0])
  cogB:= cognew(re_synth, @stack[10])


  
  text.start(16)


  repeat
    text.str(string(13, "   Debug...", 13, 13, "    pot1==", 13, "     Bin=="))
    text.bin(pot1,16)
    text.str(string(13, "     Dec=="))
    text.dec(pot1)
    text.str(string(13, 13, "    pot2==", 13, "     Bin=="))
    text.bin(pot2,16)
    text.str(string(13, "     Dec=="))
    text.dec(pot2)
    text.str(string(13, 13, "    frequency=="))
    text.dec(frequency)
    text.str(string(1))
    
                                                        
    
PUB re_synth | x
   
  repeat
    x:=0
    x|=(pot1>>8 + pot2>>3)
    


    frequency:=x
    Synth("A", 4, x)               'Synth({Counter"A" or Counter"B"},Pin, Freq)
        
PUB Synth(CTR_AB, Pin, Freq) | s, d, ctr, frq


  Freq := Freq #> 0 <# 128_000_000     'limit frequency range
  
  if Freq < 500_000                    'if 0 to 499_999 Hz,
    ctr := constant(100 << 26)      'set NCO mode ( desired mode 100 shifted 26bits left into ctr-mode register [30..26] )
    s := 1                             '..shift = 1
  else                                 'if 500_000 to 128_000_000 Hz,
    ctr := constant(010 << 26)      '..set PLL mode
    d := >|((Freq - 1) / 1_000_000)    'determine PLLDIV
    s := 4 - d                         'determine shift
    ctr |= d << 23                     'set PLLDIV
    
  frq := frqfraction(Freq, CLKFREQ, s)    'Compute FRQA/FRQB value
  ctr |= Pin                           'set PINA to complete CTRA/CTRB value


  if CTR_AB == "A"
     CTRA := ctr                        'set CTRA
     FRQA := frq                        'set FRQA                   
     DIRA[Pin]~~                        'make pin output
     
  if CTR_AB == "B"
     CTRB := ctr                        'set CTRB
     FRQB := frq                        'set FRQB                   
     DIRA[Pin]~~                        'make pin output


PUB frqfraction(a, b, shift) : f


  if shift > 0                         'if shift, pre-shift a or b left
    a <<= shift                        'to maintain significant bits while 
  if shift < 0                         'insuring proper result
    b <<= -shift
 
  repeat 32                            'perform long division of a/b
    f <<= 1
    if a => b
      a -= b
      f++           
    a <<= 1


pub get_pot


  ctra[30..26] := 000                     ' Set mode to "POS detector"
  ctra[5..0] := 3                           ' Set APIN to 17 (P17)
  frqa := 1                                  ' Increment phsa by 1 for each clock tick


  ctrb[30..26] := 000                     ' Set mode to "POS detector"
  ctrb[5..0] := 2                           ' Set APIN to 16 (P16)
  frqb := 1                                  ' Increment phsa by 1 for each clock tick


  repeat
    ' Charge RC circuit.


    dira[3] := outa[3] := 1               ' Set pin to output-high
    waitcnt(clkfreq/50_000 + cnt)           ' Wait for circuit to charge
      
    ' Start RC decay measurement.  It's automatic after this...


    phsa~                                   ' Clear the phsa register
    dira[3]~                               ' Pin to input stops charging circuit
     
    waitcnt(clkfreq/50+cnt)                 'Wait for counter module to measure decay automatically
          
    pot1 := (phsa - 624) #> 0


  
    dira[2] := outa[2] := 1               ' Set pin to output-high
    waitcnt(clkfreq/50_000 + cnt)           ' Wait for circuit to charge
      
    ' Start RC decay measurement.  It's automatic after this...


    phsb~                                   ' Clear the phsa register
    dira[2]~                               ' Pin to input stops charging circuit
     
    waitcnt(clkfreq/50+cnt)                 'Wait for counter module to measure decay automatically
          
    pot2 := (phsb - 624) #> 0
Thanks for any suggestions.
1024 x 577 - 46K
1024 x 577 - 105K

Comments

  • RaymanRayman Posts: 14,826
    edited 2012-07-14 12:37
    10 is not enough long for the stack (maybe).

    Usually, I give at least 100...
  • kuronekokuroneko Posts: 3,623
    edited 2012-07-14 20:00
    Interesting side effects! But yes, according to the Stack Length object the re_synth task needs at least 23 longs for its stack (and in this case uses some of the VGA_Text essentials as well, NG). Simply increase the stack as Rayman suggested, I usually get away with 32.
  • CopperCopper Posts: 48
    edited 2012-07-15 08:49
    Thank you both, that essentially fixed it. The display now displays as expected, and the synth code works too; curiously though, the DEC values never return to zero. They bottom out, one around 2000, and the other just over 1000, but the BIN values do return to 0 and the rest of the code works as expected.
    hmmm...
  • kuronekokuroneko Posts: 3,623
    edited 2012-07-15 17:05
    Copper wrote: »
    They bottom out, one around 2000, and the other just over 1000, but the BIN values do return to 0 and the rest of the code works as expected.
    hmmm...
    That looks like a display artefact (most likely explanation). The binary display is fixed to 16 characters (fixed width), decimals are printed with whatever width is required. IOW, if you printed say 1000 followed by 2 you'd actually see 2000. As a quick fix you could simply print a number of spaces after each decimal output (pot1/pot2/frequency), e.g.
    text.str(string(13, "     Dec=="))
        text.dec(pot2)
        [COLOR="orange"]text.str(@tail)[/COLOR]
    
        text.str(string(13, 13, "    frequency=="))
        text.dec(frequency)
        [COLOR="orange"]text.str(@tail)[/COLOR]
    
        text.out(1)
        
    DAT                                                     
    
    [COLOR="orange"]tail    byte    32[10], 0[/COLOR]    ' ten space characters + string terminator
    
Sign In or Register to comment.