Navigation
Home & news
Random page
All pages
Site search:
Databases
Fortune cookies
Fotogalleri
Haikus
SID themes
Page collections
Chip music
Hardware projects
Music downloads
Obfuscated programming
Opinion / blag
Piano music
Sane programming
Scene productions
SID related pages
Software downloads
Video downloads
Featured pages
Allt under himmelens fäste
Binary Art
Brainfuck
Chimney claw
Chopin romance
Craft
Fratres
Freecell
Hardware chiptune
Leet, sweet, petite
Nymphaea
One man and his piano
Paraforce
Pot plant monitor
Remote control
Reverberations
SID septet
Stranded
Syntax highlighting
Townwoofer
Warpfruit
Forum
Register
Log in
Latest comments
Feedback
  • Swedish content
  • Offensive content

Craft

Craft is a demo running on its own minimalistic demo platform. The demo platform is based on an ATmega88 microcontroller.

Having successfully built a soundchip out of a microcontroller together with my friends in kryo, I wanted to tackle the greater challenge of generating a realtime video signal along with the sound. This is the result:

Download

  • lft_craft (Original video clip, Xvid, 89.4 MB)
  • lft_craft_src (Schematics, firmware binaries and source code, 70.5 KB)

Scene reaction

Craft won the Console / Real Wild compo at Breakpoint 2008. I will never forget the overwhelming reaction from the audience!

Here's the Pouët page for Craft.

How does it work?

Just like your average 80's home computer, the entire design is centered around the timing of the video signal.

A typical VGA-based, low-resolution CRT monitor will redraw the screen 60 times per second using an electron beam, which is sweeping across the screen one line at a time. TFT monitors work differently, but the VGA signal is still based on the idea of an electron beam. Timing is crucial: One display line takes 24 μs, and is followed by a 7.75 μs break called the horizontal blanking period. After 480 such lines, there's a longer break (1428.75 μs, equal to 45 full display lines) before it all starts over. Two digital signals are used to synchronize the sender (graphics card, custom demo hardware etc.) and the receiver (monitor). They are called the horizontal sync and the vertical sync signals. It's OK to deviate a bit from the standard timing values as long as you keep the sync signals steady.

The microcontroller is clocked at 20 MHz. If we convert the figures above into clock cycles, we get 480 cycles of visible pixels, 155 cycles of horizontal blanking and 45 full display lines worth of vertical blanking — but during those lines you need to keep generating the horizontal sync pulses. Due to rouding errors, we get a frame rate of 59.99 Hz, but that is well within the tolerance range of a computer monitor.

Music

Sound is generated during the horizontal blanking periods. That gives a sample rate of 31496 kHz. Of course, only the really timing critical part (waveform generation) is performed during the horizontal blanking. Melody, rhythm, amplitude envelopes, arpeggios etc. are handled by a playroutine which gets called once for every video frame, during vertical blanking.

There are four sound channels in total, each with its own fixed waveform. The waveforms are 4-bit triangle, 50% pulse, 75% pulse and white noise. The noise is generated by means of a 15-bit shift register. The volume of each channel can be individually controlled, except for the triangle channel, which is always playing at full volume. This minimalistic softsynth was of course inspired by the NES sound chip.

Video

Apart from the sync signals mentioned above, a VGA signal contains three analog voltage lines — red, green and blue — that vary between ground and 0.7 V during the visible parts of the video frame. As you can see in the schematic below, I perform a two-bit digital-to-analog conversion for each of these signals, using R-2R resistor ladders. That way, the software can change the current colour in a single clock cycle using the out PORTC,register instruction.

In addition to this, I've hooked up a couple of diodes and a PNP transistor in such a way, that when the MOSI pin is low while the OC2B pin is high, the three color signals will be pulled to a high voltage, corresponding to white. This is used to generate high resolution scroll text: The MOSI pin is connected to a shift register internally in the AVR (it is typically used for serial data transmission), and this shift register can be programmed to emit a sequence of 8 bits with a single instruction, thus offloading the CPU. Smooth scrolling is then implemented by inserting variable delays before and after each display line, but that alone is not enough, because characters would appear and disappear suddenly at the edges of the screen. So additionally, the output comparator connected to timer 2 in the chip is set up to create a visibility window using the OC2B pin.

Schematics

This is how it all fits together, hardware-wise. If you are interested in the physical layout used on the breadboard, you can find it along with firmware and source code near the top of the page.

The variable 1K resistor can be used to adjust the brightness of the scroll texts.

                                 .---[ 1K ]-+------- E (PNP) C -------------------+---+---.
                                 |    /|\   |            B                       _|_ _|_ _|_
                                 |     `----'            |                       \ / \ / \ /
                                 |                       |                       --- --- ---
                                 |       .---__---.      |                        |   |   |
               (to programmer) --- RESET |        | PC5 ----[ 442 ]-----------+---+---|---|--- Red
                                 |       |        |      |          .-[ 220 ]-'       |   |
                              (n.c.) PD0 |        | PC4 ----[ 442 ]-+-[ 442 ]--- GND  |   |
                                 |       |        |      |                            |   |
            .----------+-[ 2K ]----- PD1 |        | PC3 ----[ 442 ]-----------+-------+---|--- Green
            | .-[ 1K ]-'         |       |        |      |          .-[ 220 ]-'           |
            | `--+-------[ 2K ]----- PD2 |        | PC2 ----[ 442 ]-+-[ 442 ]--- GND      |
            |    `-[ 2K ]-- GND  |       |        |      |                                |
            |                    `- OC2B |        | PC1 ----[ 442 ]-----------+-----------+--- Blue
            `---[ 1K ]-.                 |        |      |          .-[ 220 ]-'
              .--------+-[ 2K ]----- PD4 |        | PC0 ----[ 442 ]-+-[ 442 ]--- GND
              |                          |        |      |
              |                      VCC |        | GND  `-[ 1K ]-.
              |                          |        |               |
              |                      GND |        | AREF (n.c.)   |
              |            22pF          |        |               |
              |        GND -||--+- XTAL1 |        | AVCC (n.c.)   |
              |         20 MHz [ ]       |        |               |
              |        GND -||--+- XTAL2 |        | SCK -------------- (to programmer)
              `-[ 1K ]-.   22pF          |        |               |
              .--------+-[ 2K ]----- PD5 |        | MISO ------------- (to programmer)
              `-[ 1K ]-.                 |        |               |
              .--------+-[ 2K ]----- PD6 |        | MOSI ---------+--- (to programmer)
           +  `-[ 1K ]-.                 |        |
     ----)|------------+-[ 2K ]----- PD7 |        | OC1B ------------------------------------- HSync
Audio   10uF                             |        |
     --------- GND            (n.c.) PB0 |        | PB1 -------------------------------------- VSync
                                         `--------'

If you want to learn more, I suggest you dive into the source code, starting with boot.S, mainloop.S and asm.S. The most interesting part is probably the cycle-accurate code in asm.S.

Posted Thursday 27-Mar-2008 20:33

Discuss this page

Disclaimer: I am not responsible for what people (other than myself) write in the forums. Please report any abuse, such as insults, slander, spam and illegal material, and I will take appropriate actions. Don't feed the trolls.

Jag tar inget ansvar för det som skrivs i forumet, förutom mina egna inlägg. Vänligen rapportera alla inlägg som bryter mot reglerna, så ska jag se vad jag kan göra. Som regelbrott räknas till exempel förolämpningar, förtal, spam och olagligt material. Mata inte trålarna.

Anonymous
Fri 28-Mar-2008 19:31
I bow down in awe and wonder. This is just amazing...
Anonymous
Sat 29-Mar-2008 05:23
"The MOSI pin is connected to a shift register internally in the AVR ... and this shift register can be programmed to emit a sequence of 8 bits with a single instruction, thus offloading the CPU."

Hey, that's a *really* neat trick--makes me wonder what I could use that for. :-)

--Phil. (http://code.rancidbacon.com/)
Anonymous
Sun 30-Mar-2008 10:29
Fantastic work! You really deserved the victory at BP! :)
Anonymous
Mon 31-Mar-2008 10:46
Great! Best I've done on AVR was 4-chn 20kHz MOD-player, no graphics there ...
Anonymous
Mon 31-Mar-2008 13:03
Great job on the article! Congratulations for being posted on Make!
Anonymous
Mon 31-Mar-2008 15:01
You brought back such wonderful nostalgic memories for me.
A job really well done. :-D
Anonymous
Mon 31-Mar-2008 16:13
Seriously awesome work! Bet there isn't a free word left!

Jeff
warrantyvoidifremoved.com
Anonymous
Mon 31-Mar-2008 16:41
Great job! That gives to me a lot of good memories about the 80's computering styles.
Anonymous
Mon 31-Mar-2008 21:23
Really great old school demo :)

Thumbs Up !!!

Keep going, it's really awesome !!!!
Anonymous
Mon 31-Mar-2008 22:18
Great work! Nice to realize again how much can be done with a simple 8-bit processor.
Anonymous
Tue 1-Apr-2008 14:38
Wow that is amazing.

Would using 2 or 3 chips like this produce even more impressive results?

I notice there is some horizontal jitter in the lava field section, between 1:42 and 2:02.
I guess you are running short on the time needed to do the calculations accurately.
Anonymous
Tue 1-Apr-2008 21:28
beautiful work!
Anonymous
Thu 10-Apr-2008 22:44
Very great work. Absolut great demo and hardware... Big greetings, Chainsaw. (www.chainsaw72.ch.vu)
Autoscatto
autoscatto
Wed 16-Apr-2008 08:51
Hola! I`m working (for now copying =]) on your project but i have problems... What kind of diode do you use in this board?
Thanks for your good work!!! (and excuse my bad english)
lft
Linus Åkesson
Wed 16-Apr-2008 16:39

Autoscatto wrote:

Hola! I'm working (for now copying =]) on your project but i have problems... What kind of diode do you use in this board?
Thanks for your good work!!! (and excuse my bad english)

Glad you like it! =) I'm using 1N4148 diodes, but anything with a forward drop somewhere around 0.7 V should work.
Anonymous
Wed 23-Apr-2008 08:46
Really impressive. I'll be showing this to friends at KTH (kth.se), and probably build one or two. On my main lab board I have an AT90USB chip, which has to run at 16MHz to support USB, so I'd guess that means lower horizontal resolution. I think an Xmega could be really impressive, using its DMA engine to output high resolution colour signals.
-- Yann Vernier / LoneTech
Anonymous
Wed 30-Apr-2008 06:24
I am amazed and impressed. Bit-banging VGA and using the SPI port as a video shifter is too clever... wow. Does Atmel know about this demo of yours?
Anonymous
Thu 1-May-2008 07:45
the author should have drawn schematic more legibily using some circuit drawing software instead of this lousy ascii patterns

arun -
India
lft
Linus Åkesson
Thu 1-May-2008 12:21
the author should have drawn schematic more legibily using some circuit drawing software instead of this lousy ascii patterns

arun -
India

If you want to, feel free to draw the schematic using such a program, and I'll put it on the page.
Anonymous
Thu 1-May-2008 16:19
great work!
Anonymous
Thu 1-May-2008 23:54
I've been working on something simular for a few months (on and off, when i got the time) but i have not yet taken the time to create a full demo. (see www.electronicspit.com)

I must say this is a very good demo. Great work on the hardware too !
lft
Linus Åkesson
Fri 2-May-2008 09:46
I've been working on something simular for a few months (on and off, when i got the time) but i have not yet taken the time to create a full demo. (see www.electronicspit.com)

I must say this is a very good demo. Great work on the hardware too !

Yeah, I've already got it bookmarked. =) Some day I'll probably attempt something similar. The tradeoff between VGA and composite is of course that the VGA signal has a higher pixel clock, but in the composite signal you've got to modulate the colour signals. But when one tries to build something generic, such as your console, one needs external ram, and then it's not such a big deal to add further external components.
Anonymous
Sun 4-May-2008 21:48
Great job !!! my hobby is AVR's and bascom avr (too slow to done that things) but in my opinion you must show that fantastic work to atmel and you can win/get some gadgets from them for that fantastic work ! :)

Best Regards
George2002 from Poland
Anonymous
Wed 7-May-2008 16:06
Nice job :)
Will it run on ATMEGA8 overclocked to 20MHz?
Any hardware/registers specifed only for ATMEGA88 are used there?