Fractional frequency division

fernando_g

Senior Member
This circuit appeared on the Circuit Notebook column of Silicon Chip's August 2009 issue.
By kind courtesy of Mr. Leo Simpson, he gave me permission to share this circuit in this forum.

Sometimes there is a need to divide a frequency by a ratio which is not a whole number. Imagine that you have a line-synchronized timekeeping device that you would like to back up with a common 32.768 KHz watch crystal. For a 50 Hz device, performing a little arithmetic yields a division ratio of 655.36 which is not achievable with a simple counter; and if you divide down by either 655 or 656, the resultant frequency will be either a little fast or a little slow.

There is a simple technique around this limitation that may be implemented with a PICAXE08M and a presettable jam counter CD4059. First we calculate the required ratio by dividing 32768 by 100 = 327.68; the reason to divide by 100 instead of 50 will become apparent shortly.

Now, the decimals in the ratio may be expressed as a fraction, and thus 327.68 = 327 17/25, which essentially means that in a 25 period time frame, 17 of those periods will be divided down by 328, and the remaining 8 will be divided down by 327.

Or put in another way: (328*17 + 327*8)/25 = 327.68, which is our required ratio.

In this circuit, the CD4059 will perform the actual counting, and the PICAXE will assist it by counting periods and setting high or low the appropriate jam inputs. Additionally, since the output of the CD4059 is a narrow pulse, the PICAXE will perform the final divide by two and provide a squarewave with a duty cycle very close to 50%.


If the desired frequency is instead 60 Hz, we follow the same approach described above and calculate the required ratio as 273.06666667; which means in a 15 period time frame, 14 periods will divide by 273 and 1 by 274.

In equation form: (273*14 + 274*1)/15 = 273.06666667

Since this technique operates by speeding and slowing the counts, the instantaneous frequency will be slightly off. However once the total count period has been completed (every 1/4 second), it will be exactly correct.
This frequency dithering is of no concern for normal timekeeping equirements, but you should be aware of it.

After I had this circuit published, I became aware of Maxim's DS1388 RTC/Trickle Charger/Supervisor IC, Which employs an identical technique to divide down from 4096 Hz down to 100 Hz.

Code:
'Frequency divider for picaxe 8M and CD4059
'32768/ 100 = 327.68
'327.68 = (328*17 + 327*8)/25
'Out0 = Jam J1,J5 & J6; Out1 = Jam J7; Out2 = Latch; Out4 = 50 Hz out
'Input 3= Main interrupt


setfreq m8
let dirs = %00010111
high 2				'enable latch
setint %00001000, %00001000 	'interrupt on 100 Hz pulse high 

main_timebase: 
goto main_timebase		'wait until interrupted

interrupt:				
toggle 4				'toggling divides interrupt frequency by 2
low 2					'reset latch
inc b0				'increment loop count

select b0
case 1 to 17			' divide by 328
low 0 : high 1

case 18 to 24			' divide by 327
high 0 : low 1

else					'outputs 0&1 don't change,this is iteration 25
let b0 = 0					
endselect

high 2				'enable latch
setint %00001000, %00001000 	'interrupt on 100 Hz pulse high 
return
Code:
'Frequency divider for picaxe 8M and CD4059
'32768/ 120 = 273.0666667
'273.0666667 = (273*14 + 274*1)/15
'Out0 = Jam J1; Out1= Jam 5; Out2 = Latch; Out4 = 60 Hz out
'Input 3= Main interrupt


setfreq m8
let dirs = %00010111
high 2
setint %00001000, %00001000 	'interrupt on main timebase pulse high 

main_timebase:  			'loop until interrupted
goto main_timebase

interrupt:
toggle 4				'toggling divides interrupt frequency by 2
low 2					'reset latch
inc b0					

select b0  			
case 1				'divide by 274
high 1 : low 0 				
 				
case 2 to 14			'divide by 273
low 1 : high 0				

else  				'outputs 0&1 don't change,this is iteration 15
let b0 = 0 				'start loop again	
endselect

high 2					'set latch
setint %00001000, %00001000 	'interrupt on main timebase pulse high 
return
 

Attachments

Last edited:

Jeremy Leach

Senior Member
Looks clever stuff. Not looked at the detail here, but I'd have thought maybe you could do the same purely in code on a 28X1, 28X2, 40X1, 40X2 - by using the external counter facility (via SetTimer command) and then tweaking the Timer preload value in the interrupt routine.
 

fernando_g

Senior Member
You may be right Jeremy. I don't know however, if the "X" devices will have the speed to count down at a 32 Khz rate. Certainly the lowlier PICAXE devices can't.

However, the purpose of this idea was really to illustrate a particular technique to divide by a non-whole number. It may be implemented in hardware/software or a combination.

Perhaps with the "X" devices, with their higher procesing speed and internal timer/counter, could use a similar approach to divide down a fairly high frequency (1 Mhz perhaps?) with the assistance of an external counter acting as a prescaler.
 
Top