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.
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.