convert two analogue pulses (5000/second) for display on HDMI or Composite Video

Started by charliecoutas, Jun 29, 2026, 01:19 PM

Previous topic - Next topic

See_Mos

I like the idea of a PIC driving VGA but If it is for text only would it not be easier to just use an old PC or laptop and write something in visual Basic?

Even a Pi might be easier if you want something small.

top204

I have adapted the VGA code using the PIC18F46K22 device, to Positron8 on a PIC18F26K22 device, but I cannot test it yet, until I get a VGA socket from somewhere, and dig out my old VGA monitor from the loft. However, the timings look OK.

The code mechanism in the original, is very cumbersome, with rotating the whole of a port for a single bit out, so when I do test it, and get it working, I will adapt the interrupt to use a hardware SPI peripheral for the data bits, and then, maybe, adapt it for colour using PWM peripherals, or USARTs, or a simple 8-bit colour mechanism, using the 3 RGB pins.

Once I know it is working, I will add the character routines to it. i.e. Print, and multiple fonts etc..

Please let me know if it is working, if anyone has a VGA monitor to try, because it may be a few days before I find what I need here.

The source codes are attached below.

Regards
Les

JonW

Les, you should get this tomorrow from Amazon  ;D   

charliecoutas

Sorry Les, your reply came while I was typing this. Please don't go to a lot of trouble as I think I have got it sorted. Using a Rasberry Pi Pico I'm afraid. I can't test your code because my VGA screen is at Bletchley. This is what I sent before I saw your post:

Yes, I thought about that but I've used a Raspberry Pi Pico before and I thought it would be easy. I was wrong! I found some code written in Micropython on Github that I have managed to get working, eventually.

I have a Pico2 which has the later version of the RP2040 chip, called RP2350. They are supposed to be backward compatible, so I assumed code written for the RP2040 would work on the RP2350. Wrong. I later bought a Pico with the RP2040 chip and it works!

The problem seems to be in the PIO section: the PIO has a number of "state machines" which you can program to generate things like the vertical and horizontal pulses for the VGA protocol. These are independent of the main cpu so they don't affect it.

Anyway, I am now well on my way to getting a large(ish) screen with lots of text and moving images, and analysis of the paper tape on Colossus. Quite a journey.

If anybody is interested I can post the code, when I have got it working. Lynda and I are away for the next couple of weeks floating down the rivers of Europe (if there is any water left in them after such a long dry spell).

Regards to all
Charlie

charliecoutas

Les, the word grateful doesn't seem enough but I can't find a better one. Thank you so much, I would much prefer to use your code on the Colossus Tape Reader display. I can't do anything for the next two weeks, we are away on a much-needed holiday and I'm not allowed to do any electronics/coding.

I owe you one, (then another then.........)

Charlie

top204

Charlie... I had such a lovely day at Bletchley, thanks to you, Tim, Ricardo, and the, 'truly', good people there. That day will remain in my memory until the day I pass. You and Tim, actually made one of my dreams come true. So my thanks will always be to you and Tim.


This afternoon... I was sorting out my tools for the fence I am putting up in the front garden, when a package dropped in the door.

It was from amazon, so I automatically thought it was one of they ploys or spams or encouragements, because I do not go anywhere near amazon. So when I opened it, I found 2 of those VGA adapters Jon posted about, yesterday?

Many, many thanks Jon. I did not realise that you had purchased 2 of them for me. I had thought you meant: "you can get these items from amazon, and they will arrive the next day" :-)

I'll wire it up tomorrow morning, and see if my code works, and if not, correct it, then adapt it for more efficiency, and also on a PIC24 or dsPIC33 device.

We have some truly lovely people on this forum.

Very best regards
Les

JonW


See_Mos

Looking forward to having a play with PIC VGA.  I have several leads so I will most likely cut one up and use that.

charliecoutas

Les, we're back from holiday, cruising on the rivers of Europe. But sadly, nearly all of Europe's rivers are low on water due to the ongoing hot weather and perhaps climate change. We went from Budapest to Vienna and on up the Danube (it's not blue!) and on to Amsterdam. We had to change boats twice due to the water levels. But it was fine, the sales brochures should advertise "As much wine as you can drink - no extra charge."

To get back to your kind development of a PIC VGA Driver: I've tried your software, no changes, 18F26K22 etc.

The vertical sync (C.0) is good, a low-going pulse 64uS wide repeats every 16.5mS (60 frames/sec).
But the horizontal sync (C.2) is low all the time. There is nothing happening on PORTB, all low.

I'll see what I can deduce from your coding Les (which is nice and clear).

Best regards to all
Charlie

Pepe

Why do we have to set the crystal frequency value to 48MHz so that the delay in ms works correctly in Proteus?

top204

So did you go for a paddle in the Danube, with your pants up to your knees and a hanky tied on your head?

I could not get a signal either Charlie, so the original code found on the internet, that I converted seems to be faulty, surprise, surprise. LOL.

As I was converting the code, I did see some things that did not look right, but I have never created a VGA signal before, so I could not be certain... However, it seems I was right.

I'll get back into it ASAP, thanks to the excellent VGA sockets provided by Jon (many thanks Jon).

Regards
Les

charliecoutas

I could have gone for a paddle, the Danube is not very deep at the moment. Coming from Grimsby I can relate to deckchairs, sea and sand and people with hankies on their heads!

No worries on the VGA, one of the lads at the museum is a Raspberry nut and playing with the same project using a little Pico. He might beat me but your version will be preferred by me for obvious reasons.

Charlie

JonW

No worries Les.

If you want me to push the code through the trained AI to see if it can find the error, email.me the codes

J

RGV250

QuoteComing from Grimsby
Never been there but seen the film, I was in stitches in the first couple of minutes :)

Bob

charliecoutas

Bob: Well somebody must come from Grimsby! I was chatting with some pals after Lynda and I had been to Grimsby for the weekend. "Went went to Grimsby for the weekend" said I. "Why???" they said.

Jonw: That is a kind offer but I don't know how to email you or how to work email.me. It will be worth a try. Can you pm me your email addr?

Charlie

See_Mos

I just came across my old Bitscope USB logic analyser / Oscilloscope and wondered if any were for sale on eBay.

I was surprised to see Chinese logic analysers of similar spec'at less then £10 each or around £15 for two.

Just add the free Sigrok software and an old laptop or computer and screen.

JonW

There are some < £10 based on the Cyprus MCU online, but the one to get is the Sipeed SLogic16U3.  This is based on the Gowin GW5AT-LV15 FPGA, which is an unbelievably cheap FPGA with a full-speed USB 3.0 on-chip.  The analyser, as a set with a case, leads and probes, can be picked up for about £60 delivered from AliExpress.  This is a VERY capable analyser when paired with PuseView and pushes the £1000 Salae.  I bought one to decode the old-school GPIB adapter that I am building; with a cheap board, it interfaces directly to the decoder in PulseView.

JonW

Hi Charlie

Q. Why do you want two analogue channels?

How are you getting on with this? I had an idea to use the el cheapo Gowin Tang Nano 9K FPGA board to build a true SSD1306-to-HDMI emulator, and I've been at it in the evenings, sad I know, but am trying to get to grips with FPGA's.  I had a decent look online, and nothing exists, so I had a go and think I have it working!  I am struggling to get the FLASH programmed in the TANG 9k and need a fix; the SRAM load works, showing it running.  Once I get the flash going and test it with a real MCU, I'll send one to LES as he will love it!! I may port it to a tiny board, but the Gowin parts are hard to source and the dev boards, so cheap.



What it does

The FPGA emulates an SPI SSD1306 OLED panel. A host talks to it exactly as if it were a £2 display, same pinouts, same commands, no special driver — and the picture comes out on an HDMI monitor.

The emulated panel is the usual 128x64. Output is 640x480 at 60 Hz, with the panel scaled up 5x to 640x320 and centred, black border top and bottom. 128x64 is 2:1 so it can't fill a 4:3 screen without distorting it.

Compatibility

Bit-exact rather than approximate. All three addressing modes with the correct wrap behaviour, segment remap, COM scan direction, display offset, start line, multiplex ratio, inverse, entire-display-on, contrast, hardware scroll, and charge-pump gating — so if you forget 0x8D 0x14 it stays dark exactly like the real thing.

Three things that commonly get emulated wrong and are right here: the reset default is page mode rather than horizontal, remap is applied at scan time so 0xA1 flips an image that is already drawn, and bit 0 of a GDDRAM byte is the top row of the page.

Which means you can wire a real SSD1306 to the same four wires and both show the same thing. That's the test I want to do before trusting it.

Speed

I haven't driven it from an MCU yet. Instead, I built an SPI master into the FPGA that drives the actual pins with a real byte stream — so it goes out of the chip and back in through its own SPI receiver rather than cheating internally. You can put a scope on it.

That runs at 6.3 MHz. A full 1024-byte frame takes 1.43 ms, and it refreshes at 58 fps. Back to back it would manage 699 fps, so the frame rate is a choice rather than a limit. The FPGA end will take 15 MHz, but a real SSD1306 tops out at 10 MHz, so 10 MHz is the sensible number if both are ever on the same bus.

The two renders

The scope picture is a photocell model, not a square wave. Light through a round hole crossing the slit is proportional to the chord of the circle, so each hole gives a rounded hump rather than an edge. At 5000 char/s the tape is doing 12.7 m/s, a 1.83 mm data hole takes 144 us to cross, and a 0.25 mm slit gives the ~20 us transition. It's got amplitude variation and a bit of timing wander on it too. Top trace is a data channel, bottom is the sprocket — narrower and lower, as it should be. 

Worth noting the two adjacent holes on the top trace barely get back to baseline between them. 144 us of hump in a 200 us character. On a worn tape that's where it starts to merge. 

The tape picture draws the tape itself — five data tracks and the smaller sprocket, correct order with three tracks above the sprocket and two below, scrolling as it's read. Two lines wrapped like text so you see 64 characters at once. Drawn roughly to scale, 17.5 mm tape width against 2.54 mm pitch, so the holes come out about square.

Both are generated within the FPGA at the moment, so I can test the real SPI. Changing the timebase is one script and a re-synthesis.

I have added one command that isn't in the SSD1306 set: 0xE0 followed by 0-7 picks the trace colour — P31 green, amber, white, blue and a few others. Still one bit per pixel, you're just choosing what "on" looks like. Green suits this. A real SSD1306 has no 0xE0 so it can be left out if you're driving both.

Just messing about with the renders as I don't know what you would show; the pics are on a 21" Samsung monitor with the green setting.  The FPGA is much more capable for HDMI, but this just looks cool, and everyone loves the blocky SSD1306. 

Cheers

Mapo