Dienstag, 18. Oktober 2016

Snakes, Neural Networks and Genetic Algorithms

Surfing around the interwebs I stumbled upon genetic algorthms, which inspired me to create my own little java applications. I won't write a lot today, instead, I made a little video to try to explain what I did. Enjoy!


- Marv

Freitag, 11. März 2016

Splitters Suck - Adventures with Optical Audio, Part III

This is part three of a multi-part series, click here to read part one or here to read part two.

After I upgraded my PC subwoofer to optical audio input, I still had a problem: My sound card has only one Toslink output. But there is remedy! Toslink splitters! Hooray!


Those things have one input and two outputs, and entirely optical (passive). However they have a major flaw: They do not work! The plug conncetions and the prism have really bad optical characteristics and too much light is absorbed. At first, I thought the fibers were to bad, but I tried short (1m) high quality cables and experienced the same problem. Even cleaning the connectors didn't make it better, I figured out that one of the outputs was stronger than the other, it barely worked, the other one didn't work at all. A piece of junk.
You can buy active splitters, but the cheapest I found were around 50 euros, way too much money. I flirted with idea of building my own optical splitter, that would mean another box that needs power and an AC adapter though.
A lot simpler is upgrading the sound card to two optical outputs! I had still some Toslink emitters around, and I didn't really need the optical input of the sound card, so why not switch an emitter for another sender? The modification is quite simple: Just desolder the receiver, hot glue the emitter at the same place upside down (you cannot use the same pins!) and wire it parallel to the existing emitter. Just an aditional 100 nF capacitor and an 8.2 k resistor is needed (according to the datasheet i found).

Quite simple, but effective. Working like a charm.
- Marv

Donnerstag, 10. März 2016

Adding S/PDIF to Analog Hardware - Adventures with Optical Audio, Part II

This is part two of a multi-part series, click here to read part one.
The solution I presented last time was working pretty well for a few years. Someday, I upgraded my PC with a Radeon 7770 graphics card. Graphics were great, the sound horrible. - The sound? What does that have to do with a new graphics card, you might ask. Well, unfortunately, either due to noise on the power/signal lines on the main board or due to electromagnetic fields, each time the graphics card processes a frame, I heard a horrible ticking on my speakers. The rate and volume changed with the framerate and the complexity of the tasks. The noise however wasn't present on the digital outputs, only the 3.5 mm jack was affected. So why not upgrade the PC speakers to toslink?

No sooner said than done! I opened up the subwoofer and looked for a nice place where I could fit in another digital to analog converter, which I had to slightly modify:
I didn't want to use the RCA jacks since these need a lot of space. A convienient connector was already present to connect the analog input PCB to the main amplifier board, I just the same one on the bottom of the converter to be able to just switch a single plug:


Since the space on the back plate is really limited, I had to mount the converter flat on the sheet metal. Therefore, the optical input had to be mounted upright:



The last thing to do, was to make a rectangular hole in the plate. I predrilled with 3 mm, then drilled an 8 mm round hole. With a file I made the hole rectangualar:


And finally, lots of hot glue to mount it securely:


And it works! Ok, to be honest, these modifications wer nothing special, but sometimes the simple way is enough. There is one problem though - my sound card has only one optical output... But that's a story for next time.
- Marv

Montag, 25. Januar 2016

Noisy Converters - Adventures with Optical Audio, Part I

I'm quite positive that everyone who once tried to transmit analog audio over a long distance encountered sound quality issues in some form. When I wanted to hook up a pair of speakers across the room to my computer, I went for a digital solution right away: TOSLINK. A simple standardized audio interface using a fiber optic cable. Its signals are identical to S/PDIF, an elektrical digital audio interface. Both TOSLINK and S/PDIF have gotten pretty common nowadays in all kinds of audio equipment such as TVs, CD players, HiFi systems and even PC sound cards. No interference, crystal clear sound, no path loss. Sounds great so far? (Pun intended)
I bought a cheap sound card for my PC with optical output, a 10 m fiber cable and a digital to analog converter.


However, whenever the converter doesn't receive an optical input, such as when the sender is turned off, it started to output ugly noise. There wasn't really much you could do against it than shutting the converter off when my PC was off. So I made a little device with a monostable circuit triggered by the optical signal that switched to power for the converter on whenever there was an active input and shut it back of when the input was inactive. The circuit was very simple, just a TOSLINK receiver, a monostable cuircuit and a transistor. Since I also had to feed to signal trough to the converter, I used the S/PDIF coax input of the DA-converter rather than to TOSLINK in order to save an optical splitter. And it was awesome in its simplicity and it also did its job.
However there is a reason why I talk in the past tense about this device and I don't have pictures of it: It isn't alive anymore because it had a major drawback: Start up clicks on my speakers. Nasty, loud clicks. And that wasn't caused by my circuit, it was the converter itself. Probably uncharged decoupling capacitors at the output. You could use some relays  at the output of the converter to disconnect the speakers until the caps are charged, but that's a third circuit and a third box. I decided to take another path in order to combine all three circuits (the power switch, the converter itself and the relays) into one - and it turned out that with the ability to disconnect the speakers from the converter output, the power switch circuit becomes obsolete.
Rather than using relays I used an analog multiplexer CD4052 and a charge pump for a negative supple voltage, since the output is AC centered around ground. An ATtiny84 does the switching for the charge pump and decides whether to turn on or off the output. A 10 k resistor is used to keep the outputs at well defined level when shut off.



Here is the code that runs on the little AVR. Basically just 50% duty-cycle high frequency pwm on the charge pump for the charge pump and an interrupt triggered "monostable" circuit with predefined time constant. I know that the same thing could also be achieved by a smaller microcontroller, the ATtiny84 was the smallest I had lying around though.


//pin definitions: 
const byte pwm = 7;  
 const byte signalin = 2;  
 const byte sel1 = 1;  
 const byte sel2 = 0;  
 const unsigned int tresholdtime = 64; // 1 ms  
 bool volatile triggered;  

 void setup(){  
  pinMode(pwm,OUTPUT);  
  //timer0 multiply by 64  
  //millis runs 64 times as fast.  
  TCCR0B |= (1<<CS00);  
  TCCR0B &= ~((1<<CS01) | (1<<CS02));  
  analogWrite(pwm,128);  
  pinMode(sel1,OUTPUT);  
  pinMode(sel2,OUTPUT);  
  digitalWrite(sel1,HIGH);  
  digitalWrite(sel2,LOW);  
  pinMode(signalin,INPUT);  
  PCMSK0 = (1 << PCINT2); //Enable interrupts on PCINT2 (signalin)  
  GIMSK = (1 << PCIE0);  //Enable interrupts period for PCI0 (PCINT7:0)  
 }  

 void loop(){  
  triggered = false;  
  sei(); //enable interrupts  
  delay(tresholdtime); //not nice but works  
  if (triggered){  
   digitalWrite(sel1,LOW);  
  } else {  
   digitalWrite(sel1,HIGH);  
  }  
 }  

 ISR(PCINT0_vect){  
  cli(); //disable interrupts  
  triggered = true;  
 }  
I happened to be able to fit everything in the original box when I desoldered the coax jack. Even with all parts being through hole and the ICs socketed!!



And this thing got rid of all the noise. I am sure the manufacturer could have captured equivalent measures without much effort or price hike.

This is part one of a little three (or more) part series about my experiences with TOSLINK and S/PDIF.
Click here to read part two of the story.
- Marv

Freitag, 27. November 2015

A quick HUB08 LED Matrix Library & Graphics Library

I recently got an LED Matrix using the HUB08 protocol from ebay. Since none of the libraries I found on the internet worked for me, I wrote my one for the Arduino Uno, using hardware SPI. It also supports pwm brightness control and frame rates up to 2000 fps (32kHz line frequency, 16 lines). Yeah, that's fast, so the microcontoller can do other stuff in between (instead of really working with such ridiculous frame rates ;) ). The pins are hard coded into the library to achieve this speed. Please take a look at the example to understand how to connect the matrix and how to use it, it's pretty simple.
Link to github: https://github.com/emgoz/HUB08SPI

I also want to share another library with you, the Buffer Graphics Library. It features many optimized drawing functions (points, lines, rectangles, circles, bitmaps)  and buffer manipulation functions (scrolling, rotating, flipping, ...) and also works with the matrix library above quite nicely.
Link to github: https://github.com/emgoz/BufferGraphics
-Marv

Donnerstag, 4. Juni 2015

Simple Programming Adpter for Arduino Pro Mini

I ordered a bunch of these little Arduino Pro Mini Clones that just have anything to get started right away with your projects in need of a simple micro controller breakout. Sadly, they come with the standard Arduino bootloader which delays the programm start about 2 seconds everytime the board is powered up. So I wanted to update to optiboot, a great alternative to the original bootloader and also saves a few bytes flash. The standard way to do that is with an In-System-Programmer. The board hasn't got an ISP socket to reprogram it, so usually you just solder wires or pin headers to pins 11,12,13, RST, VCC and GND to hook it up to the programmer. However, I don't know what I want to do with most of the boards and it might be handy some time that there no bulky headers attached it. So I remembered those clip programming adapters and tried to built one with junk I had lying around: A peg, a piece of a zip tie, some regular PCB headers and hot glue. I had some doubts whether the contacts were good enough, but it worked surprisingly well!



- Marv

Samstag, 18. April 2015

Quirks with YET-M1 and USB-Ports

A few days ago, I ordered a YET-M1 Bluetooth Audio Adapter for just a few bucks on ebay. It has a 3.5 mm jack as audio output, you can simply hook it up to any active speaker and make it bluetooth enabled. It can so play the music from your phone wirelessly. It is powered over the USB-plug on the other end, so you just need to plug it in your phone charger.


Well, then I tried it out with an AV receiver, which even has a convenient USB port for flash drives already build in. However, the bluetooth adapter seemed like it didn't power up. The same happened with another hi-fi system's USB port. However, when powered with a phone charger or by directly applying 5V to the GND and +5V lines of the USB plug, it worked. My first guess was, that those USB ports don't output enough power for the adapter. This was easily disproved by being able to charge my phone over this port. I measured the voltage on the two power lines: 5V. So this should be alright.
Apparently it had something to do with the data lines. I opened the adapter to have a look at those and indeed, they where connected to the bluetooth chip. Maybe for configuration/programming in the factory. It seemed like this is is what pees on the parade. The AV receiver tries to communicate with the adapter and thereby freezes it.
Unsoldering the plug and bending over the data lines to disconnect them is what fixes the problem.
<s> Is that really what the manufacturer expects us to do? </s>

- Marv