Search This Blog

Friday, June 15, 2012

Bit/Bang SPI Speed of PIC18F6722

With all this work on uP's and ATMEL UC3 C Compiler Optimizations, I decided to take a look at one of my old workhorse processors the Microchip PIC16 and 18F families. I program these devices using the CCS PIC-C compiler.

Similar to the last post about UC3 processor timing when running Bit/Bang SPI type of IO quickly threw together some sample code for the PIC18F6722. I set the PIC up to run on a 10 MHz Oscillator with the 4X Internal PLL, giving a program instruction running rate of 10 MHz (the clock in these devices runs at 4 times the actual instruction rate).

The CCS compiler has a series of high level IO commands similar to the ATMEL ASF pin IO commands[1]. This mode is called “FAST_IO” and what it does is allow you to set the direction of the port pin then using a high(er) level command to set any Pin anyway you want it (using the output_bit() function).

I also built a function using direct IO. This is where C really hits the road! In CCS C we are able to directly define any bit or pin in a port using a #bit directive, then just using PIN = 1; or PIN = 0; in my program we can set that pin as requested with just one CPU instruction.

So on to the testing - since the CCS compilers that I use are always optimizing and there are no real optimization switches, we get just one number for comparison - the clock frequency of the Bit/Bang IO function (the code is very similar to the previous post on UC3 IO Optimization[1]).

=======================================================================
Using FAST_IO the SPI clock pin frequency was: 560 kHz

Using direct Pin Banging the SPI clock pin frequency was: 716 kHz
=======================================================================

Not blindingly fast compared to the UC3, but the PIC was using lots less power and is fast enough for many useful applications, in fact we have been using PIC's to successfully control all sorts of things from: Temperature Chambers to Cellphone Monitoring Radios since 1994.

Steve Hageman
www.AnalogHome.com

[1] Previous Post: http://analoghome.blogspot.com/2012/06/atmeluc3-32-bit-processors-and-gcc.html

No comments:

Post a Comment