PDA

View Full Version : Switch on/off every sine pulse



ChrisHelvey
- 26th July 2009, 03:06
Hello everyone,

I'm getting more comfortable with PicBasic Pro now and have some successful (albeit fairly simple) projects under my belt. (Still feel quite intimidated by you pros sometimes though...) I have a project that I wonder if a PIC is suitable for, keeping in mind I'm still more comfortable with PICBasic Pro than I am very complex circuits. I really just need to know if it is doable or if I'm barking up the wrong tree here. Any other simple ideas are welcomed.

I need to sense zero crossing of a 60hz sine wave (regular US outlet power) and turn one PIC port on and another off AT EVERY crossing. So, 120 times every second. Although this does not have to be exactly at zero, the closer the better.

The high/low pin(s) will turn on/off a set of IGBTs which will let the current for that (rectified) pulse through. In other words, there are two different paths for the current and it switches at each pulse. Clear as mud?

There are many reasons I would like to keep this in the PIC environment if it is possible, I would just like some feedback before I start turning my den into what my wife calls a "mad scientist lab."

I am open to using any PIC model - cost is not a huge factor in this experiment. Oh yeah, if you were wondering the obvious, a diodes-only circuit design doesn't cut it.

Thanks in advance,

Chris

Bill Legge
- 26th July 2009, 05:19
Chris

First of all - I'm a well out of date electronics engineer and only two years into hobby PIC programming. In no particular order, thoughts on your proposed project:

1. Sensing the crossings. Isolate the PIC/MCU and yourself from the mains voltage with a transformer. I don't know your level of electronic expertise (appologies in advance) but watch out for peak and RMS values. You want an AC voltage, for analysis by the PIC, with a peak to peak of 5 Volts.

2. I can't remember what phase change one gets across a transformer - but the zero crossing on the low voltage side may differ from the mains side?

3. Finding the zero crossing 120 times a second. If you use a PIC16F877A you will have the option of finding the crossing by A/D, comparators and so on. With a 20 MHz Xtal that is 5 instructions per microsecond or nearly 42,000 in one half mains cycle - sounds like enough to do lots of processing?

4. Recently, I was using Light Dependent Resistors and noticed that there was a 'mains hum' on the LDR. LDRs are not particularly fast or sensitive and a photo transistor would be better. How about:

a. Step down the mains voltage and drive an optocoupler chip (6N138 or something like it) via a current limiting resistor.

b. The LED in the optocoupler would only go ON for one half of the mains cycle - so you know which half it is.

c. On the output side you have an output that you can feed into the PIC.

d. use A/D or comparators, delays and so on to get the output signal you need.

Sorry, I've banged on. I'm told it goes with my age

Regards Bill Legge

Jerson
- 26th July 2009, 07:11
This may be a slightly different approach. This is how I do dimmers in microcontrollers.

1. Full wave rectify a stepped down ac waveform to get the typical full wave rectified waveform (2 crests per cycle)

2. Use a comparator to interrupt you whenever the crest is close to zero.

3. Once you have this, you could do whatever you want with the signals

aratti
- 26th July 2009, 08:51
Chris, the attached application note could be of interest to you.

Al.

sougata
- 26th July 2009, 14:01
Hi,

Which PIC do you plan to use ? Any PIC with an External interrupt works here. Would you be sensing the mains directly (120VAC / 60Hz) or you would be using a step down transformer for the sensing the Zero Cross.

ChrisHelvey
- 26th July 2009, 23:21
Thanks to everyone who replied. Sounds like this will be a "go" then. I didn't hear anyone hitting the brakes, so I'll give it a shot. Maybe I can even try out using Darrell's instant interrupts to get the quickest response.

Since the only purpose of the zero crossing detect is to turn on/off two sets of IGBTs, I intend to interface the mains directly to the PIC and let the internal clamping do its thing.

Now, I'll start looking for some code snippets to give me a place to start...

Should I use the "port change" feature in the PICs that offer that?

I was thinking that, simply, the first half "positive" side of the sine wave would be detected as "on" and the "negative half would be "off."

Now for the embarrassing newbie question: I understand how to detect an interrupt change, but how do I test whether voltage is swinging toward positive or toward negative (zero)? I assume capture/compare has something to do with it. I don't yet know how to do that, but it is time to jump in.

I hope that question makes sense.

Thank you all for your input.

Chris

ChrisHelvey
- 27th July 2009, 00:06
I read up a bit on DT's wonderful instant interrupts. How cool is that!? I had heard of it here often but now I see just how powerful that thing is!

I understand that an interrupt can be generated from the comparator using "CMP_INT -- Comparator Interrupt" from his include.

So, conceptually, it is simply comparing to zero volts. Whenever that changes (not zero anymore,) then interrupt. Am I on the right path here?

OR maybe simply using the port change interrupt will work? Hmm, it needs to see a certain voltage before it is considered "on" though, huh?

Here is what I need it to do:
As V rises above zero, generate an interrupt. Then I'll tell the PIC to turn on a pin.
As V falls to zero, generate an (different?) interrupt. Then I'll tell the PIC to turn the above pin off and turn on a different one.

I'm just confused about the rising/falling or comparing part of it.

Anyone have a snippet related? (Is that kind of shameless asking allowed?)

Thanks everyone.

Chris

sougata
- 27th July 2009, 06:09
I read up a bit on DT's wonderful instant interrupts. How cool is that!? I had heard of it here often but now I see just how powerful that thing is!
Chris
The Coolest (greatest) possible extension to PBP Two different version for the x14 and x16 architecture. Very Pro very powerful......Free. DT has done a lot, lot hard work for us.


I understand that an interrupt can be generated from the comparator using "CMP_INT -- Comparator Interrupt" from his include.
The comparator generates an interrupt whenever there is a state change.


Anyone have a snippet related? (Is that kind of shameless asking allowed?)

I intended to give you one. That is why asked for the PIC you would be using.

ChrisHelvey
- 27th July 2009, 20:45
Ah, very good.

I will be working on an 18f4550. I have one here and it should offer what I need.

Thanks SO much in advance.

Chris