All About Circuits Forum 50/60Hz Frequency conversion using PIC
 Register Blogs FAQ Members List Today's Posts Search Today's Posts Mark Forums Read

 The Projects Forum Working on an electronics project and would like some suggestions, help or critiques? If you would like to comment or assist others with their projects, this is the place to do it.

#1
07-04-2009, 02:41 PM
 eblc1388 Senior Member Join Date: Nov 2008 Location: UK Posts: 1,542
50/60Hz Frequency conversion using PIC

For electric clock using synchronous motor designed for the other frequency vs local mains frequency, some form of frequency conversion is required.

It is often not satisfactory to use just a crystal oscillator as one can expect timing error of about 1~4 minute per month, with the changing of ambient room temperature. An AC connected clock will do much better in long term period of months or year as the power company often undertake to correct for any timing error between an AC powered clock and an accurate time source by varying system frequency to compensate.

In simple term, the converted frequency must be somehow related/locked to the mains frequency and the clock powered by this frequency will keep time fine as any other clock.

There are many possibilities:

A. using a single 8-pin PIC - By eblc1388

1. single chip solution, works also for 60Hz into 50Hz
2. standalone 50Hz or 60Hz standard frequency output, crystal accuracy
4. software ensure exact cycles tally. e.g 600 cycle of 60Hz vs 500 cycles of 50Hz

YouTube: 50/60Hz Frequency Conversion Using PIC

B. Phase locked loop & 600Hz to 60Hz direct conversion - By eblc1388

1. use x6 PLL to get 600Hz square wave from 100Hz
2. use 5-stage ring counter to build staircase waveform(see image below)
3. pass staircase waveform to RC filter to get 60Hz sine wave

Forum Post#32: frequency multiplier

C. Harmonic method - By Rod Elliott

1. Picking out the sixth harmonic of 100Hz (50Hz fullwave rectified) signal
2. amplified and squaring the signal to get 600Hz square wave
3. divide by 10 to get 60Hz square wave
4. pass into active filter to remove all higher harmonic leaving fundamental 60Hz sine wave

The link is here: Frequency Changer for Low Voltage Synchronous Clocks

The bottom trace is the combined waveform output of the five stage ring counter and the top trace signal after RC filter, mentioned in option B above.

Attached Images
 P005a_60Hz_From_4018.jpg (94.8 KB, 132 views)
__________________
L.Chung
#2
07-06-2009, 01:40 PM
 THE_RB Senior Member Join Date: Feb 2008 Posts: 5,222

Really nice! I've been watching the frequency conversion threads.

Here is some minimalist math to add to the list, it converts 120Hz to 1200Hz, then generates 100Hz locked to the orig 120Hz. For use in clocks/timers etc that display hundredths of seconds but are still locked to 60Hz mains.

It will also convert 100Hz->120Hz, 50->60, 60->50 etc with zero-error using the very simplest of math (a bresenham accumulator system) and just 2 variables;

Code:
```	// C code for low-jitter generation of 100Hz from 120Hz mains
// PIC code, 4MHz xtal, TMR1 at 1:8 prescale
// uses 2 variables;
//   unsigned int bres
//   unsigned char pulse

start:

// wait here for 120Hz pulse
while(!check_120Hz());

// now generate 10 "fake" pulses, each is "1200Hz"
// which is 833uS. PIC 1Mhz xtal, TMR1 1:8 prescale,
// we use TMR1L period of 104 = 832uS
// note! TMR1L loop is also another zero-error system
// that we keep subtracting 104 from while retaining
// its internal error.

pulse = 10;		// make 10 "fake" pulses
TMR1L = 0;		// make first pulse immediately

while(pulse)
{
// wait here for fake 1200Hz pulse
while(TMR1L.F7);

// now fix TMR1L and do the main bres event
TMR1L -= 104;	// subtract 1/1200th of a second

bres += 100;
if(bres >= 1200)	// if 100th sec reached!
{
bres -= 1200;
do_100th_event();	// update clock, etc
}

// subract a pulse, see if 10 done yet
pulse--;
}

// gets here after 10 "fake" 1200Hz pulses,
// need to detect a real 120Hz pulse, then
// do it all again!

goto start;```
Select All
http://www.romanblack.com/one_sec.htm
and there's more code on that page for generating exact 1 second periods for clock use etc.
#3
07-06-2009, 05:36 PM
 eblc1388 Senior Member Join Date: Nov 2008 Location: UK Posts: 1,542

Well in digital clocking one can wait until the correct moment to do things, or puts out all the required pulses within 10% of the start of the whole interval. The counter that accept the clocking pulses would not care.

In analogue world, the AC sine waveform cannot be put on hold, and one cannot have 3/4 or 1.25 cycles of a waveform and then suddenly starts a new one.
__________________
L.Chung
#4
07-07-2009, 02:46 PM
 THE_RB Senior Member Join Date: Feb 2008 Posts: 5,222

I agree. That is exactly the problem that the code I posted fixes. It acts as a mathematical PLL.

That is why it is in the advanced section of the page and labeled as "low jitter".

 Tags 50 or 60hz, conversion, frequency, pic

 Similar Threads Thread Thread Starter Forum Replies Last Post PRS General Electronics Chat 24 05-17-2009 11:17 PM ibrahim Embedded Systems and Microcontrollers 1 01-13-2009 09:55 AM garry.owens The Projects Forum 8 12-20-2008 09:12 AM relicmarks General Electronics Chat 14 05-03-2008 06:50 PM relicmarks General Electronics Chat 25 04-28-2008 08:18 AM

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Electronics Forums     General Electronics Chat     The Projects Forum     Homework Help     Electronics Resources Software, Microcomputing, and Communications Forums     Programmer's Corner     Embedded Systems and Microcontrollers     Computing and Networks     Radio and Communications Circuits and Projects     The Completed Projects Collection Abstract Forums     Math     Physics     General Science All About Circuits Commmunity Forums     Off-Topic     The Flea Market     Feedback and Suggestions

All times are GMT. The time now is 12:33 AM.