wyiancwc88
New Member
I am using PIC 16F877A with 20MHz crystal. I am wondering can it generate a 2MHz clock pulse with 30-40% duty cycle. Can anyone help me on this?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I am using PIC 16F877A with 20MHz crystal. I am wondering can it generate a 2MHz clock pulse with 30-40% duty cycle. Can anyone help me on this?
'A GCBasic program for a 2Mhz signal on CCP1
'using Hardware PWM with minimum period
'and duty cycle KS 3/1/11
'Chip model
#chip 16f877a,16
#config _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF
#define led PortA.0
dir led out
dir PortC.2 out 'make CCP1 an output
'set up hardware PWM with bare minimum values
PR2 = 1 'TMR2 period value, i.e. 2clks
CCPR1L = 1 'set PWM duty cycle, i.e. 1 clk of 2 clk period
T2CON = b'00000100' 'prescale, postscale is 1:1, TMR2 is on
CCP1CON = b'00001100' 'setup PWM mode, output will be on CCP1
Start:
set led on
wait 1 s
set led off
wait 1 s
goto Start