Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

555 Timer with input/triggered from Microcontroller

Status
Not open for further replies.

nmsr1196

New Member
I'm new to the forum. But, I'm working on a project, in which I have already installed without my microcontroller. I would like to add my microcontroller but due to some limitations of the microcontroller I would like to create a triggered timer.
I need help with creating a adjustable (from 5 seconds to 20 seconds) timer (probably with a 555) that when the input goes high, it will trigger the timer to allow its load to stay on for at least 10 seconds.
Thanks (in advance)
 
I tried to incorporate the delay in the program. But the delay is too long (10seconds). Here's the scenerio. I have 6 motion detectors. If one sensor is triggered the program pauses to perform that 10 second task. When I purposely trigger a second motion within that timeframe its not always consistent. Sometimes its too busy with the first task to perform the second. So, I figured if I can have the sensor is a loop with a lot less delay to detect a high, and have a timer circuit detect that high and perform the load to stay on for 10 seconds. That way, the microcontroller is not using that processing time and can scan and loop the other sensors for motion.
 
You can trigger a 555 from a micro, you could directly connect the output of the micro to pin 2 trigger input of the 555 (if they are both on the same 5v supply) a low pulse starts the timer, you'd need to make sure the low pulse was not longer than the time duration you want as 555's are retriggerable.

If you use interrupts you can easily do what you described without the 555 with consistant results, scan the inputs at whatever rate you want using interupts, up to many khz is possible, then start a time process upon an activated sensor using a register decremented by the interupt routine, opon zero timeout.

An adjustable time delay can be done by either up and down buttons or possibly a pot wired to a a/d input.
 
Last edited:
Once a motion has been activated the sensor sensor sends out signal for about 2 seconds. Could the time (trigger) take about a one or two second pulse/input then have the timer starts his clock?
I'm not quite sure on how to use the interrupts. (I'm not a programmer by trade)



Code:
' {$STAMP BS2p}
' {$PBASIC 2.5}
' {$PORT COM8}

'GOSUB StartUp

' -----[ I/O Definitions ]-------------------------------------------------

StepSen1        PIN     15                       ' Lower level steps sensor
FoyerSen        PIN     14                       ' Foyer sensor
StepSen2        PIN     13                       ' Upper level steps sensor
BathSen         PIN     12                       ' Outside half-bath sensor
HallSen         PIN     11                       ' Hallway sensor

StepLED1        PIN     9                        ' Lower level steps LED
FoyerLED        PIN     8                        ' Foyer LED00
Stairs2LED      PIN     7                        ' Upper level stairs LED
HallwayLED      PIN     6                        ' Hallway LED
Hallway2LED     PIN     5                        ' Hallway/Loft LED

Main:
PAUSE 3000


DO
DEBUG HOME, BIN1 StepSen1
IF (StepSen1 = 1 ) THEN
HIGH StepLED1
PAUSE 5000
LOW StepLED1
ELSEIF (FoyerSen = 1 ) THEN

HIGH FoyerLED
PAUSE 5000
LOW FoyerLED
ELSEIF (StepSen2 = 1 ) THEN

HIGH Stairs2LED
PAUSE 500
LOW Stairs2LED

ELSEIF (HallSen = 1) OR (BathSen = 1 ) THEN
HIGH HallwayLED
HIGH Hallway2LED
PAUSE 500
LOW HallwayLED
LOW Hallway2LED
 ENDIF

  PAUSE 10
 LOOP
 
Code additions:
I know this code does not work due to the pause time. In my testing I was using 5 seconds (pause 5000), I actually need 10 seconds.
also the sensors are input pins (pins 11 - 15).
 
Your code needs to use flags and timer ticks. Have an interrupt triggering every 5 milliseconds. Then use that to cycle a gpr timer variable thru 0 to 200. Which is effectively 1 second. When u sense a condition that u need to respond to you set a flag (eg. if u want a 5 sec flag place a 5 in the matching flag variable and grab the current timer variable into a temp variable). With those data u can accurately (+/- 5 ms)countdown each flag to zero and obtain your timing without pausing your programming code.

BTW you will need a module setting the state of the flags, a module just handling the state of the flags and the desired outputs and a module to count down the flags. They are independent.
 
Last edited:
Can you give me an example or link please? I understand the process flow you explained. I'm not sure how to place it into code.
 
How many inputs:

How many outputs:

How many outputs do you want to be able to adjust from 5 seconds to 20 seconds:
 
The simplest way would be to repeat the pause.
Code:
    HIGH Stairs2LED
    PAUSE 500
    PAUSE 500
    PAUSE 500
    PAUSE 500
    LOW Stairs2LED
Or, better still,

Code:
    HIGH Stairs2LED
    for x = 1 to 20
        PAUSE 500
    next x
    LOW Stairs2LED
Or even more betterer ;) , as already suggested, setup a timer to give you a tick and count ticks.

Mike.
 
Thanks for the input, much appreciated.
But, if I set it up this way, within the time its processing the timer or pause(s) would it be able to sense another sensor at the same time or would it wait until the time interval and finished?
 
If you want to do other things during the delay then you need the tick approach.

The easiest timer to use is timer 2. Assuming a 4 MHz clock, set T2CON = 0x4D and PR2 = 249. With these setting the timer will timeout every 10mS and PIR1.TMR2IF will get set. So you can do something like,
Code:
    while(1)
	while PIR1.TMR2IF=0
	wend
        PIR1.TMR2IF=0
        Count100=Count100+1
        if Count100=100 then
            Count100=0
            Seconds=Seconds+1
        endif

 //any other code goes here and will get executed 
 //100 times per second

    wend
The above assumes that a stamp allows you to access the hardware. I've never used them so don't know.

Mike.
 
If it's clocked at 20MHz then the above code will operate every 2mS and so you would need to make the counter count to 500 before incrementing the seconds variable. Alternatively set Timer 2 prescaler to 16 to make it 8mS and count to 125.

Mike.
 
You are expecting a bit much with 8 + 8 + 8 requirements.
The simplest way to orgainse this is .asm
It's the only way you are going to fix a problem if one arises.
Already, everyone is telling you complex ways to tackle the problem.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top