Help writing pic program with i/p o/p hold delay


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    35

    Default Help writing pic program with i/p o/p hold delay

    Hi all

    I have already posted a help ple on this subject,
    Hopefully I may get a bit more help ...

    I will try to explain what I am trying to do.

    I am using a 12F675, running its internal clock.

    What I am trying to get my head around some timing loops,
    I am trying to do following...

    I need an output to trigger as soon as the pic gets an input, (easy)
    But it needs to hold latched for about 20 seconds from the time the input is released.

    If an input is applyed to the pic within the 20 seconds the timer needs to reset back to 20 seconds until the input is released. (then carry on as before)

    I then need to be able to cancel the 20 second delayed latch by applying a second input
    to the pic. (clearing the delay and lifting the latched output)

    (A BIT MORE INFO)

    The input pulses are actualy toggled inputs,
    The input can be anything from 1 second to several mins.

    The pic circuit is actualy going to be used in a low power radio link,
    and its to control the transmit delay to stop it from chattering.
    ...................................

    I have grasped the basics,
    but when it comes to timing loops I am beat.

    I have only been into pic programming for just over a year,
    and are learning fast.

    Half the problem is knowing where to start,

    If you possibly could draft out a bit of program code,
    I would be greatful.


    Cheers
    Dave....

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    There you go... I was feeling benevolent...

    You could do this with a 10F series chip... 90 words are not exactly taxing a 12F... (actually, thinking about it, you could do this with a NE555 configured in monostable mode)...

    Untested - but it compiles and it's a start to check the logic...

    Code:
    	'
    	'	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.0		' Input normally LOW, goes HIGH to Trigger
    	InputReset var GPIO.1		' Input normally LOW, goes HIGH to RESET
    	OutputLine var GPIO.2		' Normally LOW, goes HIGH when triggered
    
    	'
    	'	Define Variables
    	'	----------------
    	DelayTick var Byte		' 100mS Tick Counter
    
    	'
    	'	Initialise PIC
    	'	--------------
    Reset:
    	TRISIO=%00000011		' Preset I/O
    	CMCON=%00000111 		' Disable Comparators
    	ANSEL=%00000000 		' Disable ADC
    	DelayTick=0			' Reset Counter
    	Low OutputLine			' Everything RESET
    
    	'
    	'	Main Program Loop
    	'	-----------------
    Loop:
    		'
    		'	Test for RESET
    		'	--------------
    	While InputReset=1		' Just wait here if RESET
    		DelayTick=0		' Reset Counter
    		Low OutputLine		' Reset Output
    		Wend
    		'
    		'	Test for Trigger
    		'	----------------
    	If InputTrigger=1 then		' Test for Trigger
    		High OutputLine		' Enable Output
    		DelayTick=1		' Arm Counter
    		Goto Loop
    		endif
    		'
    		'	Timeout Counter
    		'	---------------
    	If DelayTick>0 then
    		DelayTick=DelayTick+1	' Count Time
    		Pause 100		' Waste 100mS
    		If DelayTick>201 then goto Reset
    					' Reset at 20 Seconds
    		endif
    	Goto Loop
    
    	'
    	End

  3. #3
    Join Date
    Oct 2007
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Many thanks..

    Hi Melanie

    Many thanks for the code,
    Its just the job and it gives me a chance to learn some more code functions.

    All the best
    Dave..

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 09:54
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. PIC read program
    By TEOWK in forum General
    Replies: 3
    Last Post: - 10th June 2005, 13:48
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14
  5. size of program vs mem on pic
    By PICMAN in forum General
    Replies: 1
    Last Post: - 1st March 2005, 17:23

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