In message <25b178740606101647x330beabasb40d57c250e88e54@mail.gmail.com> "David VanHorn" wrote: > VBG.. Been there, done that.. > In the AVR, I was able to sync my current sample to the PWM output, and by > trimming nops, put the ADC sample point in a "quiet" zone. That's my plan too, but I don't like wasting cycles in ISRs :) > How often do you sample for regulation? I used a 10mS interval. 10uS. Once every PWM cycle. PWM rate is 100kHz. I think that might be "just a bit" too fast though. ISTR the AVR450 charger updates at 1kHz or so (but that brings us back to the point of "AVR450 is a monstrosity created by someone who probably didn't know what they were doing"). I'm using 100kHz PWM to keep the inductor size down. > That adds some complexity, but not too bad. > Before stopping the current, save your PWM value. > Then halt, and at the end of the halt, make the measurements. > Then reload the PWM value you had from before, and start regulating again. In my case, all I'd have to do is: STOP_PWM: CLRF CCPR1L ; turn pwm off MOVLW 0x ; ANDWF CCP1CON ; BCF INTCON,PEIE ; pwm update ISR off RETURN and: START_PWM: MOVF PWMVAL, W ; get last pwm value UPDATE_PWM ; turn the pwm back on BSF INTCON,PEIE ; pwm update ISR on RETURN That's pseudo-asm but you get the idea. UPDATE_PWM is a macro that puts the two LSbits of PWMVAL in the CCP1CON register (IIRC), then puts the upper six bits into CCPR1L. With that, I get almost 8-bit PWM resolution. -- Phil. | Kitsune: Acorn RiscPC SA202 64M+6G VF+UniPod philpem@dsl.pipex.com | Cheetah: Athlon64 3200+ A8VDeluxeV2 1G+180G http://www.philpem.me.uk/ | Tiger: Toshiba SatPro4600 Celeron700 256M+40G -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist