EmbDev.net

Forum: µC & Digital Electronics Problems in using Timers & Interrupts of PIC18F452,.


von Bahman M. (Company: Electronic Engineering student) (bobyx)


Rate this post
useful
not useful
Hello everybody.I want to write a program using PIC18F452&XTAL=20MHZ in 
C or mikroC to do the followings;

1.Simultaneously turn  a timer on[timer0 or...] to count for 1 sec. and
also count the number of High[transition from H to L] state of the
input signal.

2.Turn  a timer on[timer0 or...] for 1 sec. and as soon as a input 
signal injected or entered to a PIC pin the timer[timer0 
or...]immediately turned off and calculate the time of passed by that 
timer.

Would you please help and give me some example codes to write those 
programs?

            Thanks,

von Bahman M. (Company: Electronic Engineering student) (bobyx)


Rate this post
useful
not useful
Still not write any.

von Wil1 (Guest)


Rate this post
useful
not useful
Hallo,
I think the guys here dont like to write in english language. I'm not 
familiar with the PIC you are using, but i try to give you some basic 
hints:
1st: download an read the datasheet 16F452!!!
Do not poll a pin for a transition! It wastes time and blocks the PIC.
Use interrupts because some pins of the PIC 16F452 are able to release 
an interrupt by HL or LH transitions.

Possible solution with interrupt released through a transition:

Within ISR (interrupt-service-routine) starts a counter from 0 or with a 
preset to count up or start a counter from a preset  down to zero.
The preset makes you able to calibrate an exact time, eg from start to 
overflow, or  down to zero
example:
fosz:           20Mhz
workcycles: 20MHz:4=5MHz
1s -> count 5.000.000 workcycles
connect TMR1 by Software with workcycles
connect the prescaler 1:8 by Software between workcycles and TMR1

Calculate: 5.000.0000Hz : 8 = 625000Hz
TMR1 counts max. up to 65536
1/10 sec =625000Hz:10 = 62500Hz
Preset TMR1 to 62500 then count down
Checkt TMR1 = 0  thats 1/10sec
Count this event 10 times -> 1sec  and that was it!

may be it helps you a little!

regards Wil1

von Programist (Guest)


Rate this post
useful
not useful

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.