Search This Blog

Sunday, May 6, 2012

VGA Wiring, Fast 16 Bit Counters

   Here are a few brief notes/findings.

Cheap Wire
   Home Depot in the States sells Cat 5e riser network cable.  This is 24 AWG solid core wire.  There are 8 wires in the cable.  These work fairly well as jumper wires for breadboard.  Left in the insulator, they make really good connection wires.  There are eight of them, so that's a parallel byte or a full register.  In the case of the line follower I want, that's the six input lines and the power and ground.  One short of what is needed ( the LED on/off line ).  Here's the cool part: THE PRICE!  A 20 foot roll of a single wire at 22 AWG at Radio Shack is a bit over $8.00 USD.  The Cat 5e Riser ( not Plenum ) cable is $0.18 per foot.  And that's for eight wires.  The stuff can be used like Kleenex at that price.  Plenum cable is not much more expensive at about $0.59 per foot.  This stuff is going on almost everything project from now on.

VGA
   A VGA driver is the next experiment on the docket.  Lucid Science has a great tutorial.  It's written for an Atmel AVR in assembly.  With a datasheet and maybe a tutorial, it's pretty easy to adapt to a PIC.  The main problem with the PIC is speed.  Even with an 18F microcontroller running at 96 MHz with PLL, the processor gets 48 MHz from that.  Each instruction takes four clocks, so the effective MIPS is 12.  This is slow and it makes conversion a bit tricky.  It should be possible to get a test display of Lucid Science's RRGGBBII palette to work.  Even with SRAM, the operable resolution for graphics will be pretty low, though.  Still, it should be fun to try.

   To that end, I wired up a VGA female cable, using some newly purchased Cat 5e cable.  As a reminder to myself:

Pin Wire Color(s) Value
1 Orange Red
2 Green Green
3 Blue Blue
5,6,7,8,10 White/Green
White/Blue
White/Orange
Ground
13 Brown Hz Synch
14 White/Brown Vt Synch

 Fast 16 Bit Counter
   Now for some cool news.  The 18F series has made some big improvements.  First, you can avoid the Read-Modify-Write problem by writing directly to the Latch registers for the ports.  Next, they include a new SFR, WREG.  This shadows the W register.  Unlike the W register, it allows direct math and manipulation.  Mathematical operations on the WREG can be interchanged with W reserved operations like movlw and addwf.

   Tonight proved two other operations unknown to me.  First, it is possible to maintain a 16 Bit increment ( an increment over 2 bytes ) in only 2 instructions.  The W register must be zero for this to work.  The lower byte is incremented as usual with incf:
   movlw 0x000
   incf   myRegLow,F
Then, the magical addwfc is invoked.  This adds the W register ( value zero ) to the higher byte as well as the Carry bit from the last operation ( the incf ).  This effectively increments the higher byte only when the lower byte overflows to 256 ( ie, back to zero ).
   addwfc   myRegHigh,F

   Wait, wait.  Don't order yet!  Now how much would you pay?  If you act now, we'll throw in the fact that you can do mathematical operations directly on the Latch registers! This means that if the SRAM address for VGA output needs to be incremented very quickly through 16 bits worth of addresses ( and it does ), it is possible.  If LATB holds the lower address byte and LATD holds the higher byte:

    movlw   0x000
beginAddressLoop:
    incf       LATB,F
    addwfc LATD,F
    bra       beginAddressLoop

This, of course, is nothing like what will be used.  It does illustrate the point.  These little discoveries will drastically reduce the cycles needed for the various operations needed for VGA output.




No comments:

Post a Comment