Mains Zero Crossing Detector.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Mains Zero Crossing Detector.

Post by medelec35 »

I am using a 12f675 with a high value single resistor connected between live and pin 6 (GP1).
Vss is connected to Neutral.

There will be an analogue voltage (0 to 5V) present at pin 7 (GP0). The higher the voltage then the lower time delay pin 2 (GP5) will be set high only on mains zero detection,
This attached Flowcode works 98ish percent of the time.
However there are odd times when zero mains is not detected.
GP5 is high for a maximum of 9.2ms, since ½ cycle lasts for 10ms and start of timer is at mains zero then I can’t see why the main zero is missed. Also some cycles are missed when GP5 is high for shortest time of 3ms

My question is:
Are there better ways of mains zero detection other then using port change interrupt?
Or is there a better way of using interrupt for zero detection?

GP2 /Int is used for over current detection, however GP2 is currently shorted to 0V
Attachments
12F675 PWM to AC12.fcf
(10 KiB) Downloaded 510 times
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Mains Zero Crossing Detector.

Post by medelec35 »

Ben or Steve.
Can you please say why there have been no answers to the above post?

Latest is: I have successfully managed to get my circuit to drive an AC motor. The speed can now be fully variable from off to full speed. with no mains hum at any speed. Although circuit is 100% working, I would like to solve the following issue:
Time duration between pulses when motor is running at full speed, alternates between 1.5 and 3ms.

The reason for this difference is due to the point around zero crossover in which pulse is triggered is not the same for positive to 0V as it is for negative to 0V. This is caused by the sample voltage can be between 0.68V and 0.048V.
In an ideal would I would like to tighten this gap, but if gap is too small, then zero point will be missed.
These two voltages represent two different points of the AC mains sine wave.

With mains frequency of 50Hz and PIC running at 4MHz I am surprised that a single voltage can be missed yet alone a voltage gap narrower than 0.6V.

So is there a better way to detect Zero crossing?
In this Flowcode, I am not using port change interrupt, due to amount of times zero points were missed.
I had thought of using the comparator part of the PIC chip, but I am trying to keep component parts to the minimum.
I'm not using rise or fall interrupt since that has priority if current drawn exceeds a predetermined value.
Any advice would be much appreciated.
Attachments
12F675 PWM to AC16.fcf
(16 KiB) Downloaded 542 times
Martin

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Mains Zero Crossing Detector.

Post by Steve »

I suppose the main reason that there have been no answer to your post is because we're all working flat-out to get v4 of Flowcode out. This has got to be our priority.

We do often help with our user's specific projects, but this is not our main role. It can be time-consuming, and is often very difficult when we do not have access to the actual hardware being used. We are here to offer advice and to fix issues with Flowcode itself. Of course, we will try to help out whenever we can. But this cannot be guaranteed.

I'm surprised that the interrupt is missing 2% of the zero-crossing points. If the interrupt routine is sufficiently brief and the hardware is creating the appropriate interrupt condition, then this should not be a problem. One of the latest articles contains advice on how to use interrupts and would be a good place to start.

Post Reply