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.

need help on generating a pic16F887 frequency generator through pwm

Status
Not open for further replies.

timi

Junior Member level 2
Junior Member level 2
Joined
Feb 28, 2006
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,422
Hi guys,

i am tying to make up a program to calculate the PR2 and Timer2 prescaler for a given frequency received by RS232.

i have the rs232 part of getting to read the data, but i am short of finding the right algorithm for the finding of the optimal:
PR2, Timer2 Prescaler.

Can anyone help me out.

Timi,
 

RS-232 is the standard for serial communication. Are you receiving some required frequency input serially???
And based on that value you want to generate the frequency by calculating the PR2 value???


If you are going for the serial input then follow these steps,

1. Make sure you first convert it from ASCII to integer value..
2.Use PR2=(PWM)/(4*Tosc*TMR2 Prescale) Select PWM based on duty cycle i.e 100% is (11 1111 1111)bit
and put a variable for TMR2 Prescale, make a poll for 1,4,16 by restriction on PR2 not more than (1111 1111)bit / 256 Decimal. 8-bit register.

Hope that helps..
-M. Aakif Raza
 

Hi makifraza,

thanks a lot that is what i was searching for. i will try to make the code into the pic and see what i can do about it.

regards,

Timi
 

I missed a little in last post. The correct formula for PR2 is
Use PR2= ( (PWM)/(4*Tosc*TMR2 Prescale) ) - 1

Also reference from Datasheet. The pwm section is given at Page 130. Topic 11.5 And the Equation is 11-1

and yes give it a few tries, if still you have any problems just post your code on the forum. :smile:
 
  • Like
Reactions: timi

    timi

    Points: 2
    Helpful Answer Positive Rating
OK, will tru this one out. thanks a lot

Timi,
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top