Sceadwian- The dual sine generator above was running 10MHz xtal and making 50Hz output. With a 12MHz xtal the same code makes 60Hz output. (If you are referring to the CRO timebase I usually turn the vernier to get a better onscreen display)
Pasanlaksiri- It's not gum its blu-tak!! Every electronics workshop needs globs of blu-tak within handy reaching distance.
I did the 50Hz to 60Hz mains locked converter this morning. It so hot here I was getting up every few minutes for refreshments so it took twice as long as expected.
However the result was excellent. Here is the dual output push-pull manually generated PWM sinewaves at 60Hz, sync-locked to the 50Hz mains;
**broken link removed**
**broken link removed**
The top trace is my 50Hz mains input, from a 12v AC transformer (and fed into the simple filter shown in the schematic)
into PIC pin GP2. The pulses are about 0v-4v.
The bottom trace is the rock solid mains locked 60Hz sine output (one of the 2 outputs).
The code is set up for a 8MHz xtal as they are more common than 10MHz, and I fine tuned the "virtual pulse" period in the interrupt to compensate for the 16 inst interrupt latency.
Code:
void interrupt()
{
//-----------------------------------------------------
// This is a TMR1 overflow interrupt for 23 of 24 cases.
// on 1 of 24 cases it acts as a GP2 interrupt on \ edge.
// This is used to generate exactly 24 virtual pulses,
// synchronised to the 50Hz mains input (GP2 \ edge).
//-----------------------------------------------------
if(!vpulse) // if it is last vpulse0
{
// just leave TMR1 free running, this allows easy first sync!
vpulse = 23;
}
else // else is vpulse1-23
{
TMR1L = (256 - (PERLO - 3 - 16)); // load TMR1 for 1 vpulse period
TMR1H = (256 - (PERHI + 1));
vpulse--; // sequence the next virtual pulse
INTCON.INTF = 0; // clear GP2 \ edge int flag
}
step++; // sequence the next 60Hz PWM step
PIR1.TMR1IF = 0;
}
The interrupt system generates ONE interrupt from the edge of the 50Hz mains cycle and then 23 interrupts (virtual pulse periods) generated from TMR1. So it generates exactly 24 equally spaced pulses for every 50Hz mains cycle.
Then the 60Hz dual PWM outputs are sequenced from 20 virtual pulses, the same basic system as the code example and diagram further up the page.
The full project and source code is here.