That code was done by someone else over a year ago. He will not respond to my e-mails about it so what you see is what you get. I'm just using it because it was all setup to go on the board I purchased, I figured I could just edit it and use it for my needs. It does work but if I am to use the same calculations you gave it would end up having a
As I understand the following set the prescale, postscale, RP2 registers. The following sets pre=16, post=16, PR2=255
(200-nsecs * prescale 16 * postscale 16 * PR2 256) which comes out to 13.1-msecs. The code also only allows the 1-2ms pulse to be sent every 4 interrupts. How is he getting away with sending a pulse every 52.5ms. Does this seem right to you?
As I understand the following set the prescale, postscale, RP2 registers. The following sets pre=16, post=16, PR2=255
Code:
// Timer2 prescale = 16
T2CONbits.T2CKPS0 = 0;
T2CONbits.T2CKPS1 = 1;
// Timer2 postscale = 16
T2CONbits.T2OUTPS0 = 1;
T2CONbits.T2OUTPS1 = 1;
T2CONbits.T2OUTPS2 = 1;
T2CONbits.T2OUTPS3 = 1;
// Timer period = maximum
PR2 = 0xFF;
// Timer2 is on
T2CONbits.TMR2ON = 1;
// Enable Timer2 interrupt
PIE1bits.TMR2IE = 1;
(200-nsecs * prescale 16 * postscale 16 * PR2 256) which comes out to 13.1-msecs. The code also only allows the 1-2ms pulse to be sent every 4 interrupts. How is he getting away with sending a pulse every 52.5ms. Does this seem right to you?