Composite video from ARM Oct 26, 2016

Some weblog posts tend to take me further away from the usual topics. No worries… it’s just that I want to explore some “outer edges” to better understand complexity & speed trade-offs between µCs and FPGAs.

So… let’s generate a video signal with a µC!

This is the HyTiny-based STM32F103 RF Node Watcher I used before, re-purposed here to generate a composite video signal.

Black-and-white composite video is very easy to generate – it needs just two output pins and two resistors. There’s an amazing TVout project for Arduino to show how.

In this case, I want to use ARM and Forth, as a coding exercise and to find out about the performance of this setup. It took a little tinkering to get all the timing loops right:

omode-pp pa2 io-mode!  \ vout
omode-pp pa3 io-mode!  \ sync

: zero  pa3 ioc! pa2 ioc! ;
: black pa3 ios! pa2 ioc! ;
: white pa3 ios! pa2 ios! ;

: zr-us ( u -- ) pa3 ioc! pa2 ioc! us2 ;
: bl-us ( u -- ) pa3 ios! pa2 ioc! us2 ;
: wh-us ( u -- ) pa3 ios! pa2 ios! us2 ;

: pulses ( u -- ) 0 do zero 2 us2 black 29 us2 loop ;
: vsyncs ( u -- ) 0 do zero 29 us2 black 2 us2 loop ;

: bbb  0 do  4 zr-us  6 bl-us  1 bl-us  48 bl-us  1 bl-us  4 bl-us  loop ;
: www  0 do  4 zr-us  6 bl-us  1 wh-us  48 wh-us  1 wh-us  4 bl-us  loop ;
: wbw  0 do  4 zr-us  6 bl-us  1 wh-us  48 bl-us  1 wh-us  4 bl-us  loop ;

: try  \ draw a big rectangle
  begin
      5 vsyncs
      5 pulses
     32 bbb
     16 www
    236 wbw
     16 www
      2 bbb
      4 pulses
  key? until ;

try

The full code is here, with 4 different tests. The us2 function is a modified microsecond delay which doesn’t use the systick timer, because all interrupts have to be disabled to get a glitch-free signal.

There’s quite some overhead in the current ios! and ioc! routines to set and clear an I/O pin. This limits the attainable horiontal resolution, since each scan line has to be generated in exactly 64 µs.

Since the signal is being generated with an infinite loop, the µC is fully consumed by this activity. To make this usable would require using interrupts, freeing up cycles during the flyback “blanking” intervals.

But that was never really the point of this exercise – as will become clear next week!

Weblog © Jean-Claude Wippler. Generated by Hugo.