3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Extreme Surface Mount Soldering

Step 3The Pulse Width Regulation Unit

The Pulse Width Regulation Unit
An ATtiny2313 microcontroller is the heart of this unit and generates the pulses. Two PCA-8574A Port Expanders, connected using the I2C bus, read DIP switches to control the pulse widths.

A few words about the control technique are in order. Pulse Width Regulation is a variation of the technique better known as Pulse Width Modulation and is a way to control power by rapidly turning it on and off. I prefer the term Pulse Width Regulation since we're really not modulating the pulses, but rather changing their duration (duty cycle) and thereby regulating the power delivered to the load. If you're more comfortable with the term PWM, go ahead and call it that.

This is really pulse width regulation, not pulse width modulation. The pulse width is regulated to control the period of time that power is applied. For example, during each 10 second period the control output is on for 3/10ths of a second. This would be a 3% duty cycle and the width of the pulse would be that same 3/10ths second every 10 second cycle. Increasing the time when the output is on by making the pulse wider would turn the unit being controlled on for a longer time. Thus we regulate the pulse width to control the load; in our case the hot plate. By turning the hot plate on and off in a relatively rapid, but constant rate, fashion, we closely control the temperature.

Pulse width modulation, by contrast, varies the width of the pulse every cycle. By doing this, and filtering the resulting pulse train, complex waveforms can be produced. This is true PWM and isn't really what we're doing here. Pulse Width Regulation is sufficient for our needs. You can learn more about PWM here.

As stated, the Pulse Width Regulation Unit is controlled by an Atmel AVR ATtiny2313 microcontroller and two I2C Port Expanders. Go ahead and download the schematic and the source code for the controller now. The source code for the control program is a Zip file that will unzip into it's own directory named Control. Use the Ghetto Development System to program the microcontroller. It's not required, but you may want to have a look at this Instructable to learn more about the I2C bus. The I2C Instructable will show you how to modify your Ghetto Development System so that you can use the I2C Bus on it.

Use the parts you ordered back in Step 1 and the schematic you've downloaded. Picture 4 shows how to build the Pulse Width Regulation Unit. My Ghetto Development System is shown (built on perf board) along with the Port Expansion and the DIP switches (built on solderless breadboard). The larger DigiDesigner box is just used as a 5V power supply. I built it this way since I use the Ghetto Development Systems for lots of other experiments. You can use the same approach or build a dedicated system - your choice. In any case, the schematic and the software are the same.

Note that the DIP switches as shown on the schematic indicate the Port Expander pins to connect the switches to. The orientation of the switches should be as shown in Picture 6. SW1A and SW1B on the schematic are really one package of four DIP switches - SW1. Same for SW2, 3, and 4. Connect as shown in the picture to pins of U2, but ignore the pin numbers on SW1A, etc. that are shown on the schematic. Just plug them in so they connect directly to U2 and U3 on the proper pins, with the other side of the switch packages connected to ground. Picture 6 shows more detail.

To program your ATtiny2313, start the WinAVR environment, change to the directory with the files you unzipped in it, and use the Makefile to compile the software and program your part. The program is pretty straightforward. Timer/Counter 1 is used in Fast PWM mode to produce the pulses used to control the AC Power Control Unit. The pulses appear at PB4, and PD6 is used to flash LED1. The 1MHz default clock of the ATtiny2313 is used and is divided by 1024. So the resolution of the PWM is .001024 seconds. Since we're going to use steps of one tenth of a second, we multiply the DIP switch settings by 98 which yields steps of 0.1003 seconds - close enough.

Once you've built the Pulse Width Regulation Unit, you'll want to test it. Power it up by connecting a 5 volt power supply to it. If you've worked ahead and built the AC Power Control Unit don't connect it just yet. When you turn on the 5V power, LED1 should blink slowly twice to let you know it's ready to go. The DIP switches connected to Port Expander U2 are used to control the Cycle Length while the DIP switches connected to Port Expander U3 are used to control the duty cycle or On Time of the cycle. Both controls are set in units of 1/10 second and use binary code. Don't panic if you're not familiar with binary code, I'll explain it.

Binary code is best thought of as a doubling code. That is, the numeric value assigned to the first switch is 1 and the subsequent switches have numeric values that double. So the second switch has a value of 2, the third's value is 4, then 8 and so on. The value of the set of switches attached to either U2 or U3 is the sum of the numeric values of all the switches that are ON.

Here is a table showing the values of the individual switches on SW1 and SW2 which are connected to U2 for setting the Cycle Length. This assumes that you've built you circuit the same as mine and have the DIP switches oriented the same way as shown in Picture 6.

DIP Switch Number Pin Number Value when ON (HI)
SW1-1 U2-4 1
SW1-2 U2-5 2
SW1-3 U2-6 4
SW1-4 U2-7 8

SW2-4 U2-9 16
SW2-3 U2-10 32
SW2-2 U2-11 64
SW2-1 U2-12 128

The same values apply to SW3 and SW4 on U3 for the On Time setting.

An example should clarify this binary stuff. To set the value of 100 for the Cycle Length, turn on switches SW2-2, SW2-1 and SW1-3. From the table, the numeric values are 64+32+4 = 100 which is the value we want. All the other switches on SW1 and SW 2 should be off. Using the software I've provided, the minimum time for Cycle Length and On Time is one tenth second, so a value of 100 represents 10 seconds. As a test of your understanding, figure out what switches to turn on to set the value of 50 (5 seconds) for the Cycle Length. I'll tell you the answer below, but you should work this out yourself first.

Continuing with our testing, LED2 will flash to show the pulses being generated. So set a couple of numbers on the DIP switches - say 50 for Cycle Length and 10 for On Time (Switches SW2-3, SW2-4 and SW1-2 ON = 50 for Cycle Length - and the answer to the question above; Switches SW3-4 and SW3-2 ON = 10 for On Time) - and press the button. Note that the DIP switches are connected to ground (lo) when, according to the marks on their packages, they are on, and are pulled up (hi) when they are off or open. This may seem backwards, but closing the switch connects it to ground and makes it read LO. Opening the switch allows it to be pulled up to HI. Picture 6 show how this works. Easy once you get used to it. Pressing the button causes the switches to be read and their setting used to program the pulse generation. You should see LED2 flashing for one second every 5 seconds. If you see any more flashes from LED1, then something is wrong with the I2C Bus and you should check your wiring carefully. Change the Cycle Length DIP switches to 100 (values shown above if you're not sure), push the button, and you should get a 1 second flash every 10 seconds. Play with this until you get bored. The push button is there to ensure that settings don't change until you're ready for them to change.

You may be wondering what happens if the On Time switch setting is the same or higher than the Cycle Length switch setting. Go ahead and try it. Now is a good time for those sort of experiments since you can't hurt anything. Probably better not to do this with the AC connected since the SCRs could be turned on constantly and your hot plate will heat up a lot!

You may also wonder why the minimum Cycle Length and On Time are 1/10 second. My research indicated that this value would avoid causing any disturbances to the AC line voltage and seemed like a good value to start with. This proved to give satisfactory control of the hot plate so I haven't had any reason to change it. Obviously, you can experiment with other values by modifying the control program.
PWM Controller.pdf(612x792) 33 KB
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
41
Followers
8
Author:doctek