Help with Pic Delay Pulse code please


Closed Thread
Results 1 to 37 of 37

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    35

    Smile Help with Pic Delay Pulse code please

    Hi all

    I big thanks to all that have help me in the past,
    But I have a small problem I hope someone can put me straight with.

    Below is my code I have had running for some time with no problems,
    What it does is to allow an input to output with a delay on the output when the input is removed,
    What I would like to add to this is if the input trigger is longer than say 1 second the output is triggered as before but doesn't have any delay,
    If the input has smaller pulses of say less than 1 second the delay is as before.

    I hope this makes sense,
    Any ideas...?

    Many thanks to all ....

    ************************************************** *************

    '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

    '
    ' Initialise PIC
    ' --------------
    Reset:
    TRISIO=%00100100 ' Preset I/O
    CMCON=%00000111 ' Disable Comparators
    ANSEL=%00000000 ' Disable ADC
    DelayTick=0 ' Reset Counter
    high OutputLine ' Everything RESET


    ' pause 4000

    ' Main Program Loop
    ' -----------------
    Loop:
    '
    ' Test for RESET
    ' --------------
    While InputReset=0 ' Just wait here if RESET
    DelayTick=0 ' Reset Counter
    high OutputLine ' Reset Output
    Wend
    '
    ' Test for Trigger
    ' ----------------
    If InputTrigger=0 then ' Test for Trigger
    low OutputLine ' Enable Output
    DelayTick=1 ' Arm Counter
    'Goto Loop
    endif
    '
    ' Timeout Counter
    ' ---------------
    If DelayTick>0 then
    DelayTick=DelayTick+1 ' Count Time
    Pause 60 ' Waste 100mS
    If DelayTick>50 then goto Reset
    ' 50 = 5 sec
    ' 100 = 10 sec
    ' origanly set at 201 Reset at 20 Seconds
    endif
    Goto Loop

    '
    End
    Reply With Quote

  2. #2


    Did you find this post helpful? Yes | No

    Default

    It depnds on what sort of accuracy you need. If it is just a rough gating effect you need then a loop counter will get you there.

    PIN_dur var byte

    PIN_dur = 0
    While Input_Trigger = 0
    pause 10 ;10mS pause
    if PIN_dur != 255 ;Check time delay isn't 255
    PIN_dur = PIN_dur + 1 ;Or it rolls over back to zero
    Endif
    Wend


    Stored in PIN_dur, now, is the number of 10mS periods the button was held down for.

    100 x PIN_dur = approx 1 second

    If PIN_dur >100 then
    goto/gosub long press code
    else
    goto/gosub shorter press code
    endif


    You could also use the PULSIN command which measures pulse lengths. Reading the result into a 16-bit variable, and at 4MHz, you can accurately measure to about 0.65 seconds, so yoiu would need to call it twice to get a 1 second push (and gate off the first reading)

    Chris

  3. #3
    Join Date
    Oct 2007
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    Hi Chris

    Thanks for your reply,

    I get the drift of your coding, (I am still a bit new to this)
    Where abouts would you insert it.
    ( I am using a 4mhz clock)

    The i/p trigger would need to be less than one second for no delay and longer than 1 second to trigger the delay,

    Cheers
    Dave...

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by g7jiq View Post
    Hi Chris

    Thanks for your reply,

    I get the drift of your coding, (I am still a bit new to this)
    Where abouts would you insert it.
    ( I am using a 4mhz clock)

    The i/p trigger would need to be less than one second for no delay and longer than 1 second to trigger the delay,

    Cheers
    Dave...
    Sorry Dave, I think I am reading your desired output in this message to be the inverse of your original message which asked for a delay on the short pulse HIHI.

    Can you please explain a little bit more about when you would like the output to be triggered ? Should it trigger immediately when the Input_Trigger pin is down ?

    Or do you mean that you don't want there to be any activity at all on the output until after the Input_Trigger has been released ?

    Chris
    GM4UCD

  5. #5
    Join Date
    Oct 2007
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    Hi Chris

    Sorry I didn't make it clear enough, I do seem to go off running..

    Ok lets start at the beginning.

    I had a go at sorting out some coding, and was failing, I got sorted out on here and was sent the corrected code, (listed in the first post) This works fine.

    What it does is as follows -: (its part of a small local repeater to stop it chattering on a weak/mobile i/p)

    When the i/p is triggered (rx) it instantly triggers the o/p (tx), when the i/p drops it gives a 2 second hang before dropping the o/p.
    (if the i/p o/p chatters on a mobile/weak signal the problem occurs the when the ctcss delays add up and I hear nothing, the delay stops this happening, I just hear the audio chopping)

    What I would like to do is add some coding to allow it to add the delay if the i/p chatters (mobile rx) the i/p re-triggers in say less than 1 second,
    If the i/p signal is solid for longer than say 1 second it will remove the delay and drop the o/p as soon as the i/p is removed.

    I hope this explains it.

    Any ideas,,

    Cheers
    Dave...

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