Hot!LCC - writing to frame buffer while DMA sending data

Author
alex_elec
Junior Member
  • Total Posts : 94
  • Reward points : 0
  • Joined: 2014/03/26 04:41:13
  • Location: UK
  • Status: offline
2018/05/01 04:18:42 (permalink)
0

LCC - writing to frame buffer while DMA sending data

Hi there,
 
Just a quick one, if I have an LCC setup with DMA/PMP on a PIC32MZ outputting display data to an LCD (in DE mode) should I suspend DMA transfers while writing to the frame buffer? Could there be a problem if I was in the middle of writing a pixel and the DMA transfer kicks in?
 
I have a 3.5" QVGA screen, on a PIC32MZ1024EFE100, MPLABXv4.15. I am not using the EBI but instead using my DMA/PMP solution that worked on a PIC32MX
 
Sometimes I see flickering/ghosting while changing what is on screen (I update the frame buffer 4 times a second to handle live readings). See video here: drive.google.com/file/d/1rqVCAZtBp0DgP038wZkAs2xNRIouDsgz/view?usp=sharing
 
Hopefully that link will work, may need copy/paste
 
Any tips appreciated!
Thanks,
Alex
 
#1

14 Replies Related Threads

    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/01 04:24:18 (permalink)
    0
    Should add, I get around a 50Hz frame rate with a Varitronix T350T2080 display. I am in communication with them as their data sheet is a bit difficult to follow as there isn't concise timing data.
     
    I toggle the data enable line only for the 240 lines of valid data then there are around 40 extra lines for the blanking period. The horizontal blanking is at the end of each line and I clock out 88 pulses here. 
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 17007
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/01 06:07:10 (permalink)
    0
    If you disable the DMA you will see it in the screen. Writing during the DMA should not hurt anything? But may be visible on the screen.
    #3
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/01 06:18:39 (permalink)
    0
    Yes that was what I thought, you can write to the buffer at any point. 
     
    have you seen anything like what is in the video I linked to before?
     
    It seems like the timing to the LCD is getting messed up somehow and it seems to start writing to the display on the wrong line almost but then corrects itself on the next frame. 
    #4
    RISC
    Super Member
    • Total Posts : 5375
    • Reward points : 0
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/01 07:58:04 (permalink)
    0
    Hi,
     
    You could also reduce frame rate to let's say 30Hz (in a 50Hz environment).
    This should be good enough.
    The latest Arial libraries have double buffer support.
    Maybe this could help if you can afford the RAM space...
    Regards
     
     
    #5
    MHGC
    Super Member
    • Total Posts : 220
    • Reward points : 0
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/01 09:40:48 (permalink)
    0
    Hi,

    What are your LCC driver settings?
    Specifically, what is the V-Sync Refresh Strategy?  Conventional or Aggressive?
    If you are using Conventional, you may want to try set Pixel Draw Memory Write Strategy to "In-between Frame & Line Draw".
    #6
    adamfolts
    Super Member
    • Total Posts : 218
    • Reward points : 0
    • Joined: 2010/10/19 08:32:20
    • Location: Prescott
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/07 14:35:15 (permalink)
    0
    It could be a PIC32MZ caching issue.
    #7
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/05/17 04:02:03 (permalink)
    0
    I'm running uP at 120MHz
     
    Here is my caching setup code:
     
     

    PRECONbits.PFMWS=1; //Two wait states - for 133-200MHz Clock speeds.
    PRECONbits.PREFEN=3; //Predictive Prefetch Enable bits = 11 = Enable predictive prefetch for any address

    CheckCheKseg0CacheOn(); //This routine is used to enable cacheability of KSEG0.

     
    EDIT: Straight off the bat there might be a problem according to my comment "Two wait states - for 133-200MHz Clock speeds."
     
    2nd EDIT: The comment is wrong, currently set to 1 wait state as correct for 120MHz clock
    post edited by alex_elec - 2018/05/17 04:22:02
    #8
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/07 04:20:41 (permalink)
    0
    bill.li
    Hi,

    What are your LCC driver settings?
    Specifically, what is the V-Sync Refresh Strategy?  Conventional or Aggressive?
    If you are using Conventional, you may want to try set Pixel Draw Memory Write Strategy to "In-between Frame & Line Draw".


    Hi there,
     
    I'm not using the full harmony driver unfortunately, I cooked up my own for the PIC32MX and have ported this to the MZ.
     
    If I were to knock up my own write strategy for 'In-between Frame & Line Draw' I would disable the DMA channel interrupt when writing to the FrameBuffer? and then re-enable once I am done? Would this be enough to follow this strategy?
     
    I'm trying to refactor my code so that I make minimal writes to the frame buffer - before I would basically redraw everything on screen a few times a second as I am reading 16 multi-plexed ADC inputs and need to display this information in a timely manner.
     
    Cheers
    post edited by alex_elec - 2018/06/07 05:16:23
    #9
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/07 05:31:57 (permalink)
    0
    adamfolts
    It could be a PIC32MZ caching issue.


    Can anyone elaborate on this?
    Would I need to flush the cache before setting up the DMA transfer everytime?
     
    I've seen some functions from sys_devcon that could be appropriate here
    post edited by alex_elec - 2018/06/07 05:34:35
    #10
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/07 08:32:20 (permalink)
    0
    Interestingly, when I check the 'CONFIG' cpu register, K0 = 0??
     
    000 = Cacheable, non-coherent, write-through, no write allocate
     
    I thought the default was: 011 = Cacheable, non-coherent, write-back, write allocate
     
    So maybe I have the wrong set up here?
     
    I'm struggling to use any of the SYS_DEVCON macros, I have included:
     
    #include <xc.h>
    #include <cp0defs.h>
    #include "..\header\sys_devcon.h"
    #include <proc/p32mz1024efe100.h>
     
    I'm getting:
    source/sys_devcon_pic32mz.c:97: undefined reference to `_pic32_flush_cache'
     
     
    #11
    NKurzman
    A Guy on the Net
    • Total Posts : 17007
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/07 09:26:03 (permalink)
    0
    The issue is does the cache know the data changed.  You can either use the Proper KSEG0 / KSEG1 address.  or use the coherent attribute to insure that the data is read from memory and not the cache.
    #12
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/08 04:28:04 (permalink)
    0
    Thanks Kurzman, yes I have played around with the Coherent attribute and things seem better.
     
    I still have some confusion regarding the K0 variable in the CONFIG cp0 cpu register. I can't seem to set it? I know the startup code is supposed to be setting this up, but it always reads 0. From the app note AN1600 the default should be 0x3?
     
    #define UNCACHED 0x02
    #define WB_WA 0x03
    #define WT_WA 0x01
    #define WT_NWA 0x00

    void SetCachePolicy(int cc)
    {
        unsigned int cpO;
        
        cpO = _mfc0(16, 0);
        cpO &= ~0x03;
        cpO |= cc;
        _mtc0(16, 0,cpO);
    }

    #13
    adamfolts
    Super Member
    • Total Posts : 218
    • Reward points : 0
    • Joined: 2010/10/19 08:32:20
    • Location: Prescott
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/20 18:14:41 (permalink)
    0
    I would look into the latest LCC Driver code/demo and see how they setup the cache for the PIC32MZ. You should just mimic that. It would simplify your problem of trying to recreate a solution that already exists.
    #14
    alex_elec
    Junior Member
    • Total Posts : 94
    • Reward points : 0
    • Joined: 2014/03/26 04:41:13
    • Location: UK
    • Status: offline
    Re: LCC - writing to frame buffer while DMA sending data 2018/06/21 00:52:11 (permalink)
    0
    Yes I think I have a better solution now, I think there is a problem reading K0 (CONFIG register) though as it never updates in the CPU registers window whilst debugging but if you read it via cpO = _mfc0(16, 0); the bits appear correct. I have raised a ticket about this but it hasn't got anywhere yet.
     
    To fix my flickering I am now only allowing writes to my GraphicsFrame at the end of the frame DMA transfer when I need to send about 10 lines of dummy data to the LCD. So that gives me about 1mS every 18mS (320x240 16-bit @ 55Hz) in which to write to my Frame buffer. It means I have to change a lot of code but its making me more efficient in what I change on the screen and when.
     
    Next time I'll go for a micro with more RAM to do double buffering and try and understand the library code better!
     
    When the LCC writes to the frame buffer in single buffer mode, does it suspend dma transfers? Or waits till the end of a frame?
    #15
    Jump to:
    © 2019 APG vNext Commercial Version 4.5