How to write a program about timer with PIC 18?

Status
Not open for further replies.

t6060

Newbie level 1
Joined
Apr 2, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
8
Can anyone help me to answer these questions about PIC18 Microcontroller??

1. Determine the appropriate prescaler and postscaler of Timer2 you should use to generate a square wave with 50Hz frequency and with 50% duty cycle if PR2 is set to d’124’ and TMR2 is initialized to d’0’.

2. Write a program that uses Timer2 with PR2 set to d’124’ to generate a square wave with 50Hz frequency and with 50% duty cycle on pin 5 of Port B.

Thanks!
 

1.) Depending on your microcontroller, go to the datasheet and look under the section Capture/Compare/PWM (CCP). This will tell you have to enable the PWM with the register and also the calculations for setting the Period and duty cycle. You know your period so you can solve for your TMR2 prescalar.

2.) Init function to setup timer2 and the ports
Set the CCP register with the PWM bits to make your PWM signal
Run forever
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…