I agree with the statement below that you should be able to just jump into the table. A typical code sequence would be something like movlw high(JumpTable) movwf pclath ; set up high half of jump movlw low(JumpTable) ; get low half addwf offset,w ; add in offset into table skpnc incf pclath ; add in carry if needed movwf pcl ; jump into table JumpTable retlw nnn ; value returned when offset=3D0 retlw nnn ; value returned when offset=3D1 etc. I suggest using a 16 bit timer and the capture compare register. You can have one jump table for the high half of the compare, and another for the low half. If you're only dimming one channel, the ccp can set a pin high or low on a match. On detecting zerocross, reset the timer and reinitialize the ccp. I just did a two channel dimmer design using two ccp registers. This made it real simple. I've also done a four channel dimmer with a single ccp, which is a bit more code intensive. I've moved all my dimmer designs to 18f chips to get the higher clock rate, easier table lookups, etc. With these designs, I can handle DMX at 250kbps and analog (0-10V) inputs. Good luck! Harold > You don't have to step through the lookup table to get the result do you? > Just get the address of the start of the table, add in the offset and > then read the result. Shouldn't take anything like 162 steps to do the > lookup. > Or am I missing something - I've been away from actual PIC programming > for a long time. > > If you want to reduce the lookup to an even lower value at the expense > of some additional calculation you need only store a 1/4 period of the > sinewave since it is symmetrical about the 90degree point. > > RP > > On 14/03/06, David V. Fansler wrote: >> 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 =96 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 =96 >> this >> counter would count up to 256 during =BD cycle of 60Hz wave. A look up >> table >> 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 proce= ss >> would start over. >> >> Now for the problem =96 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 =96 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 > -- = FCC Rules Updated Daily at http://www.hallikainen.com -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist