2013-09-21

Video on oscilloscope

My friend sent me this video a few days ago:



And I immediately wanted to do the same, but it's a huge project if done properly. It has a ILDA interface/driver, high-speed custom DACs, etc.
So I tried a simple alternative - creating a raster monitor from oscilloscope.

Here is the idea:
  • Put oscilloscope to the X-Y mode
  • Take a standard composite video (from DVD player in my case)
  • Separate horizontal and vertical sync signals from the composite video
  • Use these sync signals to generate two saw-tooth signals for raster. Vertical sawtooth (frame signal) scans top-bottom and horizontal sawtooth (line signal) scans left-right.
  • With these two signals I should get a raster/white screen on the scope
  • Assuming that I'll be fine without gray shades, just black and white image
  • Keep a raster running all the time, but when the beam is supposed to be passing over the black area then quickly change the horizontal (or vertical?) signal to the constant voltage. But choose this voltage to cause the beam to jump to the outside of the scope screen. This would form a dark spot.

This sound simple and could be done without microcontrollers, but using just a handful of analog ICs.
The only tricky part could be to separate sync signals from the composite video. I used to repair TVs a long time ago and vaguely remembered that it used to be a specialized IC to do exactly that. Sure enough google remembers it better than me: LM1881 Video Sync Separator

Here is the adapter schematic:


Horizontal sawtooth signal generated by R1, D1, C2 and buffed by the U1. The signal turned on/off by the analog switch U2A.
Vertical sawtooth signal is generated by the R6, D2, C5. It is inverted by the U2B, so it actually becomes an inverted sawtooth. This is because in the oscilloscope world higher voltage causes beam to move up, but TV scans top-bottom.
U4 is a comparator to decide when it is time to turn the beam off (based on the brightness). Actually it's not a "turning the beam off", but instead it disconnects the horizontal sawtooth signal from the scope input, which is equivalent to applying 0V to the input. This causes the beam to move to the left, beyond the scope screen, so the beam is not visible.
The alternative solution would be to use scope's blanking input (z-axis) to turn the beam off, but I thought that it'll be too much like a standard TV.

А few pictures/oscillograms to illustrate how it works. The source video were paused at this frame:


Below I am displaying both channels in standard scope mode (not X-Y).
The bottom sawtooth is vertical channel. I am triggering on the falling edge of this signal (vertical retrace).
The lame picture above the vertical signal is my horizontal trace.
The bright line just above the vertical trace signal is where my horizontal trace parks for the "beam off" period.



The same as above, just zoomed into the highlighted area (head).



And this is the result, playing the same video as the original project (touhou - "bad apple"):



Note: it looks like the video is losing frames around 0:30, but this is from the original video and have nothing to do with my adapter.

Rotary Dial for digital age

As I remember good-old rotary dial phones have been around since forever. And it is used to be a part of the everyday life, like dragons during medieval period. But like dragons, all of a sudden all these marvelous ancient devices just disappeared one day. I was lucky to find one of these dinosaurs at the local flea market:


I was eager to try it out, but unfortunately I don't have a home phone line anymore. I hook it up to my Voice Over IP (VoIP) adapter that I haven't used in years. And it almost worked! Well, it rings like it is supposed to - waking up dogs and babies in a 2 block radius and I could have a pleasant conversation over it, but I can't dial out. I hear a dial tone, but it ignores the number I was trying to dial.

The problem actually is not a phone - there is nothing could go wrong with it, ever. It's probably bullet-proof and could easily survive a minor nuclear apocalypses (haven't tried it, it is in my todo list). The problem is in my Voice Over IP adapter, it's not compatible with "ancient" rotary-dial phones. It designed to work only with (well, also vintage) push-button phones.

Ironically, rotary dial (or pulse-dial) is actually digital protocol, and is supposed to be closer relative to VoIP than "modern" push-buttons phones. The later ones were using analog encoding to transmit digits. This process has a fancy name: Dual-Tone Multi-Frequency Signaling (DTMF).
And the rotary dial is pure digital - transmitting numbers as a sequence of on/off pulses. One pulse correspond to digit "1", two pulse - digit "2", etc; Ten pulses represent digit "0".

Of course I could get another VoIP adapter that supports pulse dialing, but this would be too easy.
Instead I decided to make my own pulse-to-DTMF converter.

I had a few Atmel AVR microcontrollers lying around and using them to generate DTMF signal should be trivial. Obviously, it's been done before and I found Atmel application note to do exactly that. There is nothing special there, just using a PWM (the same method I used to play audio on the TI Launchpad) to generate analog signal. The only difference is that I am not using any external memory here. DTMF consists of just two sinusoidal waves, so we have to store one period of the sin wave and it is small enough to easily fit to the microcontroller's internal memory.

As I mentioned before, reading pulses from the phone is very simple, it's already digital, just count them up - and bam you get your digit.

Here is a a test setup with my adapter still on the breadboard



From left to right:
  1. WiFi to Ethernet converter. Just because my VoIP adapter doesn't have a WiFi and I don't like having Etherent cables everywhere
  2. VoIP adapter. I had the old Cisco/Linksys PAP2
  3. Phone (kinda obvious)
  4. Breadboard. Schematic below:

Phone line voltage in the "on-hook" state (confusing term? it seems to be originated when you are supposed to keep the earpiece on the hook and "off-hook" it in order to answer the call).

Back to the voltage,  so the "on-hook" voltage is quite high, around 48V DC and even higher (around 90V AC) during the ring. I decided to connect my board after the phone switch, so I am getting the power only when the phone is in the "off-hook" state (means handset is not on the phone).

In the "off-hook" state, line voltage is supposed to drop down to around 5V DC, which is perfect for my AVR, but I still added a 5.1V zener diode D1 just in case.

Rotary dial module is disconnected from the phone circuit and connected to my adapter only. The purpose of the connection between pins F and RR is to make phone think that the dial is still connected.

I am generating DTMF/PWM signal on the AVR pin 5 and feeding it to the emitter follower Q1 via the low-pass filter (C1, R3).

If you are curios, you can grab an AVR source code here.

Here is the video testing the adapter

During the test I ran into into the interesting issue. I noticed that AVR power consumption at the power-down mode is much higher than I anticipated (~500uA instead of ~10uA). After poking around I traced the issue to the debugWIRE interface. I were using debugWIRE to download and debug code on the AVR. But apparently debugWIRE draws a lot of current (~500uA). Disabling debugWIRE via fuses and using ISP instead solved the problem.

Last steps were to wire adapter on the perforated board.




And mount it inside the phone (thank you again, hot glue)



Done! Just put the cover on. Obviously it looks exactly the same as before modifications.


Next steps. I guess there is none. Well, maybe to record how this phone rings and use it as a ringtone.

2013-07-13

Aiding my horrible handwriting with Drawing Bot (Polargraph)

People who know me probably noticed that I have a pretty bad handwriting skills. Recently I even realized that apparently there is a  pretty scary word for my case: dysgraphia. Fortunately I was growing up long enough ago when this word hasn't been discovered yet, so this diagnosis did not affect my life. Few times I probably even benefited from it when my teachers couldn't figure out my scrawls and assumed that I was trying to write something deep-thoughtful.

Once upon a time when I was struggling to write something on the whiteboard and my colleagues were trying to read my hen-tracks I realized that I just need a whiteboard robot to help me.

My first idea was to build something like a plotter on the wall: two vertical slides on the side of the board and horizontal slide with dry-erase marker:

Well, this looks way too complicated. So maybe make it simpler: make it a polar coordinated plotter - a pivoted bar mounted top-center with a marker sliding along the bar:


Luckily, before I began my adventure I decided to use my favorite search engine to double-check that no one else is doing anything similar (I am so unique so I must be the only one who ever thought about it, like ever).

Well, unfortunately I am not that original, there are quite a few similar projects and they found even easier way of doing it:


Yes, this thing (beaded cord) - you usually pull it down to turn lamp on/off or to open/close blinds. So instead of having rigid slides they are using flexible cords to position gondola with the marker:


Well, at this point I should probably just shame myself and stop thinking about drawing robot since it already exists and I don't even have any plans to improve it. But I liked the idea so much so I decided to make a replica of such a machine.

After digging a little through similar projects I found the awesome one - Plargraph. It's an open-source project, well developed and based on the popular Arduino platform which I am already familiar with. Although, I didn't want to spend much time on it, so decided to make it kinda ghetto-style.

I started with beaded cord which I got from a local hardware store. Based on the size of the balls and links between them I printed two spools on the 3D Printer and mounted spools to the shafts of the stepper motors. Rest of that supposed to be simple: just grab a motor driver board - Motor Shield, dremel a gondola (old CD), hot-glue an RC servo to lift pen off the whiteboard, program Arduino with Polargraph code and ... realize that my motors are not compatible with Motor Shield.

The problem is my motors are pretty standard NEMA 17 steppers with very low internal resistance and designed to be driven by a special driver. This driver is supposed to measure a motor current and disconnect power source when current reaches a limit, current starts decreasing and driver turns power source back on and this on/off show repeats 20000 times a second or so. But the Motor Shield is pretty dummy, it doesn't have a current feedback, it would just turn full power, overheat and set itself on fire (haven't tried that, just guessing).

I didn't want to get a proper motor driver, I just wanted something quick. I ended up using a lab power supply to reduce motor voltage to ~3V which provides enough current for the motors without overheating the Motor Shield.
Note: It's not a good idea in many aspects, primarily because the Motor Shield is based on the L293 chip that has minimum voltage requirements of 4.5V.

Here is a video of one of the first tests:


At this point I didn't want to spend any more time on it and brought my Polargraph to work. Here is another video, drawing DMC logo:

Couple weeks later I got an excellent stepper motor driver - Allegro A4988 and finally got rid of lab power supply and replaced it with an old laptop AC adapter (it has a standard 19.5V DC output). I also had to slightly modify Arduino code to communicate to the Allergro chip instead of Motor Shield.
Note: Allegro chip is tiny and it's really inconvenient to solder (QFN package, 5x5mm), to save a hassle just get it on the breakout board.

Next steps. I also attempted to make it wireless (between host PC and Arduino), by adding a Bluetooth module to the Arduino side. But ran into some issues of how the communication protocol is implemented (it's very sensitive to delays). Maybe I'll improve it later.

Happy drawing!