Push button accumulating timer circuit

Thread Starter

doubledutch1

Joined Sep 19, 2009
4
I am trying to figure out a circuit that will activate a relay for two hours each time the button is pressed up to at least four times (8 hours).

So if it is pressed once it will activate the relay for two hours and if it was pressed twice 4 hours, etc.. Up to 8 hours minimum.
I’ve been successful using a MC68RS08KA2 MCU to do the delay for 2 hours but I can’t figure out a loop to accumulate additional time. I’ve also used a 555 to get the two hour delay but not a way to get the additional time.

Does anyone have a suggestion of a simple circuit that will do the same thing with or without a 555 or MCU? Is there another chip out there that would make this simpler?

Is there a circuit that will allow a 555 or another chip to repeat based on a button input?

Any creative thinking would be appreciated.

Thanks in advance.
 

SgtWookie

Joined Jul 17, 2007
22,201
555 timers don't work so well for long time delays.

Why don't you post your source code for the MCU?

Please use the [ code] and [ /code] blocks so that it will format correctly.
 

nanovate

Joined May 7, 2007
665
Make a little state machine:

pseudo-code
Rich (BB code):
while(TRUE)
{
	if(button_pressed == TRUE)
	{
		debounce();
		wait_til_button_released();
		state++;
	}
	
	if(timer_expired && state !=0)
	{
		state = 0;
		do_stuff();
	}
	
	switch(state)
	{
		case 0
			reset_timer();
		case 1
			start timer();
		case 2
			add time():
		.
		.
		.
		default
			state = MAX_NUMBER_DELAYS;
		
	}	
}
This is just a rough outline.
 

Wendy

Joined Mar 24, 2008
21,839
Wookie's right, though with extra circuitry you could do it. I figure (off the cuff) around 4 chips to make the circuit.

Also, every time you press the button do you want the timer to reset (start timing from that point on) or from the 1st button press?
 

Thread Starter

doubledutch1

Joined Sep 19, 2009
4
Here's the code.
The delays right now are set for a one minute delay instead of the two hour delay. I did this for testing purposes.
I hope it formats properly.

Thanks, for your help.


; This program counts the number of times a button is pushed and activates a relay for 2 hours
; for every push.
;
;
; Pin 1 = PTA2 (RESET)
; Pin 2 = PTA3 (BKGD)
; Pin 3 = VDD + 5 volts
; Pin 4 = VSS Ground
; Pin 5 = PTA5 (Relay)
; Pin 6 = PTA4 (Relay Active LED)
; Pin 7 = PTA1 (Push Button Counter)
; Pin 8 = PTA0 Pin (Not Used)
;
;
;
;
;*******************************************************************************************
; export symbols
XDEF _Startup, main
; Export both '_Startup' and 'main' as symbols. Either can
; be referenced in the linker .prm file or from C/C++ later on
; Include derivative-specific definitions

INCLUDE 'derivative.inc'

; Variable/Data Section
CLKST EQU 2

ORG RAMStart
counter: DS.B 1
counter2: DS.B 1
counter3: DS.B 1

; Const Section

ConstSection: SECTION
;
; Code Section

ORG ROMStart

;*******************************************************************************************
; Peripheral Initialization
;*******************************************************************************************
init:
;CONFIGURES SYSTEM CONTROL

mov #HIGH_6_13(SOPT), PAGESEL
mov #$03, MAP_ADDR_6(SOPT) ; Disables COP, enables BKGD (PTA3) and RESET (PTA2) pins

;CONFIGURES CLOCK (FEI Operation Mode)

mov #HIGH_6_13(NV_ICSTRM),PAGESEL
lda MAP_ADDR_6(NV_ICSTRM)
sta ICSTRM ; Sets trimming value
clr ICSC1 ; Selects FLL as clock source and disables it in stop mode
clr ICSC2 ; ICSOUT = DCO output frequency
wait_clock:
brset CLKST,ICSSC,wait_clock ; Waits until FLL is engaged

;CONFIGURES TIMER
mov #$70, MTIMSC ; Enables interrupt, stops and resets timer counter
mov #$FF, MTIMMOD ; MTIM modulo = 256 counts before interrupt
mov #$08, MTIMCLK ; Selects fBUS as reference clock (8 MHz)

;CONFIGURES I/O CONTROL PORT
mov #$31, PTADD ; Configures PTA0, PTA4 and PTA5 as output,PTA1 as an Input
mov #HIGH_6_13(PTAPE), PAGESEL
mov #$04, MAP_ADDR_6(PTAPE) ; Enables Pull UP on PTA2 (RESET)
;CONFIGURES KEYBOARD INTERRUPTS (KBI)
mov #$00, KBIES ; Selects Falling Edge/Low on Pin
mov #$02, KBIPE ; PTA1 as KBI input
mov #$06, KBISC ; Clears any false interrupts


clr PTAD ; Clears PTA port
rts

;*******************************************************************************************
; Entry Point
;*******************************************************************************************
_Startup:
main:
bsr init
clr counter
clr counter2
clr counter3
clr coins
main_loop:
loopRelay:

mov #HIGH_6_13(SIP1),PAGESEL
brset 4,MAP_ADDR_6(SIP1),RelayOn ;If button goto Relay on

bra loopRelay ;No button continue to wait

RelayOn:
bset 2, KBISC ;Clear KBI Interrupt
bset 5, PTAD ;Turn on Relay LED
bset 4,PTAD ;Turn on Relay

StartDelay:
mov #$60,MTIMSC
bclr 4,MTIMSC ; Start MTIM counter

LoopDelay:
wait
lda counter
cbeqa #255,Delay2
inc counter
bra StartDelay

Delay2:
clr counter
lda counter2
cbeqa #5,Delay3
inc counter2
bra StartDelay

Delay3:
clr counter
clr counter2
lda counter3
cbeqa #5, RelayOff
inc counter3
bra StartDelay

RelayOff:
clr counter
clr counter2
clr counter3
bclr 5,PTAD
bclr 4,PTAD
bra loopRelay
 

Thread Starter

doubledutch1

Joined Sep 19, 2009
4
Thanks everyone,

I couldn't figure out how to program a state machine with my limited code experience. I didn't get any feedback on my code so I guess no-one else figured it out either. Thanks anyways.

I did find a CSS555C timer that says it works for long delays. Anyone have experience with those that can provide feedback?

Thanks again,

Rod
 

Wendy

Joined Mar 24, 2008
21,839
The core problem with 555's and long time delays isn't the timer, it's the capacitor. Large electrolytic caps tend to leak. Couple that with a large resistor, and you have a RC circuit that doesn't follow theory very closely.

You never answered my question about the reset.

My inclination is the 4060, because it has 12 ripple counter flip flops after a basic RC oscillator.

The other idea is a simple digital counter. I like the thought about the microcontroller. Much simpler overall.
 

Thread Starter

doubledutch1

Joined Sep 19, 2009
4
Thanks Bill,

I didn't answer your question because I thought it was addressed in the original post. My mistake.

I'd like the timer to start with two hours and and add an additional 2 hours to the original start for each push of the button. So if I pushed the button at 8 am it would run until 10 am but if I pushed it again at any time during the first count down (between 8 am and 10 am) it would run until noon.

The CSS555C timer has an internal trimmed capacitor that is supposed to be very stable and predictable for accurate timing. Anyone have any experience with it to determine if it would work reliably for a two hour delay?

I have the 2 hour delay working with a microcontroller, I just can't figure out the code to get it to add an additional 2 hours after the original start. You can see the timed loops I used in one of my previous post.

Rod
 
Top