John Burton's Blog

Random stuff that only I'd be interested in!

Projects and updates

I’ve not posted much in the last few days because I’ve not done much on any projects, being away from home over the weekend and also updating my CV and putting a little more effort into trying to find a new job over the last few days. I won’t be posting much for the next few days either as I have *two* weddings to go to in the next three days.

So here are my current projects -

  • Continue to work on the TV display. This is mostly software at the moment, writing a reasonable library for displaying graphics and text in other applications. Also I’d like to output RGB signals too so I can get colour but this will require a PIC with more RAM. I could do character cell based colour perhaps in a similar way to an old ZX-Spectrum display. Hmm, idle thought –  I wonder if a PIC is powerful enough to emulate a z80 at the speed of a spectrum… Almost certainly not if it has to display video too.
  • Computer USB / IR Remote project. I’d like to build this properly and put it in a box so I can just plug it into USB port and be able to control the PC. Ideally I’d like to be able to configure the buttons from the PC (What they send…). I would like to consider using a PIC24FJ64GB106 in TQFP package which I believe I could solder onto a PCB I could make. Strangle the farnell link doesn’t show it does USB but the microchip datasheet indicates that it does
  • Learn Direct3D11. I did quite a lot with d3d9 / c++ in the past but I’d like to make a proper project with d3d11 now. I would really like to use C# as a learning excercise too but for this first project i think I’ll stick to c++.

My first project will be the d3d11 one

I was quite pleased with myself getting all of this to work, and have implemented text display too. (Although it’s horribly inefficient as I have to reverse the bits of the font from left to right as I draw them – I need to convert the font really).

But then I put up some blocks around the text and it’s clear that I’ve not got my timing quite right. Every 16 pixels there is a slight gap of less than one pixel. And by coincidence I write out the display 16 bits as a time as it’s a 16 bit CPU. Clearly I miscalculated the timing somewhere. It looks like just ONE cpu instruction, or perhaps two. Anyway, it’s nice to have spotted it here so I can fix it

Simple analogue clock

Basic line and pixel drawing improvements in my PIC24 code.
To test out the line drawing I made a simple clock.

I wish I could make better videos of this, I think I need a TV capture card or something though to do that. To be honest though the clock looks MUCH better on the video than in reality where the lines are somewhat blocky and pixellated,. The camera antialiases it nicely :)

PIC24 programming

There is a lot about the 8 bit PICs on the internet but I’ve found hardly anything about the 16 bit ones so I’m going to start documenting anything I find out on here so I don’t lose it.

First of all I’m using the MicroElektronika C compiler for PIC24 and dsPIC for my programs. You can download it for free and write small programs but I bought the version because I wanted to make bigger programs. There is a free microchip compiler (C30 I think) that you can use for free with optimisations turned off but I didn’t like the sound of that and the MicroElektronica ones comes with C libraries for quite a lot of the hardware that is much easier to use than the microchip ones. Particularly for the USB client library that makes simple HID clients a snap…. Although you can’t do anything more complex with it.

I’m using a PIC24FJ64GGB002 for most of my projects. This is because it’s available in breadboard friendly DIP packaging, although I have to remember it’s 3.3v supply NOT 5v. I connected 5v by mistake once just for a moment and luckily it seems to have survived it, although every time my software doesn’t work I’m wondering now if it’s subtle damage to the chip :(

I’m using the internal oscillator for my projects at the moment. As it’s designed to work with USB it’s reasonably precise and seems fine for tv output too and can be configured to drive the clock at 32Mhz which gives 16M instructions per second.

Chip configuration

Unfortunately for this document the c compiler has a screen for setting the config rather than having it in source code so I’ve taken screen shots and will post them here to remind me of settings in future.

The most critical line of code in my programs is this one, or none of the digital ports work :)

/* Configure ports as digital */
AD1PCFG = 0xFFFF;

In addition I configure the clock this way, although I’m not sure how much of this is needed yet.

CLKDIV = 0;

OSCCON.PLLEN = 1;

OSCCON.RCDIV_0 = 0;

OSCCON.RCDIV_1 = 0;

OSCCON.RCDIV_2 = 0;

Success generating PAL video with a PIC24

More later but here is the proof of concept -

It’s not a good photograph, I had the sun behind the TV for it – but as you can see it’s a nice stable picture with reasonable resolution and it worked!!
This circuit uses just a PIC24FJGB002 and a couple of resistors for the video ouput.

And here is a rather bad video of it…

And a slightly more complex example taken with my phone camera from my TV

Web site for electronics


I just stumbled across chiphacker.com which is like stackoverflow but for electronics questions. It doesn’t seem to have a huge amount of visitors but it’s not empty either.

I wonder if there are any other good sites I’ve missed until now?

PAL tv output from PIC

Yesterday, inspired by this I decided to make a circuit that could display text on a TV using a PIC. Basically I built something like the circuit here but I’m using a PIC24F64GB002 simply because I like PIC24 and I happened to have a couple on hand.

Unfortunatly I’ve had no sucesses at all with getting a picture so far. I figured if I outputted the line sync pulse of 4uS low every 64uS and a high level between it (except for the 8uS before and after the sync pulse) then I should see something on the TV but I see nothing at all.

Possible problems :-

  • I’m using 3v not 5v so I had to recalculate the resistor values. I think I got it right.
  • I’m getting the timing wrong. But I used my PICKIT2 as a logic probe and I seem to have the correct pulses at the correct timing. How accurate does the 64uS and the other timing need to be?
  • I’m connecting up the video output to my scart lead wrongly.
  • Something I didn’t think of yet :)

I really need an oscilloscope so that I can look at the video output in detail and work out what the problem is.

I’ll look at this again today. Yesterday I adapted an old scart lead by pushing solid core wire into the gaps in the connector and they kept falling out. It’s possible that what seemed like a good contact with my multimeter was in fact failing when I plugged it in so I’ll probably solder a proper lead today if I can be certain I got the connections right. It will certainly make testing less frustrating when the lead doesn’t fall apart every 30 seconds.

This is the output (Before the resistors that add the signals), top one is sync, bottom is video signal.

PCB / Soldering practice

I decided to make a new board to practice making PCBs and soldering SMD components. This uses a PIC16F883 ( I think) in SOIC configuration. I believe now it’s easier to use SOIC components where possible than traditional pin through hold ones as you don’t need to drill holes which are not too easy.

On my screen at least this comes out about actual size, if you click on it you can see if magnified and just how bad the soldering really is.

However it all worked first time which impressed me and I found that it’s really not very hard to make boards and solder small components so next I’m going to make something real with a proper box and everything.

There were two design flaws on the board though, both of the missing pull up resistors. So the switches don’t work which is rather annoying, and you can’t program the chip through the connector until you turn off “low voltage programming” which you can’t do until you can program it. I got round that my manually holding a pull up resistor in place until I’d programmed it first time and turned off LVP and then it worked. Also the capacitor to the left of the PIC chip is slightly off centre. It works ok so it’s not a problem but I need to do better. The pad is too big for it anyway.

Anyway, good progress. My soldering needs to improve a lot but I’ve proved I can do it.

Possibly future projects

A lot of what is written here is old and out of date now… Plans changed.
I’ll write up some of the projects I’ve worked on over the next few days but for now here are two of the things I want to make :-

  • A proper remote control receiver for my PC. I’ve made a small prototype one but I’d like to make one in a proper case and which fixes a few issues with the software on the one I made. In addition I’d like the keypresses it sends to be configurable using some kind of PC application.
  • I’d like to make a clock / thermometer  for my living room. I’ve seem some nice OLED displays I’d like to use for a display. I’d like it to have a nice alarm clock, and thermometer display. But also to record the temperature in a EEPROM so that I can draw graphs and get statistics about how hot my room is at different times of day. In addition (mostly as it will be sitting in my living room. I’d like it to have a USB interface to so I can occasionally connect it to my PC to upload the temperature data (I’ve actually made most of this except with a 2 line LCD instead of OLED as a prototype)
  • Network connected IR sender. I can never remember which channel SKY HD is on for example so rather than just pressing 170 or whatever on my remote control I have to go through pages of slow menus. I would like to have an IR sender which can change channels for me which has a web page interface and is connected to ethernet. That way I can use my android phone as a web browser and just “click” on the channel I want. I’m not sure how difficult ethernet / tcp/up is but I’ve seen some i2c chips which seem to handle quite a lot of it so it’s an area for more research.