Re: PWM using the 12F683
here's my first attempt - haven't tried it yet - I will try PWM also as an experiment
'12f638
' ======= config SETUP =================================
#CONFIG
cfg = _INTOSCIO
cfg&= _WDT_ON
cfg&= _PWRTE_OFF
cfg&= _MCLRE_OFF
cfg&= _CP_OFF
cfg&= _CPD_OFF
cfg&= _BOD_ON
cfg&= _IESO_ON
cfg&= _FCMEN_ON
__CONFIG cfg
#ENDCONFIG
' ======= Common Settings =================================
OSCCON = %01110001 ' Internal 8MHz osc.
DEFINE OSC 8
CCP1CON = %00001100 ' CCP1, PWM mode - could be %00001110 for negative
CMCON0 = 7
TRISIO = %101011 ' GP2 and GP4 are outputs
ANSEL = 0
HLEDOUT VAR GPIO.2 ' HPWM output
PLEDOUT var GPIO.4 ' PWM output
BUTTEN var GPIO.3 ' BUTTON IN
HERTZ VAR BYTE
DUTY VAR BYTE
DUTY = 1
HERTZ = 600
; hpwm Channel, Dutycycle, Frequency
' hpwm 1,128,600 ; 50% 600 hz
MAIN:
HPWM 1, DUTY, HERTZ ' continuous output from GP2
IF BUTTEN = 0 THEN ' button pushed
pause 50 ' debounce
DUTY = DUTY +1 ' incrememnt duty cycle
ENDIF
IF DUTY > 254 THEN ' MAX number
DUTY = 1 ' reset duty
ENDIF
GOTO MAIN
end
My dad never liked you...
Bookmarks