TMR2 output and the SPI block

Started by Dennis Clark March 3, 2006
   I'm running a 18F6680 at 40MHz which means that the SPI clock's 
slowest setting would be 625KHz, which requires a pretty fast set of 
opto isolators in my  case.  I'd like to run it a bit slower.  TMR2's 
output can be used as the SPI clock, but I'm curious as to the details. 
  Does the PR2 register control this register output?  The document 
isn't that clear - IOW, if I have a 40MHz/4 clock, and PR2 is set to 
255, do I get a 40MHz/4/256 = 25.6KHz clock to the SPI module?  I'd like 
to run this module between 50KHz and 100KHz to keep the cost of the 
optos down.

Has anyone done this and know?

thanks,
DLC
-- 
---
Dennis Clark    TTT Enterprises
---

Dennis,

TMR2 has a prescaler or 1/1, 1/4 and 1/16 which can be applied to
Fosc/4 first.  The value of PR2 will be the point at which TMR2 is
reset to start counting up again from zero. I.e., if you set PR2 to 1,
TMR2 will reset every second count, set PR2 to 2 and TMR2 will reset
every third count, therefore TMR2 division == PR2+1.  You can check the
CCP section for a better explanation.  There is also a post scaler on
the match output settable between [1-16]/1.

I think your output should be Fosc/(4 * Prescaler * (PR2 + 1) *
Postscaler)  Therefore your lowest TMR2IF frequecy would be 1525.878906
Hertz with a 40 Mhz clock.  

Check my math.

Chad
	--- Dennis Clark <dlc@dlc@...> wrote:

>    I'm running a 18F6680 at 40MHz which means that
the SPI clock's 
> slowest setting would be 625KHz, which requires a pretty fast set of 
> opto isolators in my  case.  I'd like to run it a bit slower.  TMR2's
> 
> output can be used as the SPI clock, but I'm curious as to the
> details. 
>   Does the PR2 register control this register output?  The document 
> isn't that clear - IOW, if I have a 40MHz/4 clock, and PR2 is set to 
> 255, do I get a 40MHz/4/256 = 25.6KHz clock to the SPI module?  I'd
> like 
> to run this module between 50KHz and 100KHz to keep the cost of the 
> optos down.
> 
> Has anyone done this and know?
> 
> thanks,
> DLC
> -- 
> ---
> Dennis Clark    TTT Enterprises
> ---
>
	My software has no bugs, only undocumented features.