;A program to control duty cycle with pot using HARDWARE PWM. ;Written to experiment with varying duty cycles fed to a the input ;of a boost DC/DC converter. Connect GP2 to that input. ;Connect AN3 to the pot that determines DUTY CYCLE.(10K pot across rails, wiper to AN3) ;----- Settings #chip 12F683, 8 ;PIC12F683 running at 8 MHz #config mclr=off ;reset handled internally #config osc=int ;use internal clock ;----- Constants #define duty GPIO.4 ;potentiometer on pin 3 (AN3) DUTY CYCLE #define boost GPIO.2 ;boost signal is on pin 5 (CCP1) #define carrier 32 ;carrier frequency is 32 kHz ;----- Variables dim width as byte ;width is the duty cycle ;----- Program dir GPIO.4 in ;make an input dir boost out ;make an output do width = readAD(AN3) ;duty cycle = A to D pot reading, ;readAD returns 0 - 255, actual result between ~1 and 99% duty cycle hpwm 1, carrier, width ;CCP1, frequency (KHz), duty cycle loop ;repeat in perpetuity