Detecting a pulse


Closed Thread
Results 1 to 18 of 18
  1. #1

    Default Detecting a pulse

    Hi all

    Because of the amount of power failures in our area , I am building a circuit to auto-switch my generator because it's quite a mission getting up at 2am sometimes to go and switch it on when there is a power failure.

    I plan to use an opto-isolator initially to detect the power failure however some form of zero-crossing detection may also be a consideration.

    This of course raises a good few (maybe silly for some) questions:
    1.Which would most accurately detect the pulses ? PULSIN or COUNT? are there other methods?
    2.Using either of these does the incoming pulse have to be a known value or can on just check to see if a pulse (ofany/unknown size) exists ?
    3.Have I chosen the correct RTC (DS1302) for the job ?

    I have been searching the forum for the last few days but haven't qyet found the right example.

    I really would appreciate some advice or guidance on how to detect the pulse and absence of a pulse just to get me started.


    Kind regards

    Dennis

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Use a rectifier (1N4004) and a 10K 2W resistor in series with the LED side of an optoisolator. Put another rectifier across the LED in the reverse direction to protect it against reverse voltage. Connect these across the power line. Put a 10K resistor on the collector of the phototransistor to 5V. The output will be an isolated 50 or 60 Hz square wave.

    I would use an interrupt to "watch" this, so your PIC could do other things while watching the power line. Of course the output of the phototransistor will only be LOW for each half-cycle, so if you sampled the phototransistor every 5 ms or so, and it never went low, it would be an idication that the power was "gone'. Note that the rising and falling edges of the square wave will be very close to the zero-crossings of the power line.
    Charles Linquist

  3. #3
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    OK, I gotta be curious... is the whole purpose of this *just* to start a generator?
    Do you really need to detect zero crossing and all that?

    How about just stepping down the voltage (little transformer), rectifying and putting a small filter cap on the output. Feed it to a PIC pin. If the pin is high... got power. If the pin is low... no power. Poll the pin about once a second should be fine for starting a generator, eh?
    Seriously. How quickly do you need to get a generator running? How quickly will it even start? It seems a few seconds delay without power is inevitable if you gotta start an engine.

    Of course maybe you have other ideas for this that need the zero crossing anyway?
    Just curious...

    Heck, I still gotta go out in the rain and put a hand crank on mine to start it.


    steve


  4. #4


    Did you find this post helpful? Yes | No

    Default Awesome suggestion :-)

    @Steve :-)

    That's some Geni , what's the output ? Can't be fun switching it on at 2AM :-)
    Mine has electric start :-) will try get a pic up this week for you :-)

    Great idea !

    I suppose component count and power draw are two reasons why I would go with the sensor.
    Searching the forum for lamp-dimmer and mains detect shows huge amounts of info for this kind of thing.
    As per quite a few app notes and posts I have seen, a single resistor can be used from LIVE and directly into a PIC pin as a zero-crossing sensor.
    OR you can use the opto-isolator.
    All that remains then is to check that you are getting a pulse on the pin.
    I would like to try the opto-isolator option first but am unsure as to whether to use PULSIN or COUNT (or another method) to check the pulse and what that little line of code should look like.

    Kind regards

    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    I humbly beg to differ here. Why do you even need a PIC to do this? A simple mains rectifier output indicates power present. Similarly, when the power fails, the reservoir capacitor will hold the voltage a little while before indicating mains failure(takes care of short power glitches if you get them)
    Sizing this value appropriately can give you some delay before you command the generator to switch on.

    In short, mains adaptor -> transistor inverter -> relay is all that is needed to achieve this.

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Or an AC relay plugged into an outlet!
    Charles Linquist

  7. #7


    Did you find this post helpful? Yes | No

    Default OK...

    It seems a sentence was left out of my posting!

    I wish to log the power failure durations, times and dates as well and that's why I would like to use a PIC as well an an RTC.
    The PIC cirucit would either form part of an existing circuit or be battery/solar powered and have little or no draw on my home circuit.

    Kind regards
    Dennis

    Quote Originally Posted by Dennis View Post
    Hi all

    Because of the amount of power failures in our area , I am building a circuit to auto-switch my generator because it's quite a mission getting up at 2am sometimes to go and switch it on when there is a power failure.

    I plan to use an opto-isolator initially to detect the power failure however some form of zero-crossing detection may also be a consideration.

    This of course raises a good few (maybe silly for some) questions:
    1.Which would most accurately detect the pulses ? PULSIN or COUNT? are there other methods?
    2.Using either of these does the incoming pulse have to be a known value or can on just check to see if a pulse (of any/unknown size) exists ?
    3.Have I chosen the correct RTC (DS1302) for the job ?

    I have been searching the forum for the last few days but haven't yet found the right example.

    I really would appreciate some advice or guidance on how to detect the pulse and absence of a pulse just to get me started.


    Kind regards

    Dennis

  8. #8
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Aha!
    I figured there must be more to it than just getting the beastie running at 2AM.

    Data logging is a good use for a PIC.

    Just detecting lack of AC power to start a motor is not.

    steve

  9. #9
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    @Steve :-)
    That's some Geni , what's the output ? Can't be fun switching it on at 2AM :-)
    6HP @ 650RPM. Aprox 4KW max output and it'll run on just about any flammable liquid you've got.


    Mine has electric start :-)
    Yeah, I've heard about guys like you.

    Maybe electric start for me someday. I've got enough tools and steel to build something for it, but it ain't real high on the priority list.

    I don't start it much at 2AM though...
    I start at when I get up and kill it when I sleep.
    I have enough 12 volt lighting (and big batteries) to get me through the night, and I can always fire up the 1KW inverter if I really need AC at night.


    I'd be scared to do any data logging here and find out how many days a year our power is really out.

    steve

  10. #10


    Did you find this post helpful? Yes | No

    Default still digginig ...

    @Steve .. at least you have the geni for those outages :-)

    @ any and everyone ... is there really no simple command like
    IF PULSE EXIST THEN ... ?

    Kind regards

    Dennis

  11. #11
    timmers's Avatar
    timmers Guest


    Did you find this post helpful? Yes | No

    Default

    When I worked in Nigeria a few years ago, we employed somebody to start the generator and switch over from utility supply to generator supply. Worked fine, no getting up at 2am like some!

    -trouble started when we bought a new generator. We instructed our gen-starter how to check the oil and and where to dip his finger to check the water (couldn't see the level due to the soundproof case).
    When we came home later that day, he was busy pouring water into the generator from a watering can. after his second refill I became curious as to why the generator was needing so much water, and there on the top of the case, was the oil filler cap as another 2 gallons disappeared down to the depths of our brand new generator. When I pulled the dipstick out, a spout of water flowed.

    After that episode I sacked the gen-starter and I built a PIC based auto starter, which would check the incoming 3 phase for over volts (occaisionaly), under volts (often), one or all phases missing (very common) and then switch over as required. It had a variable brown out facility to prevent reccuring start / stop and control of other variables like cranking time out and cool down runs. It even switched the contactor from utility to local automatically. It used 3x opto couplers to monitor the 3 phases and 3 relays for run, glow & crank.

    Worked a treat!

  12. #12


    Did you find this post helpful? Yes | No

    Default haha

    @trimmers
    That definitely is a classic :-)
    So the initial code would have been something like
    Code:
    If water_level exist then 
    goto sack_gen_starter
    else goto use_PIC
    end if
    Thanks for the info

    Dennis

  13. #13
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Other fun and useful stuff that might be added, with various levels of cost and complexity:
    • Log generator run time
    • Monitor / Alarm fuel level
    • Monitor /Alarm engine or generator winding temperatures
    • Count power outage events / Log power out time
    • Monitor output power or voltage and current demand
    • Auto start periodically to maintain bearings and equipment health...alarm if no start
    • etc ...

    This is what I love about the versatility of using PIC chips.
    Wozzy-2010

  14. #14


    Did you find this post helpful? Yes | No

    Default still searching...

    @WOZZY-2010 yes plenty that can be added.
    Hardest part would be getting a fuel top up :-)

    OK so still no replies regarding a simple IS PULSE EXISTS command ?
    I can easily detect zero-crossing but need to know how to check for th
    I was thinking of just checking for an absolute minimum pulse using PULSIN or use COUNT since AC has a 50% duty cycle and I would be checking a frequency of 50Hz or 60Hz but how do I set the period to be infinite ?
    Using this approach I could say something like WHILE COUNT_VAR > 1

    So here are the questions ?

    1. Can COUNT period be set to inifinity ?
    2. Can COUNT be set to a tight loop to count mains pulses so a variable always stays high so that I could say something like IF COUNT >1 THEN AC EXISTS ?
    3. If I used and interrupt on change for every zero-crossing could the interrupt be checked ..something like if interrupt exists then ... or if no interrupt exists then ...

    Any thoughts/ideas are welcome ?

    Kind regards

    Dennis

  15. #15
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Again - I don't know what else your PIC must do at the same time, but PULSIN and COUNT are generally bad, since your code can do NOTHING ELSE during the count interval.

    If that is the case just do something like:

    Code:
      CLEAR
    
    Topp:
    
       IF  InputPin = 0 THEN
            Counter = 0
       ENDIF
    
       IF Counter > 2 then goto PowerGone   
       IF Counter < 254 THEN Counter = Counter + 1
       Pause 5
       Goto Topp
    
    
    PowerGone:
       HSEROUT ["Turn on the Generator"]
       Pause 10
       END
    Charles Linquist

  16. #16


    Did you find this post helpful? Yes | No

    Default ooops

    @Charles

    Thanks very much for both replies and apologies for not replying tot he first one, I think for some reason I got sidetracked after reading it (it suddenly got some thoughts going) and I forgot to reply :-(

    Regarding the latest posting you have made... what exactly do you have in mind with this code ?
    Code:
    IF  InputPin = 0 THEN
            Counter = 0
       ENDIF
    
       IF Counter > 2 then goto PowerGone   
       IF Counter < 254 THEN Counter = Counter + 1
       Pause 5
       Goto Topp
    Are you suggesting I have a zero-cross detector on 'InputPin' ?

    And Counter > 2 ?
    What are we counting ?


    Kind regards
    Dennis

  17. #17
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    There are dozens of ways to do this, but in this case, I'm referring to the circuit that I described earlier - an optoisolator. The input pin in my code would be connected to the collector of the phototransistor in the optocoupler. If you build the circuit I described, you will find that the output of the opto is a square wave, with a period equal to the period of your AC (60 Hz = 16.666 ms, 50Hz = 20 ms). The output will be low for one half-cycle (8.3ms or 10 ms) and high for the other half-cycle. The low-to-high and high-to-low transitions will occur on the zero-crossings of the AC. The circuit only detects "positive" half-cycles.

    The counter increments every 5 msec, but if a half cycle comes along, the counter gets cleared (because the pin is low), and the count never gets above 2. If a positive half-cycle is missing, the counter increments to 3 and you get an indication that your power is gone.



    PULSIN and COUNT are sometimes called "blocking" commands because between the invocation of the command and the timeout, the code can do nothing else. I generally avoid them at all costs.
    Charles Linquist

  18. #18


    Did you find this post helpful? Yes | No

    Default OK...

    @ Charles

    Once again thanks for the reply ...!

    Will feedback once I have something functional :-)

    Kind regards

    Dennis

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. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  3. How to reverse polarity on output pulse??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th June 2009, 13:25
  4. Replies: 3
    Last Post: - 13th September 2008, 17:40
  5. Pulse Frequency Multiplication
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st August 2005, 10:39

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