Tjaart van der Walt wrote: > To limit the current, I use a 4 bit (16 resolution) pulse train with the > high time variable from 0 (no current) to 15 full current. If the > 'overcurrent' input is high, I decrease the high time. If the > 'undercurrent' is high, I increase the high time. Every now and again > I invert the two charge pump pins to keep the gate switching supply > up. > > When the current direction reverses, the PIC sees it as a very low > load, and swithes the FET on hard. > > The Challenge : > --------------------- > To get a gate switching frequency between 20kHz and 30kHz using > the 4MHz internal oscillator. This is not trivial and will require a good > few assembly tricks. With non-optimal C code I've been able to get > around 1.5kHz, but (as you can immagine) the circuit screams like a > banshee when you draw a few amps. The FET stays cold even at > loads up to 1.5A! If I understand you correctly, you basically want a 16-level pwm output with a frequency somewhere between 20-30 khz from a 16c84(?) running off of a 4Mhz crystal. If you do the arithmetic, that comes out to between 50 - 33 instruction cycles per pulse. (4Mhz / 4 / 20khz) That's tough! You might wish to check out my single-cycle resolution 256 level pwm or 32 level pwm: http://www.interstice.com/~sdattalo/technical/software/pic/pwm.txt http://www.interstice.com/~sdattalo/technical/software/pic/pwm256.txt and try working with them as a start. But these guys are tweaked - it'd be hell to get them working for your charger (though it would be killer!). However, it might be more feasible to implement an intertwined isochronous routine (iir - okay I made it up). Do you remember Dwayne Reid's pulse sampling problem a couple of months ago? I don't have time to elaborate right now, but maybe someone else can (Dwayne?). But basically, you can get a resolution of about 3 instruction cycles with the algorithm. So in your case, you could have 16 levels * 3 instructions/level for 48 instructions per pulse. This also gives you 16 instructions per pulse for other processing (like sampling Vds and determining the next pulse width). Scott