You are getting a "brightness value" from a remote device? You want to set = a count in the timer to produce this brightness? If your lookup table was indexed by the received "brightness value" (0, 255= ) = and containned the correct timer count for that brightness value, then just = go into the table using the new brightness value received and read out the = proper timer count and put that into timmer. You would only need to go int= o = the lookup table each time you received a new brightness value command. Bill ----- Original Message ----- = From: "David V. Fansler" To: "'Microcontroller discussion list - Public.'" Sent: Monday, March 13, 2006 6:44 PM Subject: [PIC] Dimming with a PIC I am working on a design for a two channel AC dimmer using a PIC (16F87x series). Just wondering if anyone else has done it. I am running into a timing issue - or rather a like of timing issue. Here are my thoughts: Input to the dimmer would be either a 0-5vdc voltage, or a command via the RS232 input. The dimmer would have 256 steps between full on and off. Also, I would like to linearize the output, rather than the common strong start, linear in the middle and tapers off at the end. To do this, I though that I would have a circuit tied to the 60Hz line that would provide when a zero crossing takes place. This would start a counter based on T1 - this counter would count up to 256 during =BD cycle of 60Hz wave. A look up ta= ble would be used to compare the current analog value (or command value) to the linearized value at that slice of time (1 of the 256 slices in =BD of a 60Hz wave). When the current analog value exceeds the look up table value then the AC output would be activated. At the end of the =BD cycle the process would start over. Now for the problem - A 60Hz wave has a period of 16.66ms, so half a wave would be 8.33ms. If we divide this time into 256 slices that would give us 32.5 us per slice. A PIC16F87x running at 20MHz can perform an instruction in 200ns. So at 200ns/per instruction we could perform 162 instructions in 32.5us. This is not enough time to go through all 255 steps in the look up table. I could reduce the steps to 7 bits (128 steps) and this would possibly give me enough time for the look up table, but no much else. So as I said - anyone else already been through this that can possibly guide me in a better method? I am trying to hold external hardware down to a minimum. Thanks, David David V. Fansler S/V Annabelle david@dv-fansler.com www.dv-fansler.com -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist