Help with Pic Delay Pulse code please


Results 1 to 37 of 37

Threaded View

  1. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by g7jiq View Post
    I hope this explains it.

    Any ideas,,

    Cheers
    Dave...
    Yes I see what you need now.
    I've approached this by starting a timer of 1 second (Delayticks = 100) every time the input is activated, by detecting the high to low transition of the input signal.

    On a long (good) signal the timer will elapse after 1 second because there have been no other high to low transitions of the input signal
    On a short droppy signal there are lots of high to low transitions, so the 1 second timer keeps being reset.

    By buffering the states of pins this way you can isolate high-low and low-high transitions, as well as both-high and both-low conditions. The program doesn't 'stop' in any wait loops so you should be able to add more functions inline, there is just the 10mS pause holding things up every iteration.

    It compiles alright. How does it work ?
    Chris




    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : Chris Barron *
    '* Notice : Copyright (c) 2009 Chris Barron *
    '* : All Rights Reserved *
    '* Date : 01/04/2009 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    '************************************************* * *************

    'G7JIQ MICRO LINK REPEATER
    'PIC 12F675
    'Internal RC clock
    '
    ' PIC Defines
    ' -----------
    @ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
    ' System Clock Options (Internal)
    @ DEVICE pic12F675, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic12F675, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic12F675, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic12F675, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic12F675, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE pic12F675, PROTECT_OFF
    ' Program Code Protection

    '
    ' Define Hardware
    ' ---------------
    InputTrigger var GPIO.5 ' Input normally HIGH, goes LOW to Trigger
    InputReset var GPIO.2 ' Input normally HIGH, goes LOW to RESET
    OutputLine var GPIO.0 ' Normally HIGH, goes LOW when triggered
    Led var GPIO.1

    '
    ' Define Variables
    ' ----------------
    DelayTick var Byte ' 100mS Tick Counter
    myflags var byte
    '
    ' Initialise PIC
    ' --------------
    Reset:
    TRISIO=%00100100 ' Preset I/O
    CMCON=%00000111 ' Disable Comparators
    ANSEL=%00000000 ' Disable ADC
    DelayTick=100 ' Reset Counter
    myflags = 0
    high OutputLine ' Everything RESET



    ' Main Program Loop
    ' -----------------
    Loop:
    '
    ' Test for RESET
    ' --------------
    While InputReset=0 ' Just wait here if RESET
    high OutputLine ' Reset Output
    myflags = 0
    DelayTick = 100
    Wend

    ' We're using the lower 2 bits of the 'myflags' register to store the state of
    ' the input pin over the last two program loop iterations
    ' myflags.0 stores the current pin state and myflags.1 stores the previous
    'state.
    myflags.1 = myflags.0 ' Move the last 'current state' into the 'last state' bit
    myflags.0 = InputTrigger ' Store the current state

    ' By storing the two states we can detect the transition from high to low
    ' A high to low transition = 00000010 = decimal 2
    ' A low to high transition = 00000001 = decimal 1

    if myflags = 2 then
    DelayTick = 100 ' A high to low transition, reset the delay
    else
    if delaytick > 0 then delaytick = delaytick - 1
    endif

    pause 10 ' adjust to get the resolution required (10 x DelayTick = total hang time)

    if inputtrigger = 0 then low OutputLine; if input is active set output active

    if ((inputtrigger = 1) and (Delaytick = 0)) then high outputline

    goto loop:
    Last edited by Chris Barron; - 1st April 2009 at 11:44.

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Help writing pic program with i/p o/p hold delay
    By g7jiq in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th May 2008, 21:58
  4. Pic driven digital audio delay
    By skimask in forum Off Topic
    Replies: 12
    Last Post: - 19th April 2007, 20:42
  5. Memory Space of the PIC16F84...
    By Tear in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st July 2005, 19:55

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