Detecting a pulse


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1


    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

  2. #2
    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

  3. #3


    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

  4. #4
    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

  5. #5


    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 : 0

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