Posts

Experimenting with feedback and crossover distortion

Crossover distortion

Crossover distortion

I was playing with some analog circuits and while reading this article made a test circuit to get better understanding on how an operational amplifier maintains linearity using negative feedback. While experimenting with it I produced enough content to make a short article so I did just that in hopes it will be interesting to somebody. I also made a video, which is available at the end of the article.

1. The problem

While driven by a sine wave, push-pull stage constructed out of PNP/NPN transistor pair exhibits so-called “crossover distortion” (see Wikipedia article linked above). The reason for this is a dead band – a region on a waveform between negative Vbe and positive Vbe where both transistors are closed, don’t conduct and consequently do nothing. The green oscilloscope trace on a title picture shows the distorted waveform. The modified circuit from Wikipedia article has been breadboarded to produce the waveforms. I also made an LT Spice model – it could be useful if you don’t have parts to build the circuit or want to study circuit details which are difficult to measure in real life. LT Spice is available for free from Linear Technology.

Couple notes about the circuit. For frequencies that I’m using none of the parts are critical. I used TL081 op amp an 2N3904 and 2N3906 transistors. Other will work and for LT Spice model I randomly grabbed Linear’s opamp and simulation results are surprisingly close to the real circuit. I will be using simulation for the rest of the article; real circuit can be seen in the video.

When we load a model into LT Spice, run the simulation and then probe voltages on the opamp output and push-pull output, we will see waveforms as on the following screenshot. The green waveform is the opamp output and the blue one is power stage. If kept within specified levels opamp is quite linear so there is no surprise its output faithfully reproduces the input sinewave. The opamp output drives the power stage and power stage tries to reproduce the sinewave but it can do nothing when input signal is within the deadband.

We know that the original negative feedback idea came to Harold Black when he tried to solve very similar problem – how to keep a circuit linear while using non-linear components. In our case, transistors on the real circuit are not matched and we can see that in addition to the crossover the negative half of the waveform has larger amplitude as well. Note that a simulated waveform is perfectly symmetrical and this is why any simulation result should be used with caution.

Let’s modify our circuit and move the right side of the feedback resistor to the output of the power stage. This will allow the opamp to sample the output and make an attempt to correct it. The result can be seen on the following screenshot. The opamp output is now sprints through a deadband as fast as its slew rate allows and as a result the output of the circuit is now much closer to a sinewave.

To understand what is happening let’s make another measurement (and yet another screenshot). Here, the red trace shows the inverting input of the opamp. It is a sum of generator signal and output signal which is in antiphase to the input so the red waveform really represents a difference between them. For the most part the difefrence is very small and we see a straight line. However, in the beginning of a deadband the difference between the input and the output becomes larger and the vertical spike representing this difference starts driving the opamp output correcting the non-linearity of the transistor.

Note the peak-to-peak amplitude of the signal. This measurement is quite difficult to make on a real circuit as 300uV is well below the sensitivity of most oscilloscopes. That’s where simulators shine – any signal can be easily visualized, no matter how small or fast. If you are curious, you can probe the circuit in other places observing other signals like voltages across resistors or currents in and out of transistor terminals.

By changing the model once again, the shortcoming of opamp can be seen. Here, I increased the frequency of the input signal to 100KHz and due to the finite slew rate the opamp is having difficulty following the signal. The distortion is back.

This is all. Play with the model, watch the video (link), have fun!

Oleg.

Switchmode DC-DC step-down converter kit

While designing USB Isolator I needed a 5V supply to power the device side. I picked Linear Technology LT1376-5 part which proved to be pretty reliable and mellow converter. I’ve had used this part for 3.5 years now, in a product and also in the kit and I haven’t had any serious issues with it. Some time ago I decided to put together another kit based on the same controller – at this time containing only PTH components to make assembly easier for beginners. This kit is now available at the store for $20 plus shipping and the following is a short overview of the capabilities.

The kit contains a PCB plus all parts necessary to build a DC-DC step-down converter. Voltage setting resistors to make output of 3.3V, 5V and 12V are included. The converter is capable of supplying 1A at any of the output voltages over 6-25V input voltage range ( 23Vmax for 12Vout), and can be pushed up to 1.3A if input and output voltages are close enough. Output voltage ripple is 50mv@1A.

The biggest advantage of switch mode supplies is efficiency. It is possible, for example, to step down from 24V to 3.3V without generating excessive heat even at 1A load. Also, switchers are fascinating circuits, fun to build and play with.

In addition to full kit, a bare PCB is offered for makers who prefer to source parts themselves. Eagle CAD files of the circuit are also available.

Enjoy,
Oleg.

Using your content for fun and profit

Jameco page with my content on it

Jameco page with my content on it


This story started about 2 weeks ago when I received an e-mail from a gentleman having issues with USB Host shield made by DFrobot – a well-known cloner. The shield itself is a mix of my and Sparkfun’s designs and mine has been released “for non-commercial use”. As usual, DFrobot haven’t added any value to the mix, even schematic they used to present as theirs is a verbatim copy of mine, including copyright and license. The gentleman bought his shield at Jameco Electronics – a reputable US retailer.

I looked at the product page and quickly realized that the page was carefully crafted from several elements from my site. First, the title picture was taken from the following blog post, and it shows my shield, not DFRobot’s. Under it, they used the product description from my product page, almost verbatim – the notion about soldering headers is especially funny since DFrobot’s shield comes with pre-soldered headers. Under the product description they posted a bunch of links, again, to my site, showing people how to use my shield.

From my e-mail exchange with a gentleman I learned an e-mail of Gil Orozco, V.P. of Product Management at Jameco, and immediately contacted this no doubt important and powerful official explaining my worries. I was quickly assured that the issue will be investigated and fixed in “a day or two”. I waited for about a week and checked again – nothing happened. I contacted her/him again and had been given a deadline “by 9am tomorrow”. I checked again this evening and found out that nothing really changed – the picture is still there, the product description is still there and the link to my non-commercial schematic is still there. To my disappointment, V.P.s are not really that helpful. For Jameco, maybe, for a small maker company like yours truly, not a whole lot. Clearly, I needed a different approach.

The fix was surprisingly easy. By inspecting the web page (see screenshot below, click on it to make it larger) I found out that Jameco didn’t even bother to copy the image but merely embedded it in their product page. They decided to keep displaying my shield on their product page even after I specifically asked them to remove it.

Continue reading Using your content for fun and profit

Wireless Xbox360 controller support for USB Host 2.0 library

Wireless Xbox360 code

Wireless Xbox360 code

[EDIT] Four simultaneous controllers are now confirmed to work [/EDIT]
This is a short announcement of another nice contribution to the USB Host 2.0 library code. Kristian Lauszus from TKJ Electronics announced release of wireless Xbox360 controller support for USB Host 2.0 library; up until now only wired Xboxen were supported.

As announced, up to 4 controllers are supported, however, only one has been tested so far. If you have (or can borrow) multiple Xbox controllers, please help Kristian test his code.

Enjoy,
Oleg.

Using USB Bluetooth dongle on Arduino to connect to Android phone

Arduino connected to Nexus S

Arduino connected to Nexus S


Since Kristian’s release of SPP service for USB Host 2.0 library I got many e-mails with questions about Bluetooth serial communications in general and using the SPP class in particular. While establishing a Bluetooth connection is quite easy when using PCs/smartphones/tablets, the Arduino implementation is less user-friendly (for a good reason) and somewhat confusing. This article is intended to be a short tutorial of Arduino USB Bluetooth connectivity using an Android device as a peer – in my opinion, the simplest one to set up and communicate.

To follow this tutorial, you will need the following:

  1. An Arduino board ( I sell them too )
  2. full-size USB Host Shield 2.0
  3. USB Host Shield 2.0 library downloaded and installed in your Arduino library directory
  4. An SPP example sketch
  5. Bluetooth dongle – see below for detailed discussion
  6. Android device – a phone or tablet. The accuracy of this tutorial has been checked on Nexus S phone and Nexus 7 tablet, both running Jelly Bean 4.1.1 OS.
  7. A Bluetooth terminal emulator app for Android – I use Blueterm

The hardware setup is shown on the title photo (click on it to make it larger). It is a good idea to use external power supply at least in the beginning – some Bluetooth dongles are not happy when powered together with Arduino board/USB Host shield from USB cable. On a side note, it is always a good idea to use external power supply while experimenting with USB devices, especially when using current Arduino boards with their weak regulators. Also, Bluetooth code requires plenty of resources. The example used in this article compiles in ~24K and even though it would work on standard Arduino, any meaningful project will likely require a bigger board, like a Mega.

Continue reading Using USB Bluetooth dongle on Arduino to connect to Android phone

Canon USB Protector

Canon USB Protector mounted

Canon USB Protector mounted

On my cameras, I use USB port a lot. At home I use various shooting aids (jigs?) and on the road I prefer offloading pictures to the laptop via USB rather than packing a card reader. Out of many cameras I have had over the years, Canon DSLRs have the weakest USB port. I broke it a few times; my 5DM2 was in the repair service twice in one year. When it arrived from the service today, in the box I found a nice Christmas present from Canon (or maybe they are just tired of fixing the same thing over and over again) – a USB protector designed to strengthen the camera’s USB port. The protector installed into terminal area is shown on the title picture (click on it to make it larger) and more details are given below.

The protector is a piece of rather soft plastic made to fit into the terminal well holding on the walls and two other connectors. When installed, A/V and HDMI connectors can’t be accessed. At the same time, the USB connector is supported very well – I’m not expecting it to ever break again. However, since the best protection is achieved when the thing is permanently attached to the camera I need to learn to live without HDMI.

Now, if you ask me where to get one, I don’t have an answer. The following picture shows product label. Google queries of ‘canon cap cable’ and ‘cy3-1673-000’ returned nothing. It seems that the only way to get this protector is to break a USB port (ask me how) and send a camera to Canon for repair around Christmas. I’m going to check that – I have a Rebel XSi with broken USB port which is going to Canon service on Monday :-). Stay tuned,

Oleg.

USB protector label

USB protector label

Dummy load for brushless motor controller

Dummy load Jig Complete

Dummy load Jig Complete

Here is a little jig I made to test and characterize the BLDC controller I wrote about a while back. It is a dummy load consisting of two coupled motors: one driven by a controller and another having its windings shorted either directly for maximum load or through series resistors when measured load is desired. Title picture shows finished jig (click on it to make it larger). The construction details follow.

Two brackets made of 2″ aluminum angle profile hold 50-size brushless outrunner Chinese motors rated at 100A. The brackets are bolted to 0.5″ polycarbonate base. The motor shafts are coupled with a flex coupler. Finally, the contact plates are bolted next to each motor – this way if I burn a motor, changing will be easy. The high-current wires are soldered to the female contacts. I’m using double wires to increase current capacity of the wire and also to allow observing half of the flowing current with my little 50A current probe.

I tested the load with my prototype BLDC controller and was very pleased with results. The testing is documented in the short video – check it out.

PTP 2.0 library function turns on Bulb mode on Nikon DSLR camera via USB

Bulb mode activation code screenshot

Bulb mode activation code screenshot


Last week my friend Hans and I spent some time in my lab exploring which features of his Nikon D300 are available via PTP protocol. Hans is working on extended range HDR-capable intervalometer and he needed to find out a way to switch his camera into bulb mode using Arduino board and USB Host shield. After we finished I realized that while bulb mode is not tricky to activate, it is not obvious either and no hints exist in the code and examples showing how to do this. This short article is intended to fill the void.

In PTP, shooting parameters, such as shutter speed, aperture, ISO, etc. are changed by setting certain device property. For each parameter there exists a list of allowed values of this property, each property value corresponding to a parameter value. For some parameters, property and parameter value lists are dynamic. For example, starting and ending aperture values are different for different lenses; additionally, the aperture step can be changed in camera settings. Stepping can also be changed for shutter speed and exposure compensation and this can also happen during PTP session if a photographer decides to switch modes – in this case a property may become unavailable, like shutter speed in aperture priority mode. Therefore, before changing a property value for one of these parameters it is necessary to somehow retrieve a list of available property values.

The property value list retrieval mechanism is slightly different for different cameras. On Canon DSLRs, a special event is generated by the camera and sent back to PTP host at the beginning of the session and also each time camera mode was changed, lens were swapped and so on. The application needs to track those events and constantly maintain current value list for each property. On Nikon DSLR, it is possible to simply get value list for a property any time it is needed. To save memory, the list is not stored but simply requested from the camera each time a property needs changing. It is combined with actual property change in two templates – StepUp and StepDown. If you need to increase, for example, shutter speed – call StepUp. If you need to decrease it, call StepDown.

If you “step up” shutter speed on Nikon DSLR manually, the last 2 values will be 30 seconds and bulb. If you step up shutter speed using StepUp method using Nkremote sketch it will stop at 30 seconds. This happens because bulb mode is not included in the list of available property values for shutter speed but simply defined as 0xffffffff. As a result, StepUp doesn’t know that another value is available. It is still possible, however, to set the property directly and I will show you how to do it.

Continue reading PTP 2.0 library function turns on Bulb mode on Nikon DSLR camera via USB

Running multiple slave devices on Arduino SPI bus

Stack of shields

Stack of shields

This is Part 1 of 3-part series of articles. Part 2 talks about hardware modifications while Part 3 explains how to deal with incompatible data formats.

Serial Peripheral Interface AKA SPI bus is a popular way to communicate peripheral IO controllers to a micro over short distances and many microcontrollers have SPI interface built-in, including Arduino. Consequently, many Arduino shields use SPI to communicate to Arduino; USB Host shield is one of them. When more than one such shield is connected to Arduino, several SPI slave devices start sharing SPI bus. SPI is designed to allow bus sharing and if correct signals are present at correct moments all devices get along just fine. In practice, however, nothing usually works as desired, shields are interfering and fixing it requires hardware and software modifications. I was recently tasked with connecting 3 SPI slave devices to Arduino and this article shows how I did it.

A reader is expected to be familiar with SPI bus in general and Arduino implementation in particular. In addition, Tronixstuff has SPI tutorial, which is a little bit more user-friendly.

1. The problem

Arduino shields with SPI interface generally have 2 sources of interference – 1 on hardware level and one in software.

SPI bus consists of 3 shared data lines – SCK, MISO and MOSI, plus one “Slave Select” AKA SS line per each device. All transfers are initiated by the host and proceed in both directions simultaneously. Only one device, the one whose SS line is asserted low, is participating in the transfer by driving its MISO line – all other devices are expected to have their MISO line in a third state.

Due to peculiarities in Atmega SPI implementation, designers of Arduino shields prefer using default SS line, which is assigned to pin 10 on standard-sized Arduino boards. If two shields are driven by the same SS, they will have their MISO line active at the same time. Best-case consequence of it is only one of the shields in the stack being able to communicate, worst-case is destroyed MISO line transmitters. Therefore, the first step in any multi-shield SPI project is to make sure each shield uses its own SS line and never expect this to be the case in default configuration.


Continue reading Running multiple slave devices on Arduino SPI bus

Bluetooth RFCOMM/SPP service support for USB Host 2.0 Library released!

Compatible Bluetooth Dongles

Compatible Bluetooth Dongles

[EDIT] Here is Kristian’s post with more detailed explanation of the example sketch.[/EDIT]

Kristian Lauszus from TKJ Electronics, a man behind PS3 and Xbox360 code in USB Host Shield 2.0 library did it again! I’m pleased to announce that the library now supports standard RFCOMM/SPP implementation, thanks to Kristian’s work.

RFCOMM is basic Bluetooth service and SPP is serial port emulator on top of this. The code allows interfacing standard USB Bluetooth dongles to Arduino boards using USB Host Shield v.2.0. Bluetooth dongles (the ones I’ve tested can be seen on a title picture ) are widely available, cost much less than specialized serial Bluetooth modules (I have a couple of powerful class 1 dongles bought on eBay for $1 shipped) and won’t occupy precious serial port on Arduino board. Even though most dongles are compatible with the code, there are also some that don’t work. The code has been tested for compatibility with all major OSes – Linux, MacOS and Windows 7, as well as Android devices. It will likely work with any RFCOMM client, however, more testing is necessary.

The example code is a simple SPP server. It needs to be started before attempting to connect to it from a PC/phone. Once started, the state of the server is printed on a terminal. After that, the device can be discovered/paired/connected to; it is then possible to send characters from one device to the other by means of a keyboard. In the coming days I will write a series of posts with details of connecting different Bluetooth devices to Arduino. In the mean time, enjoy the code! Please give it a try and let me know what you think.

Oleg.