Some small details left to iron out...

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
hgboy
Posts: 25
Joined: Wed Aug 13, 2008 9:35 pm
Location: Dayton, OH

Some small details left to iron out...

Post by hgboy » Thu Mar 12, 2009 2:09 am

I have almost all of the code written for my digital dash display. Well, at least for one of the screens involved with that :D

Image

The bar graphs are adjusted by ADC.Reads on channels 0-2 on a 18F4550. Right now they are just hooked up to some 10k pots, but will eventually be pulling information from the sensors in my car. And since I couldnt get the setimage function to work with octals t6963c library (my fault, not his, its a great driver) I used a LOT of line commands to draw everything.

The thing I'm having trouble with is, that when the rectangles adjust to the different values, the old images are left behind. I am unaware of how to remove this ghosting effect without refreshing the entire screen (which blinks badly due to the time needed to draw the background images again). Does anyone have any advice on how I could accomplish this?

Here is my main program loop...

Code: Select all

//Main program loop
While(true)


    Y1Value = 0
    Y2Value = 0
    XValue = 0
    
    fuel = ADC.Read(0)
    temp = ADC.Read(1)
    boost = ADC.Read(2)
    psi =  getpsi(boost)
    psinum = getpsivalue(psi)
    
    Y1Value = GetY1Value(fuel)
    Y2Value = GetY2Value(temp)
    XValue =GetXValue(boost)

    
    
    //Draw rectangles based on ADC results
    
    //Fuel gauge rectangle
    Rectangle(6,57,12,Y1Value)
    
    //Temperature Gauge rectangle
    Rectangle(115,57,121,Y2Value)
    
    //Boost Gauge rectangle
    Rectangle(37,56,XValue,50)

    //psi value
    glcd.writeat(64, 36, psinum)

Raistlin
Registered User
Registered User
Posts: 69
Joined: Tue Apr 01, 2008 1:13 pm

Post by Raistlin » Thu Mar 12, 2009 2:16 am

Just do it like you would a BoB (blitter object) on the ol amiga :D

Remember what you drew then un draw it.
In you case you only need the difference between the last rectangle drew and the new one , if the new one is higher , draw it over the top of the old one , if it is lower draw a background colour rectangle over the bit you want to get rid of
If you can read this you are too close

hgboy
Posts: 25
Joined: Wed Aug 13, 2008 9:35 pm
Location: Dayton, OH

Post by hgboy » Thu Mar 12, 2009 2:32 am

I was thinking along those lines, but I guess my issue is not knowing how to undraw what I need to. using what is in the library. This is my first encounter with an lcd of any sort.

hgboy
Posts: 25
Joined: Wed Aug 13, 2008 9:35 pm
Location: Dayton, OH

Post by hgboy » Thu Mar 12, 2009 6:23 am

It's been hard walking away from this project :D I think I have it figured out.

Code: Select all

While(true)



    
    fuel = ADC.Read(0)
    temp = ADC.Read(1)
    boost = ADC.Read(2)
    psi =  GetPSI(boost)
    psinum = GetPSIValue(psi)
    
    
    
    Y1Value = GetY1Value(fuel)
    Y2Value = GetY2Value(temp)
    XValue =GetXValue(boost)

    pen.color = 0
    Line(6,5,6,(Y1Value-1))
    Line(7,5,7,(Y1Value-1))
    Line(8,5,8,(Y1Value-1))
    Line(9,5,9,(Y1Value-1))
    Line(10,5,10,(Y1Value-1))
    Line(11,5,11,(Y1Value-1))
    Line(12,5,12,(Y1Value-1))
    
    Line(115,5,115,(Y2Value-1))
    Line(116,5,116,(Y2Value-1))
    Line(117,5,117,(Y2Value-1))
    Line(118,5,118,(Y2Value-1))
    Line(119,5,119,(Y2Value-1))
    Line(120,5,120,(Y2Value-1))
    Line(121,5,121,(Y2Value-1))
    
    Line(89,50,(XValue+1),50)
    Line(89,51,(XValue+1),51)
    Line(89,52,(XValue+1),52)
    Line(89,53,(XValue+1),53)
    Line(89,54,(XValue+1),54)
    Line(89,55,(XValue+1),55)
    Line(89,56,(XValue+1),56)
    //Draw rectangles based on ADC results
    pen.color = 1
    //Fuel gauge rectangle
    //Rectangle(6,57,12,Y1Value)
    Line(6,57,6,Y1Value)
    Line(7,57,7,Y1Value)
    Line(8,57,8,Y1Value)
    Line(9,57,9,Y1Value)
    Line(10,57,10,Y1Value)
    Line(11,57,11,Y1Value)
    Line(12,57,12,Y1Value)
    //Temperature Gauge rectangle
    //Rectangle(115,57,121,Y2Value)
    Line(115,57,115,Y2Value)
    Line(116,57,116,Y2Value)
    Line(117,57,117,Y2Value)
    Line(118,57,118,Y2Value)
    Line(119,57,119,Y2Value)
    Line(120,57,120,Y2Value)
    Line(121,57,121,Y2Value)
    //Boost Gauge rectangle
    //Rectangle(37,56,XValue,50)
    Line(37,50,XValue,50)
    Line(37,51,XValue,51)
    Line(37,52,XValue,52)
    Line(37,53,XValue,53)
    Line(37,54,XValue,54)
    Line(37,55,XValue,55)
    Line(37,56,XValue,56)
    //psi value
    //GLCD.WriteAt(64, 36, psinum)
    
    
    
Wend 

End
This draws a background color image over the upper portion, effectively erasing it. The only thing left to do with this code is implement some short conditional routines to keep the erasing from happening when the bars are at their fullest, because there is some slight flicker at these points. That or perhaps running a faster clock speed, right now I'm only using the 8MHz internal oscillator.

Raistlin
Registered User
Registered User
Posts: 69
Joined: Tue Apr 01, 2008 1:13 pm

Post by Raistlin » Thu Mar 12, 2009 8:29 pm

You could store the last rectangle length in a variable (if you can afford the mem) then subtract the current value from the last value and simply draw background over the difference , not the whole rectangle ,, this would be much faster.
If you can read this you are too close

hgboy
Posts: 25
Joined: Wed Aug 13, 2008 9:35 pm
Location: Dayton, OH

Post by hgboy » Fri Mar 13, 2009 11:38 pm

I figured out where the slight flicker was coming from. Basically, I am drawing a background color rectangle from the top down to the maximum yvalue of the rectangle + 1. The screen was flickering because i had the background color rectangle starting from the maximum yvalue of the largest rectangle drawn. This was causing it to constantly write and re write the top line when the graph is maxed out. I simply started drawing the background color rectangle one pixel higher, and the flicker is gone.

Post Reply