bitluni / ESP32-S3-VGA

115 stars 10 forks source link

Unstable screen #8

Open mylab4492 opened 9 months ago

mylab4492 commented 9 months ago

I'm using this code where I'm drawing on screen in loop but its not stable

`

include "ESP32S3VGA.h"

// r,r,r,r,r, g,g, g, g, g, g, b, b, b, b, b, h,v const PinConfig pins(4,5,6,7,8, 9,10,11,12,13,14, 15,16,17,18,21, 1,2);

//3 bit version (no resistor ladder) //const PinConfig pins(-1,-1,-1,-1,8, -1,-1,-1,-1,-1,14, -1,-1,-1,-1,21, 1,2);

VGA vga; Mode mode;

void setup() { //VGAMode mode = MODE_1024x768x60; //if(!vgaInit(pins, mode, 8)) while(1) delay(1);

mode = Mode::MODE_800x600x60;
if(!vga.init(pins, mode, 16)) while(1) delay(1);
vga.start();

}

void loop() { for(int y = 0; y < mode.vRes; y++) for(int x = 0; x < mode.hRes; x++) vga.dotdit(x, y, x, y, 255-x); for(int y = 0; y < 30; y++) for(int x = 0; x < 256; x++) { vga.dot(x, y, x, 0, 0); vga.dot(x, y + 30, 0, x, 0); vga.dot(x, y + 60, 0, 0, x); } vga.show(); } `

sobieh commented 9 months ago

It depends on the hardware you are using. 800x600 in 16 bits works only on 8MB PSRAM version of esp32s3 as it requires much faster DMA transfers from psram to peripherals. 8MB version has OctalSPI connection to external PSRAM where 2 and 4 MB versions just QuadSPI which is much slower. DMA will not keep up with such high data rate and will desync. For start try to go with 640x480x60 in 16 bits or 800x600x60 in 8 bits. It should work just fine on any hardware.

Here you can find much better example of VGA using esp32s3 using proper bounce & vsync semaphores: https://github.com/bitfixer/esp32s3vga

BTW ... looks like you are trying to use arduino/platformio ... better switch to original ESP IDF extension for vscode: https://docs.espressif.com/projects/esp-idf/en/v4.2.3/esp32/get-started/vscode-setup.html It's gives you way more options.

mylab4492 commented 9 months ago

I am using esp32s3 vga and bitluni example works if I am using it in setup only As soon as I start updating the display then display start moving randomly

On Sat, 7 Oct 2023 at 7:52 PM, sobieh @.***> wrote:

It depends on the hardware you are using. 800x600 in 16 bits works only on 8MB PSRAM version of esp32s3 as it requires much faster DMA transfers from psram to peripherals. 8MB version has OctalSPI connection to external PSRAM where 2 and 4 MB versions just QuadSPI which is much slower. DMA will not keep up with such high data rate and will desync.

Here you can find much better example of VGA using esp32s3 using proper bounce & vsync semaphores: https://github.com/bitfixer/esp32s3vga

BTW ... looks like you are trying to use arduino/platformio ... better switch to original ESP IDF extension for vscode:

https://docs.espressif.com/projects/esp-idf/en/v4.2.3/esp32/get-started/vscode-setup.html It's gives you way more options.

— Reply to this email directly, view it on GitHub https://github.com/bitluni/ESP32-S3-VGA/issues/8#issuecomment-1751725165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AINHDTHYVTVZSZHEZP7U44DX6FQTVAVCNFSM6AAAAAA5W6DHWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRG4ZDKMJWGU . You are receiving this because you authored the thread.Message ID: @.***>

sobieh commented 9 months ago

If you loop your drawing routine like that it will constantly consume all the PSRAM bandwidth leaving near to nothing for DMA and causing desync. You should simply wait for next frame vsync before you start drawing next one (semaphore). Bitluni's driver does not support that as it's only an example how to output static frame VGA signal.

You could also try to add delay(33) to your loop to make it render max 30 fps giving much more bandwidth to DMA. This is far from ideal and will waste a lot of cpu time but "should help" for experiments. Check out the link i mentioned in my previous reply for better solution.

EDIT: Get rid of this part:

for(int y = 0; y < mode.vRes; y++)
    for(int x = 0; x < mode.hRes; x++)
        vga.dotdit(x, y, x, y, 255-x);

Filling whole framebuffer like that is REALLY slow. You can optimize it by rendering to separate "image buffer" and copying the finished image several times using memcpy.

mylab4492 commented 9 months ago

Thanks for the tip! I have check the ps ram usage it is not full ps ram is always free I will try your suggestions and let you know Can we use semaphore with bitluni library as I’m using arduino for development

On Sat, 7 Oct 2023 at 8:20 PM, sobieh @.***> wrote:

If you loop your drawing routine like that it will constantly consume all the PSRAM bandwidth leaving near to nothing for DMA and causing desync. You should simply wait for next frame vsync before you start drawing next one (semaphore). Bitluni's driver does not support that as it's only an example how to output static frame VGA signal.

You could also try to add delay(33) to your loop to make it render max 30 fps giving much more bandwidth to DMA. This is far from ideal and will waste a lot of cpu time but "should help" for experiments. Check out the link i mentioned in my previous reply for better solution.

— Reply to this email directly, view it on GitHub https://github.com/bitluni/ESP32-S3-VGA/issues/8#issuecomment-1751730720, or unsubscribe https://github.com/notifications/unsubscribe-auth/AINHDTFSULPZBH3TAMC5N4TX6FT4RAVCNFSM6AAAAAA5W6DHWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRG4ZTANZSGA . You are receiving this because you authored the thread.Message ID: @.***>

sobieh commented 9 months ago

It's not about free ram just bandwidth (amount of reads + writes to the external psram). The more you write with dot() dotdit() the less bandwidth is left for the driver (dma) to read and put to vga monitor. On 2MB version there is only ~24MB/s bandwidth available. If you use all of this to draw then vga driver will not be able to read anything.

mylab4492 commented 9 months ago

Oh, I see. So what you suggest if I have to draw dynamic text on screen? Note: Bitluni old vga library is working at 800x600x60 with 3 bit color which does not use psram. So this one should work better than that.

sobieh commented 9 months ago

What i suggest ? I suggest you read my previous posts and check the other lib i linked :) It's much better written than bitluni's. You can easily go with 800x600x8 or 640x480x16 with it and render whatever you like without desyncs. The only limitation will be speed of your animations (more complex = slower).

mylab4492 commented 9 months ago

Thank you for your suggestion I have not used esp idf and I have been using arduino for past 6 years Can you guide me how to draw text using bitfixer library as ij that library there is no example given

Thank you again for you response

On Sun, 8 Oct 2023 at 4:31 AM, sobieh @.***> wrote:

What i suggest ? I suggest you read my previous posts and check the other lib i linked :) It's much better written than bitluni's. You can easily go with 800x600x8 or 640x480x16 with it and render whatever you like without desyncs. The only limitation will be speed of your animations (more complex = slower).

— Reply to this email directly, view it on GitHub https://github.com/bitluni/ESP32-S3-VGA/issues/8#issuecomment-1751848947, or unsubscribe https://github.com/notifications/unsubscribe-auth/AINHDTEO2YY6C6J6VBS5UD3X6HNMJAVCNFSM6AAAAAA5W6DHWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRHA2DQOJUG4 . You are receiving this because you authored the thread.Message ID: @.***>

bitluni commented 8 months ago

@sobieh thx for suggesting bitfixer's lib

regarding the sync issues: 800x600 ist almost at the limit of the PSRAM bandwidth. Since the PSRAM only transfers cache pieces in bursts. Syncing up the cache might cause the sync issues. Technically there is spare room in the band width during the h and v syncs which can be managed using the DMA-Buffer interrupts. This solution is very complex and I just didn't have time yet to tackle it. A middleground would be a v-sync callback to perform drawing operations. Text scrolling is on my priority list since it can be easily done with line buffer rotation. Expect that to be one of the next changes along with 14/6 bit modes that handle the sync themselves and resync automatically once it was "overwhelmed"

@mylab4492 a low resolution mainloop text-example was added recently

I'll check the pull requests and try to improve ASAP

dkm1978 commented 8 months ago

The solution to the problem should be to switch ESP32-Arduino to IDF 5.0+. There will be access to V-SYNC interrupts. All DMA buffer updates performed during vertical blanking should no longer result in errors. As proposed by @sobieh, this solution is used by the library https://github.com/bitfixer/esp32s3vga. I'll post a link to the action video again https://www.youtube.com/watch?v=UcUQ3nAcvj8 Unfortunately, errors appeared when I started using the SD card. Low throughput made itself felt. After reducing the resolution to 640x480, everything works stably. https://youtu.be/R48-PIyn2lE

bitluni commented 8 months ago

IDF 5+ is my paaaain... so much changed! yet, arduino integration is still not updated. We need to poke the esp devs. I always wanted to keep this project simple to use which IDF is not. Currently, it seems VGA S3 is only .

dkm1978 commented 8 months ago

In fact, work on the new version of Arduino ESP32 is going extremely slowly. Come on, let's be happy with what we have :) and by the way, @bitluni, great job with this driver. I prefer to use my own graphic procedures :P In general, everything works USB/SD/AUDIO and VGA. The basic interpreter also works :) https://youtu.be/_MES6m9GfDU

mylab4492 commented 8 months ago

@bitluni yes arduino is much simpler and i also don’t want to go to idf hence waiting for you updates? Let’s hope for the best

On Sun, 15 Oct 2023 at 1:29 PM, Proteus @.***> wrote:

In fact, work on the new version of Arduino ESP32 is going extremely slowly. Come on, let's be happy with what we have :) and by the way, @bitluni https://github.com/bitluni, great job with this driver. I prefer to use my own graphic procedures :P In general, everything works USB/SD/AUDIO and VGA. The basic interpreter also works :) https://youtu.be/_MES6m9GfDU

— Reply to this email directly, view it on GitHub https://github.com/bitluni/ESP32-S3-VGA/issues/8#issuecomment-1763311561, or unsubscribe https://github.com/notifications/unsubscribe-auth/AINHDTGLH4MEPW65RN24RRDX7OJVXAVCNFSM6AAAAAA5W6DHWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRTGMYTCNJWGE . You are receiving this because you were mentioned.Message ID: @.***>

spikepavel commented 8 months ago

Hello. It is better to use the arduino IDE. It is simpler and means more people will use it. Bitluni, thank you for your work. We are looking forward to updating the library.