Coding a PIC12F683 to act as a variable frequency charge pump. Two pins are made outputs and set to complimentary values. An Exclusive OR instruction is executed repeatedly to produce complimentary square waves. The frequency can be altered by pushing the reset button. Full code below:
list p=12F683
#include "p12f683.inc"
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
clockspeed equ 0x20
org 0x000
checkresets
banksel 0x80
btfss PCON,1 ;test the POR bit
goto readclock;there was a power on reset
btfss PCON,0 ;test the BOR bit
goto readclock;there was a brown out reset
changeclock ;this section if there was no POR, BOR
banksel 0x00
movf clockspeed,w
andlw 0x30
addlw 0x10
andlw 0x30
movwf clockspeed
banksel 0x80
clrf EEADR ;only EEprom location 00 is used
movwf EEDAT ;also write clockspeed to EEprom
bsf EECON1,2
movlw 0x55 ;
movwf EECON2 ;required EE write sequence
movlw 0xAA ;
movwf EECON2 ;
bsf EECON1,1
goto setresets
readclock
banksel 0x80
clrf EEADR ;only EEprom location 00 is used
bsf EECON1,0
movf EEDAT,w ;read EE data into w
banksel 0x00
movwf clockspeed
setresets
banksel 0x80
bsf PCON,1 ;set POR bit
bsf PCON,0 ;set BOR bit
setclock
banksel 0x00
movf clockspeed,w
banksel 0x80
movwf OSCCON ;set CPU clock
; movlw 0x01
; movwf OSCTUNE
setports
banksel 0x00
; movlw 0x07 ;only needed for GP0,1
; movwf CMCON0 ;turn off comparator
bcf GPIO,4
bsf GPIO,5
banksel 0x80
clrf ANSEL ;turn off analog inputs (GP4 needs this)
bcf TRISIO,4 ;RA4 is output for charge pump
bcf TRISIO,5 ;RA5 is output for charge pump
main
banksel 0x00
movlw 0x30 ;set bits 5,4 of w for toggle
loop
xorwf GPIO,f ;toggle charge pump outputs
goto loop
end

By Julian

Youtuber, shed dweller, solar charge controller aficionado

3 thoughts on “Microchip pic12f683 as a variable frequency charge pump part 1”
  1. Avataaar/Circle Created with python_avatars tjousk says:

    Surprises me that I can hear anything that high, I've not been terribly kind to my ears…

  2. Avataaar/Circle Created with python_avatars Julian Ilett says:

    The divide factor is 24 so 500kHz divides down to 20.83kHz. I can't hear frequencies that high anymore, but I guess it's possible it got recorded. Nice one!

  3. Avataaar/Circle Created with python_avatars tjousk says:

    I can still hear something when you switch it to 500khz, quite faint, but definitely still there.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.