Sie sind auf Seite 1von 24

Building a PIC Controller for an Aladdin Light Lift By Roy Seifert Introduction As with many new two-story homes

built today, my home came with an open, two-story entryway/foyer. At the top of the entryway, about 16 feet above the ground, is a hexagonal brass and glass light fixture. At the time I looked at the new model homes my first thought was, Who is going to climb up there to change a bulb and clean the glass? Although I dont have a fear of heights, I have a fear of ladders falling off of them that is! So I started looking around to see if someone had something to keep me from having to climb a ladder.

Figure 1: Aladdin Light Lift A visit to a local lighting store introduced me to the Light Lift manufactured by Aladdin Light Lift Inc. There were other, less expensive light/chandelier lifts on the market, but the Light Lift had a longer cable, and did not reel the electrical cable with the lift cable. This allowed the Light Lift to use a single, longer, non-electrified cable. The light was connected to a circuit board that broke electrical contact when the light was lowered from the ceiling. Since there was no AC power on the lights when lowered it was much safer for the user. When the light was raised back into the ceiling, contact was made with the circuit board so the lights worked normally. I called around town to all of the lighting companies I could find in the yellow pages and found a distributor willing to sell me a Light Lift at wholesale! Apparently they werent selling and he wanted to get it out of his inventory. So I carried it around in the back of my car for 2 weeks until I closed on my house, and then installed the unit myself.

Building a PIC Controller for an Aladdin Light Lift Control Panel

Common

Figure 2: Homemade Control Panel The control panel that came with the unit had a single (on)-off-(on) key switch (the parenthesis indicate momentary contact). This switch required that I continuously hold it in one position or the other to keep the unit moving. I can guess that this was to prevent the user from walking away and having the light lower too far. Unfortunately, the key switch was faulty it only worked in one direction; but with a few dollars and a trip to Radio Shack, I purchased the parts I needed to make my own control panel and its been working for 12 years! It consisted of an on-off key switch to prevent accidental use, and an on-offon toggle switch for up and down. The toggle switch connected common to either the up or down wire, but I didnt have to hold it while the unit was moving. The original control cable and control panel came with interlocking connectors, but I replaced them with Radio Shack 4-pin connectors 274-224 and 274-234. 5-Second Delay The owners manual that came with the Light Lift stated that I needed to wait a minimum of 5 seconds before reversing the motion of the lift. This was to prevent causing problems with the motor, brake, and pulley system. Im really the only one who ever operates the unit; but what will happen if I sell the house? Most people wont take the time to read the instructions and could possibly damage the unit; especially realtors showing the house. Fast-forward 12 years to the present. I have started learning about programming PIC microcontroller units (MCU) as a hobby so I decided I wanted to program the 5-second delay into a microcontroller to prevent a quick reverse. Light Lift Smart Controller I was browsing the Aladdin web site and found that they manufacture a programmatic controller that not only prevents the quick reverse of motion, but it also allows the user to program it so the light always lowers to the same location every time. The price for their unit was $99.00, but I was able to manufacture my own for less than half that amount. My controller doesnt work exactly the same as the Aladdin unit, but it does perform the following functions: LEDs indicate when ready to operate and other status. Lower the light down from the ceiling with one press of a toggle switch and indicate down motion. The toggle switch does not have to be held down.

Building a PIC Controller for an Aladdin Light Lift Raise the light up to the ceiling with one press of a toggle switch and indicate up motion. The toggle switch does not have to be held up. Indicate when the light gets to the home (ceiling) position and automatically stop up motion. Force a 5-second delay before allowing a change in direction. Load default duration which was 2 1/2 minutes for my house. I use this feature to restore the 2 1/2 minute duration for my house in case I change the programmed duration. Program default duration. Normally this should never change, but I made it somewhat universal so others could use it. Program duration for lowering the light. Cancel or change the programmed duration. Ignore the programmed duration. Remove power from the controller with a key switch when not being used. This both saves power and prevents accidental use.

Reading the instructions for the Aladdin controller, my guess is that their controller is always powered on, but requires a button press/sequence for it to wake up from sleep mode. I decided I didnt want my MCU powered on all the time. I attended a computer technology school right out of high school to learn how to fix large-scale mainframe computers, and worked at that occupation for 11 years. During that time I taught myself programming, so between my computer, electronics, and software background, I felt this project was well within my capabilities. PIC Microcontroller Programming

Figure 3: EasyPIC6 Development Board Searching the Internet I found mikroElektronika, a company in Serbia that produces both the hardware and software that I needed to program the microcontroller. The EasyPIC6 development board they manufacture allows me to program many different PIC microcontrollers, and contains the circuits to develop and test LEDs, LCD graphical and character displays, switches, one analogue to digital 3

Building a PIC Controller for an Aladdin Light Lift converter (ADC) and various interfaces. It also contains a port expander and access to the microcontrollers ports via header pins. The software that comes with the board contains examples designed for the PIC16F887 microcontroller, and the board comes with one of those microcontrollers. What a great tool for developing different applications! I used this board with its switches and LEDs to develop and test my controller. Software MikroElektronika allows you to download trial versions of each of their compilers. Assembly language is a bit cumbersome for me, I know nothing of Pascal, I know some C language, but I am very fluent in BASIC, so I decided to purchase their MikroBASIC Pro compiler for PIC. Microcontroller

Figure 4: PIC16F688 A microcontroller is essentially a computer in a small, integrated circuit package. It has all the capabilities of a larger computer, but with less capacity. A microcontroller is normally programmed to perform one function, rather than many functions. Microchip Technology Inc., a manufacturer of microcontrollers, publishes a selection guide for choosing the right microcontroller. I chose the PIC16F688 for the following reasons: Small footprint, 14-pin DIP At least three pins had weak internal pull-up. These would be used for the switch inputs. 7 output pins, 5 for LEDs, (Ready, Home, Up, Down and Program) and 2 to drive reed relays connected to the Light Lift. The reed relays take the place of the toggle switch in my original control panel. EEPROM for storing duration. This was an important feature since I didnt want the duration to be erased when the microcontroller was not being used and powered off.

I am using just a small percentage of the capabilities and capacity of this MCU, but it only cost $1.62.

Building a PIC Controller for an Aladdin Light Lift Hardware


1 2 3 4 5

Light Lift Cable D Black - Comm Red - Up Green - Down White - +16VAC Lite Lift 16VAC - White 2

D1 1N4005 C1 47uF C3 .1uF

IC1 LM7805

C2 .1uF

16-Pin Header Up Sw 1 2 LL 16 4 GND Dn Sw 3 6 Home Sw Home Sw 5 8 Key Sw Up Blu LED + 7 10 Key Sw Dn Org LED + 9 12 LL Comm Pr Red LED + 11 14 LL Up Hm Yel LED + 13 16 LL Down Rdy Grn LED + 15

1 VDD +5 Lite Lift Up - Red 14 1 K1 2 Home Sw 5 R3 220 4 C Key Sw 8 1 Key Sw 10 Lite Lift Common - Black 12 4 Lite Lift Down - Green 16 GND 4 Home Sw 6 K2 3 6 RC4 7 RC3 3 2 4 RA3 5 RC5 2 RA5 3 RA4

VSS GND 14

IC2 PIC16F688

RA0 13 R1 220 RA1 12 R2 220 RA2 11 RC0 10 R4 47 RC1 9 R5 120 RC2 8 R6 137

1 Up Sw 3 Down Sw C 7 Up Blue LED+ 9 Dn Orange LED+ 11 Pr Red LED+

S1 Key Switch Key Sw Home Yellow LED+ 13 S2 Toggle Switch R7 120 Ready Green LED+ 15 R8 120 D2 Green D3 Blue D4 Orange D5 Red GND Down Up B Key Sw

LED+ LED+ LED+ LED+ LED+ A

Switch Plate

D6 Yellow

Title: Lite Lift Controller - Home Rev: 6.01 Date: 2010.09.01 1 2 3 4 Eng.: Roy Seifert Sheet: 1 of 1 5

Figure 5: Light Lift Controller Schematic It turns out that there is a fourth wire in the control cable that comes from the Light Lift. This contains a full wave rectified, 26 VAC that comes from the unit. In the above schematic I take that 26 VAC, feed it through an isolation diode D1, filter it with C1, and feed it to IC1 an LM7805 +5-volt regulator. This provides the power for the PIC MCU. The key switch S1 disconnects common from the circuit, thereby disabling power when not in use. Since timing is not so critical I decided to use the internal 8MHz clock of the microcontroller to save a few cents on components. I chose different colored LEDs to indicate status as follows: Green Ready. This LED required 2.4 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 120 ohm resistor. (4.7 2.4 = 2.3, 2.3/.02 = 115 ohms; 120 was the closest I could obtain)

Building a PIC Controller for an Aladdin Light Lift Blue Up. This LED required 3.9 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 47 ohm resistor. (4.7 3.9 = .8, .8/.02 = 40 ohms; 47 was the closest I could obtain) Orange Down. This LED required 2.4 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 120 ohm resistor. (4.7 2.4 = 2.3, 2.3/.02 = 115 ohms; 120 was the closest I could obtain) Red Program mode. This LED required 2 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 137 ohm resistor. (4.7 2 = 2.7, 2.7/.02 = 135 ohms; I was able to obtain a 137 ohm resister) Yellow Home position. This LED required 2.4 volts at 20 mA. Since the MCU puts out 4.7 volts, I needed a 120 ohm resistor. (4.7 2.4 = 2.3, 2.3/.02 = 115 ohms; 120 was the closest I could obtain)

Notice that most of the current limiting resistors I am using for the LEDs have a slightly higher value than what was required. This helps to ensure that the LED runs at lower than maximum current so the LEDs should last longer. R1 R3 are static protection for the input to the MCU as recommended by numerous documents published by Microchip Technology Inc. K1 and K2 are 5-volt reed relays with a built-in diode. I used a dual row, 72-pin header strip that I cut to make the 16-pin header; 2 rows of 8 pins. I purchased most of the parts I needed from Mouser Electronics and Radio Shack. A list of parts can be found at the end of this article. Radio Shack no longer sells the key switch I purchased 12 years ago, so I purchased one from Mouser. This turned out to be the most expensive component of my controller. Firmware As mentioned before, I used the EasyPIC 6 development board with its integrated switches and LEDs to develop the firmware. I designed the firmware so that when the PIC is first powered on the LEDs flash in a sequence then the green Ready LED stays on indicating the controller is ready. I used a center-off, momentary contact rocker switch to initiate motion. It turns out the rocker switch was not the best solution, so I replaced it with a momentary toggle switch; more about this later. Press the toggle switch up to move up (the blue Up LED comes on), or press it down to move down (the orange Down LED comes on). Another press of the toggle switch stops the motion, the corresponding motion LED shuts off, and the green Ready LED blinks for 5 seconds. This 5-second delay prevents initiating a quick reverse and possibly damaging the Light Lift. When the green Ready LED stops blinking motion can again be initiated. When the light reaches the ceiling a Home LED comes on and motion stops automatically. Holding the toggle switch up or down when the controller is first powered on causes all of the LEDs to come on and the default duration is loaded from the EEPROM. Pressing the toggle switch up or down allows the controller to go ready. To enter program mode, press and hold the toggle switch up or down for 3 seconds; the Program LED comes on. In program mode the user can perform a number of functions: 1. Program duration press and release the toggle switch down; the light moves down. When the proper height is reached, press and release the toggle switch down again to stop motion. The duration is stored in EEPROM memory and the unit will stop at the same location every time.

Building a PIC Controller for an Aladdin Light Lift 2. Program default duration - press and release the toggle switch down; the light moves down. When the proper height is reached, press and release the toggle switch up to stop motion. The Program LED blinks for 3 seconds. Press and release the toggle switch up within the 3 seconds; the duration is now the default duration and is stored in EEPROM memory. If the toggle switch is not pressed within the 3 second duration, no changes are made to the memory. 3. Delete program duration press and release the toggle switch up. The program LED shuts off and the programmed duration is removed from the EEPROM memory. 4. Exit program mode press and hold the toggle switch up or down for 3 seconds. This exits program mode without making any changes. Once duration has been programmed, when the light is moving down it always stops at the programmed duration. When the light is moving down, holding the toggle switch up or down for 3 seconds causes the controller to ignore the programmed duration. I discovered that it takes exactly 2 1/2 minutes for my light to reach a suitable height, so I programmed the MCU with that default duration. However, this default duration can be changed for other users. I have included a copy of the BASIC code at the end of this article. Home Switch In the junction box at the top of the ceiling are two switches used to stop the motor when the light reaches the top. Only one switch is used; the other is a backup. I attached two wires to the common and normally open connectors of the spare switch and ran that cable to the junction box for the control panel. These two leads are tied to RA4 input of the MCU and ground. Sensing the home position shuts off the up reed relay when the light is moving up. PCB

Figure 6: Light Lift Controller PCB I found a PCB design program on the Internet called Abacom Sprint Layout 50. Figure 6 shows my PCB design for the controller. I used red to indicate the outline of the components to ensure they would fit on the board and not interfere with each other. This board is fairly small, only 1.5 x 2 so it will fit into a single-gang outlet box. I decided to make the installation modular by using a 16-pin header to

Building a PIC Controller for an Aladdin Light Lift connect a ribbon cable to the board. I connected the ribbon cable to the LEDs, control panel switches, and the Light Lift and home switch plugs. There are a number of methods for producing PCBs at home. The key to the process is being able to transfer the artwork onto the copper board in preparation for etching. I dont have a laser printer so the iron transfer method wouldnt work for me. Another method is to make a silk-screen stencil, but I didnt want to spend the $20 for two sheets of stencil, and whatever it would cost for the proper paint. Plus, since this method was new to me, I didnt want to spend the extra money to experiment, learn and possibly make mistakes. Ive had good luck in the past with photo-sensitive boards so I decided to go with this method. I purchased a positive photo-sensitive board and the developer solution from Mouser. I probably should have purchased 2 boards in case I messed one up, but I was on a tight budget for this project.

Figure 7: PCB Artwork The photo-sensitive PCB I purchased was 3 x 5. I cut it so I could produce my board and still have some unexposed board left in case I made a mistake. The heavy green section at the bottom in the above figure did not get etched; this allowed the etching process to complete quicker. It also allowed me to attach the artwork to the PCB with a piece of tape on this area folded under the board. I first printed a mirror image of the PCB etch side on 3M transparency CG3480. This transparency is specifically designed for use with ink-jet printers. My artwork printed heavy and sharp. Following the instructions that came with the board, I laid the artwork print side down (which is why I had to print a mirror image) onto the sensitized side of the board, attached it with a piece of tape, and covered it with a piece of glass I removed from an old picture frame. I positioned it five inches below a florescent light and exposed it for 10 minutes, then placed the board into the developer solution I diluted with ten parts cold tap water. I constantly wiped the board with a foam brush I purchased from my local hardware store. The development process took about 6 minutes. After the board was developed I washed off the excess developer in running tap water; now the board was ready to etch.

Building a PIC Controller for an Aladdin Light Lift

Figure 8: Etched PCB I purchased a bottle of PCB Etchant Solution from Radio Shack #276-1535, and using a glass tray, etched my circuit board. This process took about 16 minutes to remove the excess copper. I used a hair dryer to warm the solution and keep it moving over the board which sped up the etching process. Ok, so now I had to drill the holes for the components. I am fortunate to have a MAXNC 10 CL CNC hobby mill that I use for fabricating parts. Abacom Sprint Layout 50 allows me to export all of the component holes as a plotter file which I import into my CAD/CAM program, BobCAD-CAM V20, and use to drill the holes in the board.

Figure 9: Corel Draw Plot Its actually not quite that easy. I first imported the plotter file into Corel Draw 12. Each of the holes gets imported as a node. I then connected two nodes with a line. BobCAD-CAM V20 doesnt recognize the nodes if I import the plotter file directly, but it does recognize the lines I created with Corel Draw 12.

Building a PIC Controller for an Aladdin Light Lift

Figure 10: BobCAD-CAM Drilling Next I exported the lines to a drawing file, which I then imported into BobCAD-CAM V20. At the end of each line I placed a point; each point became a hole location which I programmed with the CAM portion of the software. In the above figure you can see the points and lines on the left, and the resultant G code drilling instructions on the right.

10

Building a PIC Controller for an Aladdin Light Lift

Figure 11: Drilling PCB Holes I purchased a circuit board maker kit from Drill Bit City that contained the correct size bits I needed to drill the component holes. I drilled holes in the corners of my board and mounted it to a piece of wood using screws. Using my MAXCNC 10CL mill and the CAM program I created I drilled the component holes in the circuit board.

Figure 12: Completed PCB Once the holes were drilled I cut off the bottom and populated it with the components I purchased from Mouser. I mounted a 14-pin DIP socket onto the board so the MCU wouldnt be permanently installed in case I needed to reprogram it. I put some heat-shrink on the LM7805 to insulate it, and also on the back of the board to prevent the solder pads from shorting against the metal body of the key switch.

11

Building a PIC Controller for an Aladdin Light Lift Control Panel

HOME

Figure 13: Control Panel Design I used Corel Draw 12 to design the layout of the control panel as shown in Figure 13 above. It was designed to fit onto a blank wall plate cover. I exported the design to my CAD/CAM software and created the milling file for the cutouts.

Figure 14: Control Panel Using my MAXCNC 10CL mill, I used a 3/32 square end bit to mill the cutouts. Even though I used my hobby CNC mill, I could have done the same thing with hand tools; Ive done it before. I printed the 12

Building a PIC Controller for an Aladdin Light Lift text on adhesive labels, cut them out, then applied them to the panel. I sprayed a coat of clear lacquer onto the plate to protect the labels. Wiring Harness

Figure 15: Wiring Harness After the panel was milled I created a wiring harness to connect the individual components. I connected the wires from the ribbon cable to the appropriate hardware as shown in the schematic. To make it modular and easy to replace components I used plugs and connectors where possible. For the key switch pins I used two female pins from a Radio Shack 274-234 connector and covered them with heat shrink tubing. The lens for each LED socket snaps on making it easy to install and remove from the panel. I left the up and down wires off of the Light Lift plug for testing purposes. I didnt want the unit to move during testing.

13

Building a PIC Controller for an Aladdin Light Lift

Figure 16: Completed Light Lift Controller As mentioned before, my original design used a rocker switch, but pressing on the rocker switch caused the plastic panel to crack and eventually break. I decided to use a 3-position toggle switch with up and down momentary contact, and center off. With a toggle switch, pressure is placed vertically on the plate, instead of horizontally, which should prevent the plate from cracking and breaking. I plugged in the control panel to the Light Lift cable, turned on the light switch, turned on the key switch, and to my relief, the LEDs went through the ready sequence so that the green Ready LED stayed on. I tested all of the controller functions to make sure everything worked correctly. This was a good thing because I hadnt really bread-boarded or tested the circuit. Finally, I turned off the power, installed the up and down pins into the controller interface plug, connected the home switch, and turned on power for the final test. The Light Lift moved up and down as it should and I was able to program the duration. Now, whenever I lower the Light Lift, it always stops at the same location so I can clean the glass and change a bulb. Instruction Card I printed a small instruction card using heavy card stock. I laminated the card using press-on adhesive laminate, and installed an eyelet on the card. I then installed this card onto the key ring that came with the keys for the key switch. Now anyone operating the controller will have access to the instructions. I have included a copy at the end of this article. Summary This project required a number of processes in order to complete: Program a microcontroller Design the circuit Fabricate the circuit board 14

Building a PIC Controller for an Aladdin Light Lift Fabricate the control panel Install all of the components

I lower the unit maybe once every six months to clean the glass, but there is no power applied to the controller when not in use, so depending on the life of the individual components, this controller should last for years before requiring any maintenance. Hopefully it adds to the resale value of my home, not to mention I have the pride of designing and building a nifty little project. The advantage to using a DIP socket on the circuit board was that I could remove the MCU whenever I needed to upgrade the firmware. Since writing this article I have made two improvements to my initial program, which I have loaded into the MCU. I also added a short routine to blink the green Ready LED based on the firmware revision number. I am currently up to revision #2. Parts List The following table contains the list of parts I purchased for this project. Capacitors and resistors are so inexpensive that I usually purchase in quantities of 5 so I have spares on hand for other projects. Source Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Mouser Ref C1 C2, C3 D1 D2 D3 D4 D5 D6 IC1 IC2 K1, K2 R1, R2, R3 R4 R5, R7, R8 R6 S1 Part # 140-XRL10V47-RC 581-SR215C104K 625-1N4005GP-E3 78-TLHG4400 78-TLHB4400 78-TLHO4400 78-TLHR4400 78-TLHY4400 512-LM7805CT 579-PIC16F688-I/P 816-9007-05-01 291-220-RC 660-CF1/4C470J 71-CCF07-G-120 660-MF1/4DC1370F 633-CKL12BTW01042 QTY Description 1 Aluminum Electrolytic Capacitors - Leaded 10V 47uF 20% 2 Multilayer Ceramic Capacitors (MLCC) Leaded 50volts 0.1uF 10% X7R 1 Rectifiers 1N4005 Vr/600V Io/1A 1 Standard LED - Through Hole Green Tint Diffused 1 Standard LED - Through Hole Blue Tint Diffused 1 Standard LED - Through Hole Orange Tint Diffused 1 Standard LED - Through Hole Red Tint Diffused 1 Standard LED - Through Hole Yellow Tint Diffused 1 LM7805 Positive Voltage Regulator 1A 1 PIC16F688-I/P MCU 2 Reed Relay 1FORMA 5V W/DIODE 2 Carbon Film Resistors - Through Hole 220ohms 1 Carbon Film Resistors - Through Hole 47ohms 5% 2 Metal Film Resistors - Through Hole 1/4watt 120ohms 2% Rated to 1/2watt 1 Metal Film Resistors - Through Hole 137ohm 1% 100PPM 1 Keylock Switches 19MM ON-ON RMVE 1POS TUBE KEY#042 3A LUG 15

Building a PIC Controller for an Aladdin Light Lift Mouser Mouser Mouser Mouser Mouser Mouser Mouser Radio Shack Radio Shack Radio Shack Radio Shack Radio Shack Radio Shack Drill Bit City S2 642-637NH2 593-1700C 593-CNXBX4108 590-603 590-418-500ML 649-67997-472HLF 164-9008-E 274-224 274-234 274-222 278-1610 64-4039 276-1535 301-R8WSFBRB 1 5 5 1 1 1 1 1 2 1 1 1 1 1 Toggle Switch SPDT (ON)-OFF-(ON) LED Lenses Clear Fresnel Lens Cliplite 3mm LED Mounting Hardware T1 2-Lead LED Con 8 Prototyping Products 3x5 Copper Clad Bd presensitized 1/16 Chemicals Developer 600 series Headers & Wire Housings 72P HDR 2 Row Headers & Wire Housings IDC SOCKET 16 PIN W/STRAIN RELIEF 4-Position Male Polarized Connector 4-Position Female Polarized Connector 2-Position Male/Female Polarized Connector Multicolor Heat-Shrink Tubing (12-Pack) Female Crimp-On Quick Disconnects (10Pack) PCB Etchant Solution Circuit Board Maker Kit

16

Building a PIC Controller for an Aladdin Light Lift BASIC Code


' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' * Project name: Light Lift Controller Home * Copyright: (c) Roy Seifert, 2010 * Revision History: 20100901: - initial release; 20100907 - Version 2 Pressing the toggle switch up while in program mode stores the duration in the default location. * Description: This firmware provides programmatic control of the Light Lift. It provides an automatic 5-second delay when reversing the direction of the Light Lift. The duration of down motion can be programmed and is stored in EEPROM so the unit stops at the same position every time. Up motion stops when the home switch is activated. Since the internal pull-ups are enabled the switch input is 1 for off, and 0 for on. LEDs indicate the status of the controller. * Test configuration: MCU: PIC16F688 http://ww1.microchip.com/downloads/en/DeviceDoc/41203E.pdf Dev.Board: EasyPIC6 http://www.mikroe.com/en/tools/easypic6/ Oscillator: Internal 8.0 MHz Ext. Modules: None Software: mikroBASIC PRO for PIC 4.1 http://www.mikroe.com/en/compilers/mikrobasic/pro/pic/ * NOTES: RA0 - PB switch input with pullup, up RA1 - PB switch input with pullup, down RA4 - PB switch input with pullup, home RA5 - Reed relay output, up RC5 - Reed relay output, down RC0 - Up (blue) LED RC1 - Down (orange) LED RC2 - Program (red) LED RC3 - Ready (green) LED RC4 - Home (yellow) LED EEPROM addresses 00-01 and 02-03 set to default duration of 2 1/2 minutes

program Lite_Lift_Controller ' Output port declarations dim up_relay as sbit at dim down_relay as sbit at dim up_LED as sbit at dim down_LED as sbit at dim program_LED as sbit at dim ready_LED as sbit at dim home_LED as sbit at dim dim dim dim dim dim dim dim dim dim up down up_button down_button prog home ignored count press_count EEdur as as as as as as as as as as boolean boolean boolean boolean boolean boolean boolean integer integer integer

PORTA.5 PORTC.5 PORTC.0 PORTC.1 PORTC.2 PORTC.3 PORTC.4

' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '

Up relay port Down relay port Up LED port Down LED port Program LED port Ready LED port Home LED port Moving up flag Moving down flag Up button pressed flag Down button pressed flag Program mode flag Home flag Ignored flag Count duration of motion Count duration of button press Programmed duration stored in EEPROM

'******************************************************************************* ' This procedure initializes the MCU bits and registers. '******************************************************************************* sub procedure init

17

Building a PIC Controller for an Aladdin Light Lift


OSCCON INTCON PIR1 PIE1 ANSEL CMCON0 ' ' ' ' ' ' ' ' ' ' ' RA0 RA1 RA4 RA5 RC5 RC0 RC1 RC2 RC3 RC4 = = = = = = 0x77 0x00 0x00 0x00 0x00 0x07 ' Internal 8MHz clock ' Disable interrupts

' Configure all analog inputs as digital ' Comparators off

PB switch input with pullup, up PB switch input with pullup, down PB switch input with pullup, home Reed relay output, up Reed relay output, down Up (blue) LED Down (orange) LED Program (red) LED Ready (green) LED Home (yellow) LED 1 = = = = = = = = = = = = = input, 0 = output %00010011 ' RA 0, 1, 4 input, RA 2, 3, 5, 6, 7 output 0x00 ' RC 7:0 output 0x00 ' Enable individual PORTA pull-ups 0x13 ' Enable pull-ups on A0, A1, and A4 0x00 ' All outputs low false ' Initialize all flags to false false false false false false false

TRIS bits: TRISA TRISC OPTION_REG WPUA PORTC up down up_button down_button prog home ignored

'******************************************************************************* ' When the PIC is first programmed all EEPROM locations are set to 0xFF by the ' PIC Flash programmer. This routine sets EEPROM locations 05 to 0x00 only ' after the PIC is first programmed. A value of 0 in location 05 indicates that ' the EEPROM has been initialized so it won't be initialized again when powered ' on. Set EEPROM addresses 01, 00 and 03, 02 to 0x0973 for initial 2 1/2 ' minute duration. Addresses 01 and 00 store the programmed duration. ' Addresses 03 and 02 store the default duration which can be restored by ' holding a button pressed during power on. delay_ms(250) count = EEPROM_Read(0x05) if count <> 0 then EEPROM_Write(5, 0)

' Initialize EEPROM to 0

' Store initial programmed duration 0x0973 into EEPROM delay_ms(20) EEPROM_Write(01, 0x09) delay_ms(20) EEPROM_Write(00, 0x73) delay_ms(20) ' EEPROM addresses 02 and 03 store default duration 0x0973 EEPROM_Write(03, 0x09) delay_ms(20) EEPROM_Write(02, 0x73) delay_ms(20) end if '******************************************************************************* '******************************************************************************* ' Load stored duration from EEPROM. Stored duration is an integer ' which requires two bytes. The upper byte is stored in EEPROM address 01 and ' the lower byte is stored in EEPROM address 00. hi(EEdur) = EEPROM_read(0x01) ' Read high byte lo(EEdur) = EEPROM_read(0x00) ' Read low byte '******************************************************************************* '******************************************************************************* ' If a button is pressed at power on, turn on all LEDs, restore default duration ' from backup EEPROM location, bypass the rest of the initialize routine.

18

Building a PIC Controller for an Aladdin Light Lift


if Button(PORTA,0,1,0) or Button(PORTA,1,1,0) then PORTC = 0x1F ' Turn on all LEDs ' Restore duration from backup EEPROM location hi(EEdur) = EEPROM_read(0x03) ' Read high byte lo(EEdur) = EEPROM_read(0x02) ' Read low byte delay_ms(20) EEPROM_Write(01, hi(EEdur)) delay_ms(20) EEPROM_Write(00, lo(EEdur)) delay_ms(20) ' Wait for button to be relesed while Button(PORTA,0,1,0) or Button(PORTA,1,1,0) wend ' Stay here until powered off or button press while true if Button(PORTA,0,1,0) or Button(PORTA,1,1,0) then Break end if wend end if '******************************************************************************* ' Flash LEDs to indicate working. Wait 1/4 second between LED action. Leave ' ready LED on to indicate ready to use. PORTC = 0x1F delay_ms(250) PORTC = 0 for count = 1 to 2 delay_ms(250) down_LED = not down_LED delay_ms(250) program_LED = not program_LED delay_ms(250) up_LED = not up_LED delay_ms(250) home_LED = not home_LED delay_ms(250) ready_LED = 1 Next count for count = 1 to 4 ready_LED = not ready_LED delay_ms(250) next count ' All LEDs on ' All LEDs off

' Toggle down LED ' Toggle program LED ' Toggle up LED ' Toggle home LED ' Turn on ready LED ' Blink ready LED for version number

end sub '******************************************************************************* '******************************************************************************* ' This procedure stops motion and resets the flags. '******************************************************************************* sub procedure stop_all up_relay = 0 ' Stop all motion down_relay = 0 up_LED = 0 ' Turn off up LEDs down_LED = 0 ' Turn off down LED program_LED = 0 ' Turn off program LED up = false ' Reset flags and motion counter down = false for count = 1 to 20 ' Blink ready LED for 5 seconds to ready_LED = not ready_LED ' prevent quick reverse delay_ms(250) next count count = 0 ' Reset motion counter ' Restore EEPROM duration if ignored if ignored = true then hi(EEdur) = EEPROM_read(0x01) ' Read high byte lo(EEdur) = EEPROM_read(0x00) ' Read low byte ignored = false ' Reset ignored flag end if end sub '*******************************************************************************

19

Building a PIC Controller for an Aladdin Light Lift

main: init while true

' Initialize MCU and registers ' Loop waiting for a button press

' Up or down button pressed if Button(PORTA,0,1,0) or Button(PORTA,1,1,0) then ' Up button pressed if Button(PORTA,0,1,0) then up_button = true else down_button = true end if

' Down button pressed

' Wait until button is released press_count = 0 while Button(PORTA,0,1,0) or Button(PORTA,1,1,0) delay_ms(62) press_count = press_count + 1 ' Button held for 3 seconds to enter program mode if press_count = 48 then ' Must not be moving to enter program mode if (up = false) and (down = false) then ' Not already in program mode if prog = false then prog = true ' Set program mode flag program_LED = 1 ' Turn on program LED else ' Already in program mode prog = false ' Reset program mode flag program_LED = 0 ' Turn off program LED end if delay_ms(1500) ' Time delay to remove finger from button else ' Moving and button pressed for 3 seconds if down = true then EEdur = 0 ' Clear EEdur so light lift will not stop at programmed duration ignored = true program_LED = 1 delay_ms(250) program_LED = 0 end if end if up_button = false down_button = false end if wend ' Set ignored flag to reload duration when stopped ' Blink program LED

' Reset button flags

' Finger removed from button, no buttons pressed, perform action if a ' button was pressed if Button(PORTA,0,1,1) and Button(PORTA,1,1,1) then ' If moving, stop motion If ((up = true) or (down

= true)) and ((up_button = true) or (down_button = true)) then

' Store duration in EEPROM if down stopped while programming if (down = true) and (prog = true) then ' Store duration if down button pressed if down_button = true then prog = false ' Reset program mode flag EEPROM_write(0x00, lo(count)) ' Write low byte to EEPROM EEPROM_write(0x01, hi(count)) ' Write high byte shifted right 8 bits to EEPROM EEdur = count ' Set programmed duration with count value end if ' Version 2 ' Store default duration if up button pressed if up_button = true then

20

Building a PIC Controller for an Aladdin Light Lift


down_relay = 0 ' Stop down motion to wait 3 seconds down_LED = 0 ' Turn off down LED for press_count = 1 to 12 ' Wait up to 3 seconds for up button press delay_ms(250) program_LED = not program_LED ' Blink program LED ' Up button pressed again within 3 seconds if button(PORTA,0,1,0) then EEPROM_write(0x00, lo(count)) ' Write low byte to EEPROM EEPROM_write(0x01, hi(count)) ' Write high byte shifted right 8 bits to EEPROM EEPROM_write(0x02, lo(count)) EEPROM_write(0x03, hi(count)) bits to EEPROM EEdur = count while button(PORTA,0,1,0) wend Break end if 'Down button pressed If button(PORTA,1,1,0) then EEPROM_write(0x00, lo(count)) EEPROM_write(0x01, hi(count)) EEdur = count while button(PORTA,1,1,0) wend break end if next press_count prog = false program_LED = 0 end if ' End version 2 end if stop_all up_button = false down_button = false else ' Up button pressed if (up = false) and (down ' Stop motion, reset flags, blink ready LED ' Reset button flags ' Not in motion ' Set programmed duration with count value ' Wait for finger to release button ' Exit for loop ' Write default low byte to EEPROM ' Write default high byte shifted right 8

' ' ' '

Write low byte to EEPROM Write high byte to EEPROM Set programmed duration with count value Wait for finger to release button

' Reset program flag ' Turn off program LED

= false) and (up_button = true) then

' Clear EEPROM duration if up pressed while programming if prog = true then EEPROM_write(0x00, 0) ' Write 0 to low byte in EEPROM EEPROM_write(0x01, 0) ' Write 0 to high byte in EEPROM EEdur = 0 ' Set programmed duration to 0 prog = false ' Reset program mode flag program_LED = 0 ' Turn off program LED else ' Not in program mode if home = false then up_relay = 1 ' Move up up_LED = 1 ' Turn on Up LED up = true ' Set up motion flag end if end if up_button = false ' Reset button flag else ' Down button pressed if (up = false) and (down down_relay = 1 down_LED = 1 down = true down_button = false end if end if end if end if end if

= false) and (down_button = true) then ' Move down ' Turn on Down LED ' Set down motion flag ' Reset button flag

21

Building a PIC Controller for an Aladdin Light Lift

' Count duration to load into EEPROM if (down = true) and (prog = true) then delay_ms(62) ' 62 ms chosen to allow quick response to button press count = count + 1 ' Increase count value end if ' Set home flag and LED if home switch pressed if button(PORTA,4,1,0) then ' Home switch pressed home = true ' Set home flag home_LED = 1 ' Turn on home LED else ' Home switch not pressed home = false ' Reset home flag home_LED = 0 ' Turn off home LED end if ' Auto stop if moving down and motion = EEPROM or if moving up and home ' switch pressed. if (up = true) or ((down = true) and (prog = false)) then delay_ms(62) count = count + 1 ' Count motion duration if ((down = true) and (prog = false) and (count = EEdur)) or ((up = true) and (home = true)) then stop_all end if end if wend end.

22

LIGHT LIFT Controller


5. The program duration is now set to the default duration.

LIGHT LIFT Controller


Ready Controller 1. Turn on the light switch so the lights come on. 2. Insert the key and turn to the On position. All LEDs flash then the green Ready LED stays on indicating the controller is ready. If the light is up to the home (ceiling) position the yellow Home LED also comes on. Lower Light (Green Ready LED must be on) 1. Press the toggle switch down, then release. The orange Down LED comes on and the light moves down. 2. If duration has been programmed, the light stops when the programmed duration has been reached. Raise Light (Green Ready LED must be on, yellow Home LED must be off) 1. Press the toggle switch up, then release. The blue Up LED comes on and the light moves up. 2. The light stops when it reaches the home (ceiling) position and the yellow Home LED comes on. Stop Light Motion (Green Ready LED must be on) 1. While the light is in motion, press the toggle switch up or down, then release. The light stops moving, the corresponding LED turns off, and the green Ready LED blinks for 5 seconds. The light may not be moved again until the green Ready LED stops blinking. 1

Change Default Duration (Green Ready LED must be on, yellow Home LED must be on) NOTE: This should only be performed one time immediately after the controller is installed. 1. 2. 3. 4. Start with the light raised up to the home (ceiling) position and the yellow Home LED on. Press and hold the toggle switch up or down for 3 seconds. The red Program LED comes on. Press the toggle switch down, then release. The orange Down LED comes on and light begins to lower. When the light reaches the desired location press the toggle switch up then release. The light stops moving, the orange Down LED turns off, and the red Program LED blinks for 3 seconds. Before the red Program LED stops blinking, press the toggle switch up then release. The red Program LED turns off and the duration is now the new default duration and also the new programmed duration.

5.

NOTE: To make no changes to the default or programmed duration, do not touch the toggle switch while the red Program LED is blinking. After 3 seconds the red Program LED stops blinking and turns off and no changes are made. 4

23

LIGHT LIFT Controller


2. The light also stops automatically at the programmed duration when moving down, or at the home (ceiling) position when moving up. Turn the key to the Off position. The green Ready LED turns off. Remove the key and store it in a safe location.

LIGHT LIFT Controller


Delete Program Duration (Green Ready LED must be on) 1. Press the toggle switch up or down and hold for 3 seconds. When the red Program LED comes on, release the toggle switch. 2. Press the toggle switch up, then release. The duration is deleted and the red Program LED turns off. Ignore Program Duration (Green Ready LED must be on) 1. While the light is moving down, press and hold the toggle switch up or down for 3 seconds. When the red Program LED blinks indicating the programmed duration is being ignored, release the toggle switch. 2. Motion must now be stopped manually (see Stop Light Motion on Page 1 of this card). 3. After motion is stopped, the programmed duration is restored so the light will again automatically stop at the programmed duration when moving down. Set Program Duration from Default Duration (Key switch must be off) 1. Turn on the light switch so the lights come on. 2. Press and hold the toggle switch up or down. 3. Insert the key and turn to the On position. When all LEDs come on, release the toggle switch. 4. Press and release the toggle switch up or down. All LEDs flash then the green Ready LED stays on indicating the controller is ready. 3

3. 4.

Program Duration (Green Ready LED must be on, yellow Home LED must be on) 1. Start with the light raised up to the home (ceiling) position and the yellow Home LED on. 2. Press and hold the toggle switch up or down for 3 seconds. When the red Program LED comes on, release the toggle switch. 3. Press the toggle switch down, then release. The orange Down LED comes on and the light begins to lower. 4. When the light reaches the desired location press the toggle switch down, then release. The light stops moving and the red Program LED and orange Down LED turn off. The light now stops in the same location when the programmed duration is reached. NOTE: To exit program mode without making any changes; with the red Program LED on, press and hold the toggle switch up or down for 3 seconds. The red Program LED turns off. 2

24

Das könnte Ihnen auch gefallen