If your connecting the PIC to the live AC line, I suggest you use "two" 2.5Mohm resistors in series, and maybe another two from there to ground (setup as a voltage divider). You'll also need to use B4 through B7 as your interrupt pin (make sure the internal pull-up resistor is off, which should be the default I think). Make sure your using resistor rated high enough (most are only 100v rating). If you want to use B0, you'll need to fully rectify the AC first (0 to 170 "DC" waveform), then feed it through two 2.5Mohm resistors, and I've found that you'll have to voltage divide it by using another two 2.5Mohm resistors to ground. Obviously, you'll have to use a falling edge interrupt. Be aware, that the interrupt happens about 20 to 32us before the "actual zero crossing" event occurs (adjust timing accordingly). This is a bit better, as then you don't have to worry if the wall outlet/plug strip/etc.. your plugged into is wired up correctly (polarity insensitive). Either way, you'll get an interrupt every 8333us on a 60hz line, and every 10,000us on a 50hz line. Read the data sheet on the PIC your using to find out how to setup & clear the appropriate interrupts. Remember, in this configuration, EVERYTHING on the circuit should be considered at line potential. Choose/build your circuit interface and housing (plastic box, plastic tactile buttons, or plastic body potentiometer w/ plastic knob, etc) accordingly. PIC port (B0 or B4 Thru B7) | | 2.5M 2.5M |__/\/\/\/\__/\/\/\/\___Ground | | 2.5M 2.5M |__/\/\/\/\__/\/\/\/\___Hot DC or AC If your already using a transformer to power your PIC (like a 120VAC to 12VAC, and then through a filter cap and regulator), you could also use the AC or DC output side of that (for DC ZC, put another diode between the positive side of the filter cap and the bridge, and feed a resistor to the PIC port from between the bridge and that diode). Obviously, the lower output voltage of the transformer will cause you to detect the ZC even earlier (again, adjust your timing accordingly). You can use TMR1 to turn on/off a CCP pin, when it matches the CCP register pair (calculated and set, in your main routine), to turn on your triac opto. You can then turn it off, as the first thing you do after saving critical registers, in your zero crossing interrupt (works for a B0 interrupt, don't know about B4 though B7 interrupts). Note: Using the CCP pin "does require" that you know about the ZC before it actually happens, or you won't be able to turn off the triac before the next half cycle (it would always be full on otherwise). Otherwise, you can use TMR0 at a 1:32 prescale (at 4mhz PIC speed) to generate an interrupt to turn on the triac (at 4mhz, it's nearly the entire 1/2 cycle time range of 8.3ms, and not much jitter). You'd just need to set TMR0 to an appropriate value during the ZC interrupt (255 = full on, 128 = half power, 0 = nearly off). You can either leave the port on, and turn it off right before ZC like described above, or if your application is not having to do anything else, just wait for about 30us after turning it on (in your interrupt routine), and then turn it off again. Using the TMR0 technique would also allow you to develop this on an 16F84 instead (flashable), and would allow you to fairly easily migrate this to a really cheap 12C71, or the one your using now, later on if you wanted to. -----Original Message----- From: Andre Abelian To: PICLIST@MITVMA.MIT.EDU Date: Wednesday, February 14, 2001 7:30 PM Subject: Re: [EE]: dimmer with pic can't make it work >Olin, > >I assume power ( HOT ) thru 4,7Meg resister should be connected to >one of pic pin then how do I synchronize it. I still do not clearly picture >it. Thanks for your help. > >Andre > > > >> > all I see while PWM goes from 0-70 % blinks a few times >> > and stays on on higher duty cycle for load I use regular 110 v lamp. >> >> Remember that the triac will stay on once it is triggered until the next >> power line zero crossing. You need to synchronize the control signal to >the >> power line. >> >> >> ***************************************************************** >> Olin Lathrop, embedded systems consultant in Devens Massachusetts >> (978) 772-3129, olin@embedinc.com, http://www.embedinc.com >> >> -- >> http://www.piclist.com#nomail Going offline? Don't AutoReply us! >> email listserv@mitvma.mit.edu with SET PICList DIGEST in the body >> >> >> > >-- >http://www.piclist.com#nomail Going offline? Don't AutoReply us! >email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu