--_003_008301cc109d1a4103800300a8c0main_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Joe Koberg wrote: > 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; > } That's the basic idea, although use of floating point and 16 bit integers i= s totally silly if this was done on a PIC. Just because you can do something easily in a higher level language doesn't make it a good idea. The problem with 16 bits is that the repetition period can be very long, much longer than the thermal time constants. In my implementation I used 8 bit integers, 0 is full off and 255 full on. Even that is more resolution than needed considering it's inside the feedback loop. I attached the salient part of my code since the comments would probably wrap and make a mess if pasted here. This runs once for eac= h of the 32 heaters on every line cycle zero crossing. The PIC is a 18F4550. > It was my understanding that it's "bad" to draw DC from the line, so I > was wary of drawing half-cycles. It's probably not great if lots of devices did it all synchronized. In my case the unit is driving 32 heaters, each independently controlled. The chance of them all turning on every other half cycle and being in sync for more than a few cycles is pretty much zero. --_003_008301cc109d1a4103800300a8c0main_ Content-Type: text/plain; name="x.txt" Content-Description: x.txt Content-Disposition: attachment; filename="x.txt"; size=667; creation-date="Thu, 12 May 2011 05:12:24 GMT"; modification-date="Thu, 12 May 2011 05:12:24 GMT" Content-Transfer-Encoding: base64 ICAgICAgICAgOw0KICAgICAgICAgOyAgIFRoZSBkZXNpcmVkIG91dHB1dCBsZXZlbCBpcyBpbiBX LCBhbmQgRlNSMCBpcyBwb2ludGluZyB0byB0aGUNCiAgICAgICAgIDsgICBkaXRoZXIgZXJyb3Ig YWNjdW11bGF0b3IuDQogICAgICAgICA7DQogICAgICAgICBhZGR3ZiAgIGluZGYwICAgICAgIDth ZGQgdGhlIG91dHB1dCBpbnRvIHRoZSBlcnJvciBhY2N1bXVsYXRvcg0KICAgICAgICAgc2tpcF9j YXJyICAgICAgICAgICA7dHVybiBvbiBvdXRwdXQgdGhpcyBoYWxmLWN5Y2xlID8NCiAgICAgICAg IGp1bXAgICAgYWN1cGRfbm90b24gO25vDQogICAgICAgICBtb3ZmICAgIGlyZWcxLCB3ICAgIDtn ZXQgbWFzayBmb3IgdGhpcyBvdXRwdXQgYml0DQogICAgICAgICBpb3J3ZiAgIGluZGYxICAgICAg IDtzZXQgYml0IGZvciB0aGlzIEFDIG91dHB1dA0KICAgICAgICAgbW92bHcgICAyNTUNCiAgICAg ICAgIHN1YndmICAgaW5kZjAgICAgICAgO3VwZGF0ZSBkaXRoZXIgYWNjdW11bGF0b3IgdG8gb3V0 cHV0IG9uIHRoaXMgaGFsZi1jeWNsZQ0KYWN1cGRfbm90b24gICAgICAgICAgICAgICAgICA7c2tp cCB0byBoZXJlIHRvIG5vdCB0dXJuIG9uIG91dHB1dA0K --_003_008301cc109d1a4103800300a8c0main_ Content-Type: text/plain; name="ATT00001.txt" Content-Description: ATT00001.txt Content-Disposition: attachment; filename="ATT00001.txt"; size=208; creation-date="Thu, 12 May 2011 05:12:24 GMT"; modification-date="Thu, 12 May 2011 05:12:24 GMT" Content-Transfer-Encoding: base64 LS0gDQpodHRwOi8vd3d3LnBpY2xpc3QuY29tIFBJQy9TWCBGQVEgJiBsaXN0IGFyY2hpdmUNClZp ZXcvY2hhbmdlIHlvdXIgbWVtYmVyc2hpcCBvcHRpb25zIGF0DQpodHRwOi8vbWFpbG1hbi5taXQu ZWR1L21haWxtYW4vbGlzdGluZm8vcGljbGlzdA0K --_003_008301cc109d1a4103800300a8c0main_-- .