Archive for October, 2007

Video over UTP

Friday, October 26th, 2007

I installed video surveillance system at my work place. Nothing special 6 color CCTV cameras, one computer with few hundreds of gigs storing about a month of h.264 video. But I had a problem with one camera. The distance from camera to computer is not very big, about 300 meters (~900 feet). But the problem was that cable must pass several storage and manufacture workshops. With very electrically noisy environment. Also, the ground potential in the ends of cable is different. So, I decided to use already installed UTP cables. There are lots of commercial solutions to transport video over UTP cable. But my budget was very small, in fact I managed to empty it before this UTP problems… :) I bought cheap, passive BNC to UTP video balloons. Connected… and it was great disappointment. Mine video baluns didn’t have galvanic isolation between UTP and coaxial cable. Also, the signal strength was very low and full of noise. This was my mistake- in fact, video balun is not simple 75 ohm to 100 ohm line transformer, but some auto-transformer. And the transformer rate is 1:1. don’t believe to all mystical distances adverted in balun description…

There were some problems to solve:
1. Galvanic isolation- to remove ground loop effect.
2. Convert asymmetrical coaxial cable to symmetrical and vice versa in wide frequency band. (50Hz…5MHz).
3. Cancel all possible interference from working devices in workshop.
4. Compensate loses in UTP cable.

The only solution is active amplifier. I selected old chip from Elantec (now Intersil) EL2044C (Low power, Low voltage, 120MHz Unity-Gain stable operational amplifier) from some video multiplexer. This chip is intended to use in video device, wide supply range (from 2.5V to 36V), output designed for 75 ohm video load.

Most complicated part in this design is transformer. It must be very wide frequency range. In transmitter side I used passive solution- I used that video balun. It will convert to symmetrical signal video output from camera without any additional devices. On the receiver size I build small box with PSU and video amplifier. May problem is transformer specifications- all internet is full of “buy it” solutions and no “make yourself”. I don’t know how many windings must be in the transformer and what size or core to use. So I decided to use “connect and test” version. Using spare UTP cable I connected “line emulator”. I had about 120 meters of cable, so I connected all pairs in serial to get 4×120, about half of kilometer of signal cable. Video source- DVD player. On other side TV. First transformer I selected made bad results- it was possible sometimes to catch video, but now colors and lot’s of other problems like shades. I connected oscilloscope to the end of cable and revealed, that there are lots of reflections in cable and high frequency part of signal is lost in transformer. Color in PAL is transferred using 4.43MHz frequency and all this color component is very low. I added some capacitors to increase gain in higher frequency, but this didn’t solve the problem.
Suddenly, while browsing the internet, I found some web-page about one man using transformer from old LAN card to transmit 10MHz signal over symmetrical cable. I grabbed old LAN card and used transformer… The “color” situation was better, but I’ve lost low frequency part of the signal… The final solution was a bit crazy: dual transformer. One for high frequency and other for low. Both transformers connected in serial. Don’t mix phases in transformer.

Final circuit diagram (schematics) of the amplifier:

Video over UTP

Upper transformer is from LAN card. Lowe one is some from some power supply- it was feedback transformer on ferrite ring.
I don’t remember real value of the capacitors. 100 ohm resistor near transformer is main line load. Capacitor is used to increase high frequency gain. 500 ohm trimmer is used to adjust the reflections in the cable. Horizontal 100 ohm resistor is less that 100 ohm. I don’t remember (about 47Ω). Transformers are 1:1.

5 kΩ trimmer is to adjust gain.

PSU is double voltage, +6V and -6V, made from 12V with synthetic ground.

CIS

Thursday, October 25th, 2007

At work, sometimes, we need to print some papers in color. So we need some cheap color printing solution. First we used old HP 970cxi printer, but now we need to print more. Original cartridges are very expensive, so we used refilled ones. It is very easy to fill color cartridge, just add some ink using top hole. There some more work with black ink cartridge- the hole must be closed with steel ball. But the cartridge is too small. So I bought more powerful printer for this- HP Business Ink Jet 1000 series. It is “semi- professional” printer with unmovable cartridges. The cartridges contains much more ink than moving ones. But I bought this printer having idea about CIS (continuous ink system). In some Russian site I even find instructions how to build it and how to disable ink cartridge chip. But then I decided to use already made solution and bought CIS system from China in eBay. For about $90 (including shipping and handling) I received full CIS system prefilled with ink. Here is the photo of CIS system in our printer:

CIS for HP1000

We already added ink to the system. Just pour some in to the bottle and that’s all! The only problem is with magenta color- some problems with ink head. I don’t know what is causing the problem: bad ink, bad pressure of ink, bad parking or just coincidence.

Paypal in Lithuania

Thursday, October 25th, 2007

Original post dated September 28th, 2007.

After about ten years of waiting, most popular online payment system is working in Lithuania. Few years ago we used Western Union online payment system, but it was closed. Meanwhile Paypal was afraid of Lithuanian hackers or our bank system. Now, from 28th of September, the system is working. You may donate any sum to support this web log using this image link:

Thank you for your support!

Cleaning tap filter

Sunday, October 21st, 2007

A bit offtopic, not very electronic post. Our tap water is full of lime (calcium). And this lime tens to grow on small tap filters, aerators. After some time I noticed, that the water stream is not very even, the bubbles are not so dense and small. After some more time the stream is skewed. The problem is very simple- lime on the filters. It is possible to find and buy new filters (aerators) in Aikada store (I often visit this company as I am responsible for IT in this company)… But coffee is better in Vitra company. :) So, I visited shop and noticed, that some aerators are missing in display. After some interrogation they confessed, that some visitor steal those small devices. So, I decided to describe how to clean all lime using environment friendly way.

lime on aerators

This recipe is usable even with such large device as cloth washing machine.
Collect all aerators (filters), other small parts covered with lime. These parts must be thermal resistant. Put all parts to electric kettle, add some water and some citric acid. About two full spoons for cup of water. Switch kettle on…

cleaning lime

After few minutes the stench from kettle inform, that everything is going fine. After some time, the stench disappears, and the water will get yellow color. Now rinse the kettle.

lime gone

The same recipe for washing machine- just add about one or two kg or citric acid to it and start the “hottest” cleaning program. And no need for expensive special washing materials, no Calgon… Use your saved money for more pleasant purposes.

This article is a bit “advert” type.

ATMEGA USB 006

Saturday, October 20th, 2007

It is time to use USB. After several unsuccessful experiments I found some working project in the internet. Maybe other project are working too, but only this one was usable and understandable for me. As I need not only binary compatibility, but compatibility in the source code level. I want to recompile all stuff by myself. In this project only USB Windows system drivers are downloaded from sourceforge web pages.
Why designing the PCB I looked to several other project and adapted my circuit diagram to accept several types of connections. With slight modifications, it is possible to use other firmware.

AVR USB LCD

So, the USB- Universal Serial Buss. This “universal” means that this system is multipurpose and more complicated. It is not only serial data transfer, but stack of procedures, drivers and other stuff to connect external devices to master unit using same buss. It is more complicated that old RS232 serial one and it is very hard to implement all features to simple device. Also, as this buss is “universal” globally, there are some limitations- every device must have unique identification. This identification is coordinated by some organization. This organization distributes VIN (vendor identification number) for money. We shall use free, testing numbers. All software is distributed under GPL/LGPL licenses, so fell free to use it. USB firmware is used from http://www.obdev.at/products/avrusb/index.html. VIN/PIN (also called VID/PID) is used from same source.

Also, LCD module is used to test this project.

There is small testing software for Windows to test the device. It allows to print text on the LCD and some other small command. The source code will be in the next post as I have problems with compiling it with my compiler.

20070922.zip.

ATMEGA USB 005

Monday, October 15th, 2007

There are lots of chips with serial control. Some of them use Philips I2C buss. There two data lines and two power lines to transmit all data. There DTMF encoders, switches, Dolby surround audio processors, multiplexers and many many other devices. Just open any TV set and you can find some- like TV tuner. ATMEL chip has build in serial interface, but it is called TWI. In my PCB there are two bigger SMD pads to connect I2C buss. Don’t forget to solder 10K pull up resistors.

FM75

For testing TWI bus I selected I2C temperature sensor. It is LM75 or any other clone. I am using small PCB from old plasma display panel with Fairchaild FM75 chip. It is smarter and more precise clone of original LM75. FM75 is backwards compatible with LM75. It has more precision and this means more data bytes available to read. At full precision it used 12 bits for temperature. In my software I used simplified algebra to convert 1/16 fractions to metric system. For more precise calculations, read FM75 and LM75 datasheet. And maybe AD7416 datasheet too.

FM75 ATMEGA16

I am using i2c.c from internet, from USB Tenki project. This project is very interesting, pay a visit to original Tenki web page for more advanced device. lm75.c is from same source. LCD modules are same as in older my web blog posts. When you connect your LM75 chip, don’t forget to check the device address- base address is the same, but user selected pins maybe connected in other way.

Programa: 20070919.zip.

With these chips and software example it is possible to build some thermostat project. But don’t write all controll stuff for ATMEL chip. Read the datasheet again and use LM75 thermostat option. Use ATMEGA only for control, display and setup.

ATMEGA USB 004

Sunday, October 14th, 2007

There is ADC in ATMEGA16 with 8 multiplexed inputs. This analog to digital converter have several interesting options. Here is abstract from datasheet:

• 10-bit Resolution
• 0.5 LSB Integral Non-linearity
• ±2 LSB Absolute Accuracy
• 13 – 260 μs Conversion Time
• Up to 15 kSPS at Maximum Resolution
• 8 Multiplexed Single Ended Input Channels
• 7 Differential Input Channels
• 2 Differential Input Channels with Optional Gain of 10x and 200x(1)
• Optional Left adjustment for ADC Result Readout
• 0 – VCC ADC Input Voltage Range
• Selectable 2.56V ADC Reference Voltage
• Free Running or Single Conversion Mode
• ADC Start Conversion by Auto Triggering on Interrupt Sources
• Interrupt on ADC Conversion Complete
• Sleep Mode Noise Canceler

The ATmega16 features a 10-bit successive approximation ADC. The ADC is connected to an 8-channel Analog Multiplexer which allows 8 single-ended voltage inputs constructed from the pins of Port A. The single-ended voltage inputs refer to 0V (GND). The device also supports 16 differential voltage input combinations. Two of the differential inputs (ADC1, ADC0 and ADC3, ADC2) are equipped with a programmable gain stage, providing amplification steps of 0 dB (1x), 20 dB (10x), or 46 dB (200x) on the differential input voltage before the A/D conversion. Seven differential analog input channels share a common negative terminal (ADC1), while any other ADC input can be selected as the positive input terminal. If 1x or 10x gain is used, 8-bit resolution can be expected. If 200x gain is used, 7-bit resolution can be expected.
The ADC contains a Sample and Hold circuit which ensures that the input voltage to the ADC is held at a constant level during conversion. The ADC has a separate analog supply voltage pin, AVCC. AVCC must not differ more than ±0.3 V from VCC. Internal reference voltages of nominally 2.56V or AVCC are provided On-chip. The voltage reference may be externally decoupled at the AREF pin by a capacitor for better noise performance.

Software is very simple. It just read data from ADC and prints the results to LCD module. With small change in the source (just uncomment fre lines) and it is possible to read data from all channels.

ATMEGA ADC

Changing value near text “Stepas” just indicate the cycle number (in default program version) or ADC channel number. And if this number is changing, we can determine, that software is still working :)

Sorftware, source code: 20070918.zip.

ATMEGA USB 003

Thursday, October 4th, 2007

Blinking LED is not very cool. And not very informative. But we can use LCD module. It is very cheap and available device. There are many types of LCD modules in the world. I am using most popular- HD44780 controller based alphanumerical module. It is 2 lines, 16 symbols. There are 14 or 16 pins on this module. Two extra pins are used for backlight. All other pins are used in 8 bit mode. As MCU pins can be used for more usefull purposes, we use 4 bit mode- every byte is transfered in two cycles. As MCU is very fast, we can not notice any lag here.
LCd module has selftest mode. When we connect power supply we must see upper line in black. If, not black square are here, try to adjust contrast using the only available trimmer on the PCB.

LCD AVR

LCD control software is from internet. After several experiment I selected Peter Fleury program. Other versions I tested had some hardware limitations. LCD connection is described in lcd.h file. No need to change lcd.cfile. But you can peek to it to find what procedures are in here.

Testing program is in test_lcd.c file. There is some push button routines here too. I am using jumper named “firmware” as button.

LCD AVR

If you power this device from computer’s USB slot, don’t pay attention to windows messages about unknown device connected to USB buss. We solve this problem later.

Software source and hex file for testing is here: 20070917.zip.

ATMEGA USB 002

Wednesday, October 3rd, 2007

Now we need to test PCB and MCU. To test this hardware we need to run some program. And to build program we need tools. I downloaded and used free software from internet. WinAVR package: http://winavr.sourceforge.net/. Also, I am using programmers notepad2. It is useful tool for MCU programmer.

First program is simple LED flasher. We will test if MCU is working and if all LED diodes are working and all pins of MCU is properly soldered. The only LED will be on all the time is power LED. As the photo is made with long exposure, it seams, that all LEDs are on. In real, they are flashing in binary way.

ATMEGA 16 LED flasher
(My printer is dead, so the PCB is ver ugly)

Software source and hex file: 20070916.zip

Software is very simple- we just set some pin to output and start counting cycle. Counting results are set to output pins. It is bad programming practice to put whole byte to several pins. In real world we need to alter only these bits we need to change- never put data to unused pins or input pins. But this program is for testing only.

Few comments. As I mentioned, mine LPT port is damaged, so I am using add on card. So, edit “makefile” for your programmer. You must check the “program”section. In my version there is few words to describe port address of my add on card:

program: $(PRG).hex
avreal32 -pBC00 -ab -e +$(AVREALMCU)
avreal32 -pBC00 +$(AVREALMCU) -ab -w -c $(PRG).hex -v

Just change -pBC00 to you port. Use “avreal32 -h” for more information. Or, if you use other programmer, replace these line according your programmer manual. Or, don’t use “make program” menu item in editor’s toolbar.

Also, some words for absolute beginners. Typically you can find information about simple things- everybody know how to do and they even don’t think, that somebody will not know how to do simple compile things. So, to compile software use “make all” menu item from programmers notepad or from CMD prompt. The computer will print lots of stuff on screen, but the main message is at the end:Process Exit Code: 0 and if you don’t see any ERROR.
Command “make clean” or Tools->[WinAVR] Make Clean, cleans all compiled files. So if you change something in the source, use make clean to be sure.

And the last menu item, make program or Tools->[WinAVR] Program we program firmware to MCU.

Few words about security bits. Carefully read original Atmel documentation. Sometimes these bits are mixed in various documents. Some tell that “set” means write 1, others- vice versa. It is possible to set MCU to “closed” mode and it will not be visible by programmer. As I am using “second hand” MCU I don’t need to change fuse bits. Mine bit looks like this:

Fuses
OSCCAL = AD, AB, A7, A8
BODLEVEL = 0
BODEN = 1
SUT = 2
CKSEL = F
BLB1 = 3
BLB0 = 3
OCDEN = 1
JTAGEN = 1
CKOPT = 1
EESAVE = 0
BOOTSZ = 3
BOOTRST = 1

As it is still working I am not changing any bit. Use this online tool http://palmavr.sourceforge.net/cgi-bin/fc.cgi

You can find HEX file in archive, so you can test hardware without any compilation.

ATMEGA USB 001

Tuesday, October 2nd, 2007

In older posts I mentioned, that I resoldered several ATMEL ATMEGA16 processors. So, I decided to build something usefull using this MCU. As this controller has more ROM and RAM, I decided to use only high level programming language- c. All software in these web pages are compiled and tested on my hardware. So, if you download something here and it is not working, first of all check your hardware and software. Then you may as some questions. Also, I will try to fix possible errors in software loaded from the internet. For example, simple error in LSB ans MSB handling caused one big program to be useless. This error stopped me for two days- it is very hard to find error in alien source code.

AVR USB

As I selected several independant projects in the internet I constructed universal circuit diagram and PCB. So almoust all software is working without modifications or just small modifications on PCB.
To build this project, you need: ATMEGA16 (maybe other mega will work too, but with change in software and harware), LCD module, few LEDs, some resitors, capacitors and 12MHz quartz. One trimmer is usefull too. Also some connectors for programming and USB.

This project will deal with various ideas. From simple LED flasher to complicated USB driven devices. It will be simple ADC, IR (infra red) receivers, I2C bus, LCD manipulating and etc.

After the software and hardware is tuned, user can build small PCB with everything designed for end product.

Circuit diagram (schematics) of the device:

AVR USB
(press on image for larger view)

Image of the PCB:
AVR USB

Circuit diagram and PCB layout for Eagle software .

MCU is programmed using Altera ByteBlaster MV
and AVREAL software. Also, I want to tell, that I damaged my default printer port in my experiments. So I am now using add-on card. This is important when using my software- the programming section of make file must be edited to your needs.

avreal/WIN32 - AVR controllers LPT programmer by Redchuk Alexandr
v1.25rev5 (Jan 15 2007 20:02:38) http://www.ln.com.ua/~real/avreal
bug-reports, suggestions and so on mail to avreal@real.kiev.ua