Archive for Blog

The Art of Electronics

The study of electronics is a very interesting and rewarding occupation for either the hobbyist or aspiring engineer.

Even the most casual hobbyist has easy access to thousands of low cost components, allowing anyone to take up the pursuit of electronics and advance it to any level of sophistication that he or she might desire – including as a rewarding career.

Back in the 70’s and 80’s, it would typically cost thousands of dollars to get started in the development of products that used a microprocessor – meaning that only large businesses could afford to do it. The use of a microprocessor also usually required the use of a number of support IC’s such as timers, port expanders, memory, and communication IC’s. The end result tended to be complicated and difficult to breadboard for testing purposes.

Today, just the opposite is true. Hundreds of low cost microcontrollers are available from a number of different manufacturers. For about ten dollars or so, one can purchase a complete development board that has an on board programmer and debugger and along with a free complete development environment (IDE) that can be downloaded to any laptop. (Some are code limited, but usually a generous limit.)

Sure, you would need to learn to program in assembly or C and also need a basic understanding of digital logic. However, the easy availability of the internet, for most people, allows the access to all kinds of electronics information, including electronic forums where you can ask others for help and even find complete programming examples to help you get started. Also, complete datasheets on practically any component you can imagine is usually just a few clicks away.

That said, it is always a good idea to have on hand a few reference books that pertain to your area of study.

In my opinion, one of the best must have books available for general electronics is:

The Art of Electronics (Third Edition) by Paul Horowitz and Winfield Hill.

This book, of about 1200 pages, contains an extensive amount of information on the basics of voltage, current, and resistance. Also, the theory behind and the use of components such as resistors, capacitors, inductors, diodes, bipolar and mosfet transistors, op-amps, voltage regulators, logic devices and much, much more.

The book also has numerous pictures and circuit examples that can be considered building blocks for your own projects. Most examples are simple and use components that are inexpensive and easily obtained. This allows one to breadboard and test the examples, providing an excellent way to learn and experiment with circuit theory.

All in all this is an excellent book for both the beginner and expert alike.

One Final Thought:

There seems to be a number of counterfeit and poorly produced copies of this book being sold, mostly online and at suspiciously low prices.

Please respect the enormous amount of effort over many years that the authors have put into creating this series of books starting with the first edition in the early 1980’s by purchasing only authorized and official versions.

 

 

end post

MSP430 Encoder Adjustable PWM

PULSE WIDTH MODULATION

Pulse Width Modulation (PWM) is an easy and efficent way of controlling the speed of a DC motor or control the brightness of a lamp or LED. In conjunction with a low pass filter, PWM can also be used as an accurate way to create a digital to analog converter, which in turn can be used to create sine waves or other analog waveforms.

A basic PWM output consists of a digital waveform that is fixed in frequency and varies in duty cycle, usually from 0% (FULL OFF) to 100% (FULL ON). When used to control an inductive load such as a motor, PWM, operating at a high enough frequency, provides an average value of current flow to the motor which is directly related to the duty cycle of the PWM.

While it is possible to create PWM in software, many low cost microcontrollers, including the Texas Instruments MSP430 series, contain hardware timer modules which allow the creation of PWM waveforms to be easily implemented.

The program shown below creates a single PWM output using a MSP430G2553 microcontroller along with the MSP_EXP430G2 Launchpad.

The PWM control program has the following attributes:

1.) PWM output frequency of 10 kHz. (Easily Changed)
2.) PWM output duty cycle is adjustable using an inexpensive quadrature encoder
3.) PWM output is adjustable from 0% (Full Off) to 100% (Full On) in 1% increments.
4.) Visual indication of PWM duty cycle percentage using a red – green LED.
5.) Visual indication (Blue LED) when PWM is at exactly 50%.
6.) Encoder pushbutton switch sets PWM output to 0% (Off).
7.) Precise PWM frequency and duty cycle using a 4.0Mhz crystal oscillator.
8.) LaunchPad LED1 and LED2 flash with increment and decrement pulses from encoder.

OUTPUT DRIVER

Most applications will require an output driver to control a motor or a lamp. A reasonably priced driver is the SN754410 quadruple half H-bridge driver that has a 1 amp output capability per driver at a voltage of 4.5 VDC to 36VDC in positive supply applications.

COMMENTS

The start-up PWM value is set at 5%. This can be easily changed in the main function below. The maximum PWM is set to full on (100%), this can be changed to another value in the encoder interrupt.

I have done extensive testing and the encoder interface works very well, in fact quite bullet proof – no skipped or extra encoder pulses even when the encoder is rotated as fast as possible. The combination of RC network and interrupt polling makes it happen.

Note: The program below utilizes an external 4.0 MHz crystal oscillator connected to pin 19 (xin) of the MSP430 Launchpad. This oscillator is not shown on the schematic! The program can be modified to utilize the microcontrollers internal oscillator.

 MSP430 ENCODER PWM MAIN FUNCTION

MSP430 ENCODER PWM INTERRUPTS

MSP430 ENCODER PWM OUTPUT WAVEFORMS

PWM OUTPUT AT 1%

 

PWM OUTPUT AT 50%

 

PWM OUTPUT AT 99%

 

MSP430 ENCODER PWM SCHEMATIC

MSP430 ENCODER PWM SCHEMATIC

 

ENCODER PWM PROTOTYPE

ENCODER PWM PROTOTYPE

 

 

 

 

 

 

 

End Post

Create Encoder Pattern Using Excel

I recently have been working with quadrature encoders. I created several programs using an encoder to control the speed of a motor using pulse width modulation. These encoders are of mechanical design and for best results require a resistor and capacitor filter on the inputs in order to compensate for switch bounce.

The final result worked very well. However, these encoders have mechanical contacts which are subject to wear and are generally limited to a maximum number of cycles.

Optical encoders can be used to overcome these limitations. They are quite a bit more expensive than mechanical encoders.

I decided I wanted to experiment with making my own optical encoder. The necessary artwork is not that complex, simply an alternating pattern of black and white segments. I did not have a suitable drawing program other than my PCB artwork program – which was unable to produce a suitable encoder design.

In studying the problem, I suddenly realised that the encoder artwork resembled a circular pie chart. Since I did have the spreadsheet program Excel and I was already familar with how it works, I decided to try using it to make a circular pie chart with equal alternating black and white segments.

It turned out to fairly easy. The requirements are simple: You want an even number of black and white segments with the total evenly divisable into 360 degrees. I chose to start with an encoder wheel with a total of 24 segments. Since 360 divided by 24 is equal to 15, you simply need to enter the value of 15 into 24 number cells in Excel. The easy way is to enter 15 into the first cell and then drag the value down into the next lower 23 cells (24 total cells).

Once this is done, you create a simple pie chart and then format each cell with an alternating pattern of black and white colors by clicking on each value in the legend and selecting the correct color. I suggest saving the final pattern as a PDF document.

The only other variable is the size of the artwork. This is important as the encoder output must be in the correct pattern in order work correctly.

The most basic encoder typically has two outputs called “A” and “B” and since the outputs are 90 degrees out of phase they are referred to as a quadrature output encoder. Having two outputs gives the ability to determine the direction of rotation either clockwise or counter-clockwise.

The ultimate size will be dependent on the size and type of optical encoders that are going to be used. I plan on experimenting with the Sharp GP1S53VJ000F transmissive photointerrupter.

I found I could easily adjust the final print size of the encoder using the printer software and entering a percentage of the normal print size. I ultimately did this by trial and error.

I eventually plan to use the artwork to create a circuit board with the encoder pattern.

Sharp OptoInterrupter

 

24 Segment Encoder

 

Forty Segment Encoder Pattern

 

 

End Post

 

Surface Mount Test Clips

Any one working with electronics, even at the hobby level, will at some point be forced to work with surface mount components. It is a fact of life these days that more and more integrated circuits are released only in surface mount packages.

This fact should not discourage anyone from working with SMT. Sure, they can be more difficult to handle and solder. However, equipped with the proper tools, which are readily available, the use of SMT can be done by the hobbyist and they do have some advantages. Two such advantages are a more compact circuit board design, and if you make your own circuit boards, fewer holes that have to be drilled for through hole components.

Some tools that are necessary are a good quality 5x magnifying glass, a fine soldering iron tip and some static free tweezers to handle the parts with. A flux pen and some soldering paste are also a good idea to have on hand – both are available in water washable formulas.

A problem that I recently ran into is the ability to connect test equipment such as a oscilloscope to a SMT device.

It started when I made a simple test PCB in order to run some operational tests on a PCA9685 Led driver. This device is only available in SMT. The easiest package to work with is the TSSOP28 with a pin pitch of 0.65mm – yes, quite small.

When I designed the PCB, I neglected to add test points for any of the outputs or the I2C pins. Fortunately, I found that there is a solution for this.

A company called TPI USA makes an excellent line of surface mount test clips – Nano Clips and Micro Clips. The Nano Clips are designed for 0.3mm pitch leads and also work on 0.65mm pitch leads as well. The Micro Clips will work on a 1.27mm pin pitch. Both clips have gold plating for good conductivity, and are available in a number of different colors. They connect using a 0.65mm x 4mm long pin located on the clip body.

I purchased two of the Nano Clips from DigiKey Electronics, and although they are not inexpensive, they do work very well.

I connected them to my oscilloscope using a wire whip I made from some 30 awg stranded wire I had on hand. I soldered a small female connector removed from a transistor socket to one end and a 0.65 mm square pin to the other end. I covered both with some small diameter heat shrink tubing.

Problem solved!

Here is a picture of them in use.

 

 

end post

 

MSP430 Long Timer Delay

In the previous two posts I described how to use a timer interrupt in order to create precision time delays. This time I describe a method to create much longer time delays. These time delays are useful in looping main “c” functions that require periodic updating.

Similar to a previous post that described a timer interrupt with a M430G2452 mcu, we will be programming a longer time delay using a timer interrupt and the timer will be clocked using a high accuracy external oscillator.

In this example the delay will be contained in a function that can be called any where in the main program loop. Also it would be easy to create different time delay functions by simply changing a couple of variables.

The function works by using a fixed time delay and then looping this delay the required number of times. A timer interrupt is used to increment the loop counter. By changing the value in the loop counter, long accurate time delays can be created.

MSP430 LONG TIME DELAY PROGRAM

 

 

TIMER OUTPUT WAVEFORMS

ONE SECOND TIME DELAY

 

FIVE SECOND TIME DELAY

 

end post