On 2011-05-10 16:18, Olin Lathrop wrote: > > In a recent project I used a Bresenham style algorithm to dither the outp= ut > to some heaters. Each heater is fully on or off each half power line cyc= le. > Since there are many many 1/2 power line cycles within the first order ti= me > constant of the heaters, there is not problem introducing low frequencies= .. I think "re-invented" a similar algorithm for a toaster controller a few=20 weeks ago and surprised myself at just how simple and effective it can be. uint16 current_setting, accumulator; void change_heater_setting( float desired_fraction ) { current_setting =3D desired_fraction * 65535; } void zero_crossing_isr( void ) { if (accumulator < current_setting) heater_output =3D ON; else heater_output =3D OFF; accumulator -=3D current_setting; } The ISR runs on every negative-going zero crossing (the AC line is=20 connected to an external interrupt pin via multi-megohm resistor). So it=20 only switches whole cycles. This basically produces pulse density=20 modulation with 16-bit resolution. At the lowest setting it would=20 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=20 was wary of drawing half-cycles. (Imagine if your output setting was 50%=20 and you were consuming every other half cycle). Joe Koberg --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .