Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generating Clock output from PIC 16F877A

Status
Not open for further replies.

gidp

Newbie level 5
Joined
May 20, 2009
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
pic clock output

Hello,

Can anyone let me know how can I generate a clock of about 30KHz on the output of one of the pins of PORTC, In parallel to the main program. Meaning that I do not wan this clock freq’ to be affected by the
Main Program code length or delay. The clock should be with duty cycle of ~50%, and the crystal is 4MHz using PIC 16F887A.

Thanks in advanced,
Gid
 

pic16f877 generate clock

You could use the pwm module to generate the output clock.
This is done in hardware so will not affect your main code.
 

16F877A CLOCK

There you go :

/*
* PWM registers configuration
* Fosc = 4000000 Hz
* Fpwm = 30303.03 Hz (Requested : 30000 Hz)
* Duty Cycle = 50 %
* Resolution is 7 bits
* Prescaler is 1
* Ensure that your PWM pin is configured as digital output
* see more details on https://www.micro-examples.com/
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b00100000 ;
T2CON = 0b00000100 ;
CCPR1L = 0b00010000 ;
CCP1CON = 0b00011100 ;

main() {

while(1){

}
}
 

clock output pin pic24

Thanks a lot guys.

Added after 4 hours 36 minutes:

Hello Hugo,

I have done the following (in Assembler), but its not working, can you please let me know why?

; PWM registers configuration
CLRF T2CON ; Stop Timer2
BSF STATUS, RP0 ; Bank1
MOVLW B'00100000' ; Set Period
MOVWF PR2
BCF TRISC,2 ; Set PORTC bit 2 as output
BCF STATUS, RP0 ; Bank0

BSF T2CON,2 ; Starts TIMER2
MOVLW B'00010000'
MOVWF CCPR1L ; Set Duty Cycle
MOVLW B'00011100'
MOVWF CCP1CON ; Set PWM mode
 

pic16f877a+t2con

You can use the timer interrupt in the microcontroller
for consistent time period.

Best Regards,
Siong Boon

MODERATOR - SIGNATURE LINKS ARE NOT ALLOWED
 

pic clock output pwm

Thanks for all the help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top