PDA

View Full Version : Timer and 12F509



Pedro Santos
- 3rd November 2008, 13:44
Hello

I want to use the PIC 12F509 to monitoring one impuls in a Timewindow from 0 to 16 seconds, that means on power up a Timer starts and if i not receive one impuls until 16 seconds the programm stop, if the impuls come the Timer cleared to count again.

The 12F509 have no interrupt pin, than i must poll the pin, correct?
Have anyone make this with a 12F509? I have not programmimng anything with Timer, have anyone a sample code for the 12F509 with Timer

Thanks
Best Regards
Pedro

Jumper
- 3rd November 2008, 14:02
Hi,

How accurate do you need this 16 seconds to be and how long is is the signal you are looking for?

A simple way would be polling the pin in a tight loop with a short delay inside.

Lets say you have a delay of 10 ms in the loop and do this loop 1600 times you should end up with a 16 second time window.

If you need more accuracy yuu can adjust the delay by using delay_us if timing is critical..

You didnt mention the clock frequency but unless it is really slow it will be hard to get 16 seconds time by just using a timer... in that case you need to reset it several time or count how many times it overflows... or something

/me

Pedro Santos
- 3rd November 2008, 14:15
Hello Jumper

I have two Jumpers that i read at power up to choose four possible timings
16 seconds, 18, 19 and 20 seconds
I want use on the PIC 12F509 the internal 4Mhz oscilator

Best Regards
Pedro

Jumper
- 3rd November 2008, 14:25
I might be slow.. but I still dont understand fully.


You have 2 jumpers you can read at startup to set the time window.. so you get 4 different times (16,18,19,29 sec).. I am with you this far.

Then you say you look for something to happen during this time window... if it happens.. then you start a new time window to look again... if it doesnt you stop the program.

so...

power up
check input pins
load a word variable with the correct time (1600 for 16 s and 2000 for 20 sec)

start_again:

n=0
for n =0 to word variable
check for your signal
if you find your signal goto start_again
Delay_ms(9)
Delay_us(1000) ' here you can adjust the loop time
next n

STOP


This could work unless you are looking for 16.000000000000000 seconds or similar. By adjusting the delay_us() time you can calibrate the loop time.

Since you doesnt seem to have anything else to do during this time why do you want to use the timer?
/me

Pedro Santos
- 3rd November 2008, 14:51
Hi Jumper
You are right, i don't need to use the Timer

Thanks

Regards
Pedro