Shop OBEX P1 Docs P2 Docs Learn Events
Graphics problem - see bottom of thread. — Parallax Forums

Graphics problem - see bottom of thread.

computer guycomputer guy Posts: 1,113
edited 2008-10-06 07:30 in General Discussion
Hi there everyone,


I was designing a program that involved reading a txt file from an SD card when weird stuff started to happen.

To test my theory that it was the fsrw object that was causing it I copied the line
obj
  sdfat : "fsrw"




to graphics_demo.spin

All of a sudden the picture displayed on the tv had random coloured pixels.

It would appear that fsrw is causing memory to become corrupt.

Is there a fix for this or something I need to change?

I am running my main code at
       _clkmode        = xtal1 + pll16x
        _xinfreq        = 6_000_000



But it shouldn't make any difference right?



Thank you smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

Guitar Hero controller using the prop (WIP) --> HERE

Post Edited (computer guy) : 9/22/2008 12:56:15 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-17 22:00
    Remember the discussion about using system clock's outside of spec? The Propeller is specified for system clocks up to 80MHz. There's good test data in the datasheet on what happens above 80MHz. Some Propeller chips will work fine, some will not. It partially depends on the power supply voltage and the operating temperature. As the chip gets hotter, it tends to quit working. As the power supply voltage drops below 3.3V, it tends to quit working. I suggest you change the clock mode setting to PLL8X or, if possible, change the crystal to a 5MHz one and try again. It should behave better.
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-17 22:15
    Thank you Mike. smile.gif

    Changing the clock mode setting to PLL8X has reduced the amount of random pixels.
    Maybe I need to hunt down a 5MHz crystal.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • tpw_mantpw_man Posts: 276
    edited 2008-09-19 01:47
    It appears in the sdipiqasm driver that the clock frequency is hard coded to 80MHz

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 01:59
    tpw_man,

    Is there a way to change this?
    I am testing my code on my Hybrid Development Board and really don't want to have to change the crystal back and forth.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • tpw_mantpw_man Posts: 276
    edited 2008-09-19 02:01
    I have no idea, sorry. I just remembered that it had some random constant with the clock freq in it. You might want to try changing that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
  • Harrison.Harrison. Posts: 484
    edited 2008-09-19 02:32
    I think 'clockfreq' is only used for the 1-second I/O timeout. It just means your timeout will be a shorter since you are running at 96MHZ instead of 80MHZ. I doubt it is the source of your problem.

    If you really want to correct the clockfreq timeout then put something like 'clockfreq := clkfreq' in the sdspi start method (make sure you put it in BEFORE the cognew).

    What TV driver are you using? You might be running into your TV driver's screen buffer space (maybe you are using too much stack or something).
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 02:38
    Harrison,

    I am using the default graphics.spin that comes with the propeller tool.

    In my test code I have.

    _stack = ($2000 + $2000) >> 2 'accomodate bitmap buffers

    In the graphics example it is.

    _stack = ($3000 + $3000) >> 2 'accomodate bitmap buffers

    But that was tacking up to many longs so I reduced it.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-19 03:57
    Reducing _stack doesn't reduce the amount of space actually used by the driver. _stack is just a tool for the compiler to check to make sure there's enough room after the program for the amount of space you specify. You've just specified a smaller requirement (without actually reducing the requirement). As a result, when your program's stack area grows enough, the graphics driver scribbles all over part of it. No wonder your program stops working.

    The graphics driver uses double buffering to avoid blinking when the graphics are changing. You'll have to turn off the double buffering to actually reduce the amount of memory the graphics driver uses.
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 04:00
    I have managed to remove some longs that where not needed and have reduced the affected area substantially.
    This TV and graphic stuff is new to me.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 04:08
    Mike,

    Perhaps I can take a few mins out of your time.

    I am wanting to simply draw 5 ovals on the screen, next to each other.

    Green, Red, Yellow, Blue, Orange.

    What code would I need to:

    1. Init colors
    2. Init tile screen
    3. Draw these ovals.



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-19 04:52
    For #1 and #2, I'd just take the graphics_demo.spin program that comes with the Propeller Tool, strip out the "init bouncing lines" portion and any mouse references, remove the "start mouse" code, leave in the "clear bitmap", and strip everything from "draw spinning triangles" to "draw incrementing digit". You won't need "increment counter that makes everything change". Instead of that, you want 5 calls to a method like

    PRI drawEllipse(theColor, centerX, centerY, semiMajor, semiMinor, numberPts)

    This would call the gr.plot routine to actually draw the points in theColor. See en.wikipedia.org/wiki/Ellipse for an algorithm.

    You could either use gr.line to draw line segments or just use a high numberPts value. If you want a solid oval, you could call gr.fill or build your own ellipse fill routine using line drawing across the ellipse.
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 04:57
    I have found that drawing an ellipse (or close to) can be done using:
          gr.width(15)
          gr.box(-110, 5, 20, 20)
    
    



    However I cant get it to set the color.
    The color code looks complex and I don't understand it.


    You start by setting color (0 to 63) to different colors. ( I would assume 64 different colors )

    However gr.color(color) Only accepts 0 to 4.

    This really doesn't make sense to me.

    I am using the graphics driver to show a proof of concept before I have the actual hardware.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE

    Post Edited (computer guy) : 9/19/2008 5:10:44 AM GMT

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-19 05:31
    Graphics pixels have only 4 choices of color. These are chosen from a palette, in this case, of 64 color sets (of 4 colors each) that are specified on a tile by tile basis (usually 16 wide by 32 high). If you align the ovals to a 16 x 32 boundary, you should be able to change the palette entry being used for that oval.

    I'm sorry, it's been so long since I've used the graphics routines, that I have to look things up. I know the principles, but not all the details.

    My preference is to use one of the VGA tiled text drivers (depending on the resolution you want to use) that Chip wrote after all the other video drivers. They allow you to set up localized areas of the screen for graphics that you run with the graphics routines, but only those limited areas require a pixel buffer and you can use different colors for each area. The rest of the screen is used for text-only.

    Have a look at this. Chip wrote it as part of the series of tile-based drivers, but I don't think he put it in the Object Exchange along with the others.
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 05:48
    So the init tile screen code sets what pixels have access to what 4 colors.

    The code makes no sense to me so I cant edit it.

    If someone can write the init tile screen code for me so that there is access to the following:

    20 x 20 square in the top left of screen. (Green)
    Then 20 x 20 squares next to that. (Red, Yellow, Blue, Orange)

    attachment.php?attachmentid=55884

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
    400 x 80 - 381B
  • Harrison.Harrison. Posts: 484
    edited 2008-09-19 06:38
    Try using TV_Text to print out characters to form your blocks (kind of like ASCII art). It'll use a lot less memory space, and will be easier to comprehend.
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 07:26
    Getting a perfect filled shape is hard on its own. Getting each one to be a different color is even more of a challenge.

    Thank you for your suggestion anyway Harrison but I really dont see how its possible.


    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-19 07:32
    Could someone please explain what the following line does.

    repeat x from 0 to tv_hc - 1
        repeat y from 0 to tv_vc - 1
            screen[noparse][[/noparse]x + y * tv_hc] := i << 10 + display_base >> 6 + x * tv_vc + y
    
    



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-19 13:19
    "screen" is a word array that contains the tiles. Each tile consists of a pointer to the memory for the tile (16 longs for a 16 x 32 tile) and an index to the color table entry for the tile.

    The code you showed constructs each tile by calculating the address within the bitmap for the graphics display and putting that into the tile along with a default color ("i"). If this were a text display, the tiles would contain a pointer to a font table entry and the index of a color table entry. Note that the tile pointer is not a true address. The display driver shifts it around to get an address as it's building a scan line.

    You will have trouble getting adjacent 20 x 20 areas of color. You'd be much better off using a 16 x 16 or 32 x 32 area because of the tile size.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-19 13:36
    This routine will change the color of a tile given the x and y locations of the tile:
    PRI changeColor(x, y, color)
       x := x >> 4   {change from pixel coordinate to tile coordinate for a 16 x 16 tile}
       y := y >> 4
       result := color[noparse][[/noparse] y * tv_hc + x ]
       color[noparse][[/noparse] y * tv_hc + x ] := (result & $3FF) | (color << 10)
    


    For 32 x 32 areas using 16 x 16 tiles, you'd do:
    repeat i from 0 to 4
       changeColor(i * 32 + 0, 0, i + 1)
       changeColor(i * 32 + 16, 0, i + 1)
       changeColor(i * 32 + 0, 16, i + 1)
       changeColor(i * 32 + 16, 16, i + 1)
    


    Now each of the five 32 x 32 areas uses one color table entry from 1 to 5
    with the default color table entry still 0 for the rest of the screen. Each
    color table entry consists of 4 bytes (corresponding to a graphics color from
    0 to 3). There's a test program (graphics_palette) that displays the color
    for each possible byte value. Use that to choose the byte values to use.

    Post Edited (Mike Green) : 9/19/2008 1:43:26 PM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2008-09-22 12:34
    Here is the code I have and all I get is a black screen.
    What am I doing wrong?
      'init colors
      repeat i from 0 to 63
        colors[i] := $00001010 * (i+4) & $F + $2B060C02
    
      'init tile screen
      repeat dx from 0 to tv_hc - 1
        repeat dy from 0 to tv_vc - 1
          screen[noparse][[/noparse]dy * tv_hc + dx] := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
    
      'start and setup graphics
      gr.start
      gr.setup(16, 12, 128, 96, bitmap_base)
    
          
    repeat i from 0 to 4
       changeColor(i * 32 + 0, 0, i + 1)
       changeColor(i * 32 + 16, 0, i + 1)
       changeColor(i * 32 + 0, 16, i + 1)
       changeColor(i * 32 + 16, 16, i + 1)
    gr.finish
    gr.copy(display_base)
    [/i]
    



    Thank you Mike. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE

    Post Edited (computer guy) : 9/22/2008 12:40:09 PM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2008-10-06 07:30
    Anyone?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Building Blocks To The Propeller Chip A web site designed to help people who are new to the propeller chip.

    Guitar Hero controller using the prop (WIP) --> HERE
Sign In or Register to comment.