EmbDev.net

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


Author: Bahman Mohammadhoseini (Company: Electronic Engineering student) (bobyx)
Posted on:

Rate this post
0 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,

Author: Bahman Mohammadhoseini (Company: Electronic Engineering student) (bobyx)
Posted on:

Rate this post
0 useful
not useful
Still not write any.

Author: Wil1 (Guest)
Posted on:

Rate this post
0 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

Author: Programist (Guest)
Posted on:

Rate this post
0 useful
not useful

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.