By the way, can anybody direct me to a good optically isolated zero-crossing detector circuit? I know it must be really simple, but probably there is already a well known circuit? Somehow google search did not help much. The idea is to create a short pulse at zero crossing. Circuits I have seen were working the other way around, that is, led in a optocoupler was "on" all the time, except short period at zero crossing. That seem ineffective to me, since that LED requires much more power. If voltage has to be dropped from 230V to optocoupler's operating voltage, this should make a huge difference in heat dissipated on voltage dropping resistor. On Thu, May 12, 2011 at 02:34, Joe Koberg wrote: > On 2011-05-10 16:18, Olin Lathrop wrote: >> >> In a recent project I used a Bresenham style algorithm to dither the out= put >> to some heaters. =A0Each heater is fully on or off each half power line = cycle. >> Since there are many many 1/2 power line cycles within the first order t= ime >> constant of the heaters, there is not problem introducing low frequencie= s. > > I think "re-invented" a similar algorithm for a toaster controller a few > weeks ago and surprised myself at just how simple and effective it can be= .. > > > =A0 =A0 uint16 current_setting, accumulator; > > =A0 =A0 void change_heater_setting( float desired_fraction ) { > =A0 =A0 =A0 =A0 current_setting =3D desired_fraction * 65535; > =A0 =A0 =A0 =A0 } > > =A0 =A0 void zero_crossing_isr( void ) { > =A0 =A0 =A0 =A0 if (accumulator < current_setting) > =A0 =A0 =A0 =A0 =A0 =A0 heater_output =3D ON; > =A0 =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0 =A0 heater_output =3D OFF; > =A0 =A0 =A0 =A0 accumulator -=3D current_setting; > =A0 =A0 =A0 =A0 } > > > The ISR runs on every negative-going zero crossing (the AC line is > connected to an external interrupt pin via multi-megohm resistor). So it > only switches whole cycles. This basically produces pulse density > modulation with 16-bit resolution. =A0At the lowest setting it would > output a one-cycle pulse every 1092 seconds (a very low frequency indeed.= ) > > It was my understanding that it's "bad" to draw DC from the line, so I > was wary of drawing half-cycles. (Imagine if your output setting was 50% > and you were consuming every other half cycle). > > Joe Koberg > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 KPL --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .