[time-nuts] A Simple PIC Divider

Chuck Harris cfharris at erols.com
Sun Aug 6 23:51:31 EDT 2006


Hi Tom,

The CCS C compiler does just fine.  When you use the delay function,
it is smart enough to know when it is better to insert a few NOP
instructions (and other time wasters), and when it is better to toss
in a loop.  The code it generates is generally better than I can do
myself using assembly, and I have been programming in assembler, off
and on, for more than 25 years.  There just aren't that many different
ways to do things with a risc processor.

If I wanted to divide a 10MHz clock down to 100KHz, I could do something
like:

#include <12F629.h>

#use delay(clock=10000000)
main()
{
	while(1){
		delay_us(5);
		output_toggle(PIN_A0);
	}
}

Or, if I wanted a 1PPS output, I would just have to change the delay_us(5)
instruction to delay_ms(500).

If you look at the resulting code, you will find it is as lean and bare as
you would code by hand.

A buck for a 10 MHz to 1PPS divide chain in an 8 pin dip is kind of hard
to beat (that could be a really bad pun!).

-Chuck





Tom Van Baak wrote:
>> I don't think any of those chips has a serial port.  You would have to do 
>> (heroic) bit-banging if you needed that.
> 
> True, although simple, robust, and free code samples
> for this are all over the web. Or as Chuck mentioned,
> serial support is included in various PIC compilers.
> 
> One caution, though. Most high-level languages are
> not compatible with the fixed instruction loop count
> code technique used in the pic divider.
> 
> /tvb
> 
> 
> 
> _______________________________________________
> time-nuts mailing list
> time-nuts at febo.com
> https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
> 



More information about the time-nuts mailing list