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.

How to write a program about timer with PIC 18?

Status
Not open for further replies.

t6060

Newbie level 1
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top