Pic controlers and counting ?
Hello
New to PIC's but not to programming.
Currently I am counting input pluses with a PIC 16f886 at 20khz.
I am doing some thing like
IF pin high THEN
X=X+1
(not exact code but I am sure you get the gerneral idea)
The problem I am haveing is that the code is long and has quite a few RS232 outs
and by the time the logic loops back around to the IF statement I have missed counts.
Is there some special counting command I should be thinking of useing or can a make a pin a interupt that has precendence over what is going on ?
My only concern if there is a interupt fuction that I can not cut a RS232 string out in half.
Any thoughs ?
Mark
Maybe not really like that
Hi,
If we look the datasheet for the PIC18F886 you will notice that we have 3 timers:
Timer0: 8-bit Timer/Counter with 8-bit
Programmable Prescaler
• Enhanced Timer1:
- 16-bit timer/counter with prescaler
- External Gate Input mode
- Dedicated low-power 32 kHz oscillator
• Timer2: 8-bit Timer/Counter with 8-bit Period
Register, Prescaler and Postscaler
Timer0 can be clocked with the T0CKI (RA4)
Timer1 can be clocked with the T1CKI (RC0)
Timer2 can NOT be clocked with an external pin.
There is an other possibility and that is that you use interrupts for counting but that might upset the serial data unless you also do that part interrupt based.
But since you say that you are new to pics I would suggest that you use the timers as counters. Associated with the timers are the timer registers and that is where the current number of counts are stored.
8-bit timer/counter register (TMR0) for Timer0
16-bit timer/counter register pair (TMR1H:TMR1L) for Timer1
I suggest you start with Timer0 since that is the easiest one to set up.
5.0 TIMER0 MODULE in the datasheet is something you must read and understand before you will be successful with this.