a ac p v controller for your pc - · pdf filea pic microcontroller ... used in light-dimmer or...

Download A AC P V CONTROLLER FOR YOUR PC - · PDF fileA PIC microcontroller ... used in light-dimmer or heater-con-trol applications. The sidebar, “The Parallel Port,” reviews the operation

If you can't read please download the document

Upload: letu

Post on 06-Feb-2018

216 views

Category:

Documents


1 download

TRANSCRIPT

  • AN AC PROPORTIONAL VOLTAGECONTROLLER FOR YOUR PCNEIL BUNGARD

    W hile it is easy to controlappliances from a PC,that type of controlusually has one of two conditions:on or off. There are many applica-tions where it would be desirable toproportionally control the voltagelevel of an appliance that uses 11 O-volt AC service. Light dimming isone obvious application. Otheruses include motor-speed control;heater control; and the ability toeasily create an inexpensive, pro-grammable DC power source.

    In this article, were going to showyou how to use the parallel port of aPC, a few optical-coupling devices,and a Microchip PIC microcontrollerto control the conduction angle ofa 1 10-volt AC source, and hence toproportionally control a device con-nected to the PCs parallel port.

    Controlling AC. Lets begin by look-ing at a 60-Hz 11 O-volt AC sine waveand talk about the concept of con-duction angle. Figure 1 A is the circuitthat will be used for this discussion.Well assume that S1 is an electronicswitch that can be activated in-stantly at any time. If S1 is closedand remains closed, Fig. 1B wouldrepresent a single cycle of the signalthat would be seen by load resistorR1 . In that case, the load draws cur-rent during the entire cycle andwould have a conduction angle of360 degrees. In Fig. lC, S1 does notclose until the sinewave reaches 90degrees in the cycle. As the signalpasses through zero at 180 degrees,S1 is opened, stopping the flow ofcurrent to R1 for the next 90degrees. At 270 degrees, S1 closesagain and current once again flowsthrough R1 until the zero crossing at360 degrees. The signal in Fig. 1 C hasa conduction angle of 180 degrees.Since, in general, the conductionangle is the number of degrees thatcurrent passes through the load in

    Use YOUR PC to control appliance voltage levels.

    each cycle, that means that theamountbf current seen by R1 wouldbe half the amount that would oth-erwise have passed through it.

    In general, that is the way that anordinary wall-mounted light dimmerworks. The physical position of thelight-dimmer knob sets the conduc-tion angle at which conduction willbegin after each zero crossing.Additionally, when the sinewavepasses through zero, conduction isautomatically stopped. Of course,that example controls the conduc-tion angle mechanically. Such anarrangement is fine for open-loopcontrol applications where you setthe control once and leave italone. For many control applica-tions, however, you are not interest-ed in just setting a conductionangle and letting the process run.You will want to monitor the processand dynamically adjust the con-duction angle to keep the processoperating at a preset level.

    To dynamically control the con-duction angle, you will need to knowprecisely what the angle is and beable to make adjustments accord-ingly. That is done by finding whenthe sinewave passes through zerovolts. There are many circuits for

    determining the zero-crossing point.If you need a high degree of preci-sion, op-amps can be used to getwithin a few microvolts. Most applica-tions, however, do not need that levelof precision and a quick and dirtyway of determining the zero-cross-ing point with a TTL-compatible out-put signal is to use an opto-coupler.

    The opto-coupler circuit shown inFig. 2A will work well but has someinherent shortcomings. Current-limit-ing resistor R1 must limit the forwardcurrent through the opto-couplersdiode and the external clampingdiode to within the maximum limitsfor the devices at the peak voltage,which is about 156 volts when usingwall current. The peak-inverse-volt-age ratings of the diodes shouldalso be at least 160 volts.

    Another consideration is that theopto-couplers output waveform willbe non-symmetrical. That is becausethe input signal on the opto-cou-plers diode must exceed thediodes forward-bias turn-on volt-age before the diode conducts.That phenomenon has been exag-gerated in Fig. 2B to illustrate theconcept. Since the actual turn-onvoltage is slightly above zero volts,the output will not have a perfect

  • 50% duty cycle. Another problemthat is related to the turn-on-voltagecondition-and is much subtler-isthat the diodes turn-on and turn-offvoltages are not exactly the same.This principle, called hysteresis, isexhibited by most electronic com-ponents. It is especially noticeable indevices that monitor or controlthreshold activities such as zerocrossing. The symmetry and hystersiseffects can be compensated for;we will see how to use software tocompensate for those conditionslater in this article.

    Now that we are able to detectthe zero-crossing portion of an ACcycle with a TTL output signal, howdo we control the current to a loadwith a desired conduction angle? Ageneral solution to that problem isshown in Fig. 3. A PIC microcontrollermonitors both the zero-crossing sig-nal from the opto-coupler and an 8-bit data byte from the PCs parallelport, which represents the desiredconduction angle. By comparingthe two pieces of input data, thePIC decides when to trigger theelectronic switch. The electronic

  • switch well use in our controller cir-cuit is actually a Triac that is trig-gered by the PIC. The sidebar,Triacs, Diacs, and Control, explainsthe basics of how four-layer semi-conductors are designed and used.

    Using an 8-bit word to representthe desired conduction angle lets uscontrol the conduction angle of theAC waveform in 256 discrete steps.That is probably more than enoughresolution for most applications andappears continuous when beingused in light-dimmer or heater-con-trol applications. The sidebar, TheParallel Port, reviews the operationof the PC parallel port and how itinterfaces to the outside world.

    Circuit Description. Bringing all ofthe concepts weve discussed sofar together yields our project,called the Parallel-Port Controller. Itsschematic drawing is shown in Fig. 4.Hardware operation for the entirecircuit should be familiar based onthe previous discussions.

    Wall-socket current is applied to

  • PARTS LIST FOR THEPARALLEL-PORT

    CONTROLLER

    IC1-PIC14C544 microcontroller, integratedcircuit

    IC2-H1 1AX optoisolatar, transistor-based, integrated circuit

    IC3--MOC3010 optoisolator, Triac output,integrated circuit

    TR1-2N6347 Triac,D1--1N4004 silicon diodeD2-lN523 1 Zener diode

    (All resistors are -watt, 5% units unlessotherwise noted)

    Rl, R5-100-ohmR2-1 OOO-ohmR3-11,000-ohm, -wattR4-l8O-ohm

    ADDlTIONAL PARTSAND MATERlALSC1--O.Ol-F capacitor, ceramic-discJl, J2-4-pin right-angle connector

    (Molex 26-60-5040 or similar)J3---DB25 right-angle male connector

    (Mouser 152-3325 or similar)J4---Co-axial power connector, male

    (Mouser 161-3112 or similar)RES1--8-MHz ceramic resonatorWall transformer, Plexiglas covers,

    hardware, etc.

  • J2. The AC waveform is applied toIC2 through R3 with D1 providing areverse path as discussed before.The TTL squarewave is applied to pin17 of IC1.

    When the PIC program decidesthat the output should be turnedon, an output signal from pin 18 ofIC1 activates the photodiode ofIC3. Current for the diode is supplied

    by Rl. The output of IC3 is appliedto the gate of TR1, which completesa path between the main connec-tions of J1 and J2. The load beingcontrolled is connected to J1 .

    An 8-bit value for the amount ofdelay is applied to J3 from a PCsparallel port. Power for the circuit isconnected to J4 and regulated byD2

  • SPP

    Pin

    234567a910111213

    ? 141516

    17 18

    19 20 21 22 23

    2425

    ABLE 1-MODE PHYSICAL iiqD LOGICAL PIN ASSIGNMENTS

    Signal In/Out Register InvertedStrobe In/Out control YesData 0 Out Data N OData 1 Out Data N oData 2 out Data N OData 3 Out Data NOData 4 Out Data NoData 5 Out Data NoData 6 out Data NoData 7 out Rata INoAck in status NoBusy In Status YesPaper Out / End In Status N o

    In Status NoAuto Linefeed In/Out Control YesError/Fault In status N oInitialize In/Out Control NoSelect Printer In/Out Control Y e sGround GndGround GndGround GndGround GndGround GndGround GndGround GndGround Gnd

  • Software. Overall operation of theParallel-Port Controller is really afunction of the program running inIC1 , Compensation for the non-sym-metry and hysteresis problems men-tioned before are accomplished bytweaking certain variables in theprogram.

    The block diagram of the PICprogram is shown in Fig. 5. After ini-tializing the variables that the pro-gram uses, the PIC waits for a posi-tive-going zero crossing to occur.At that time, a value from the par-allel port is read and used to deter-mine when to trigger the Triac.Once the Triac has been pulsedon, the program waits for the neg-ative-going zero crossing. Whenthat occurs, the current parallel-port value is again obtained andthe precise turn-on time for thenegative half of the cycle is calcu-lated. Once the Triac is triggeredon for the negative half cycle, theprogram loops back to the topand the process is repeated.

    A study of the source code willshow the inner workings of TheParallel-Port Controller. The sourcecode is available at the GernsbackFTP site (ftp.gernsback.com/pub/EN/ppc.txt).

    After initialization of the programvariables, a starting point is estab-lished and the wait_for_pos rou-tine begins looking for a positive-going zero crossing. When the zerocrossing is detected, the PIC movesa value from the parallel port intothe variable temp1 . At this point, acheck is made to see if the Triacshould be full on (temp1=0) or fulloff (temp1=255); if so. the appropri-ate action is performed, otherwise acall is made to a subroutine calleddwell.

    The dwell subroutine does twothings. First, it executes a timingloop that compensates for the pre-mature zero crossing caused by theforward voltage drop of the detec-tion diode. At the same time, theloop compensates for the