Switch on/off every sine pulse


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2006
    Posts
    36

    Default Switch on/off every sine pulse

    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

  2. #2
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Zero Crossing

    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

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Chris, the attached application note could be of interest to you.

    Al.
    Attached Images Attached Images
    All progress began with an idea

  5. #5
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Which PIC do you plan to use ?

    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.
    Regards

    Sougata

  6. #6
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Which PIC

    Quote Originally Posted by ChrisHelvey View Post
    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.
    Quote Originally Posted by ChrisHelvey View Post
    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.
    Quote Originally Posted by ChrisHelvey View Post
    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.
    Regards

    Sougata

  9. #9
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Pulse Capture and byte building
    By boroko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st July 2009, 01:59
  2. 'Soft' On/Off Power Switch
    By Art in forum General
    Replies: 19
    Last Post: - 14th November 2008, 01:54
  3. Replies: 3
    Last Post: - 13th September 2008, 17:40
  4. How to read pulse from reed switch
    By passion1 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th June 2007, 14:29
  5. Switch PIC16F877 ON/OFF
    By koossa in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 27th August 2005, 12:34

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts