PDA

View Full Version : Help writing pic program with i/p o/p hold delay



g7jiq
- 25th May 2008, 21:23
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....

Melanie
- 26th May 2008, 00:40
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...



'
' 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

g7jiq
- 27th May 2008, 21:58
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..