Searching \ for '[PIC]:Timer2 woes.' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=time
Search entire site for: 'Timer2 woes.'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Timer2 woes.'
2002\08\04@021426 by cdb

flavicon
face
I am trying to use timer2 on a 16F877 to create an interrupt roughly
every 50mS.

To this end I have enabled the software interrupt in CCP2CON to
software trigger (0x0A), loaded CCPR2L with 'd' 30. T2CON I have
postscale *16, PIE2 is enabled as is PIE in INTCON (I'm using TMR1
elsewhere).

The value for CCPR2L comes from CLOCK 10MHz /4=
1/(2.5MHz/256/16/30)=49.15mS

My problem is that at 51mS the test for CCPI2 in PIR2 is set - no
problem, however it will not clear until approx 58mS have passed and
then does not set itself again.

I am writing this program in 'C' but have changed the test from the
torturous movlw 254 andwf H'0D' produced by the compiler to inline
assembler BCF PIR2, CCP2IF but it makes no difference.

I have tried prescaling instead of postscaling but my understanding
is that the S/W interrupt is generated after the postscalar for
timer2.

I have read the 16F8xx and 877 and AN594b pdf's but they all seem to
leave me hanging, as they only describe in detail the PWM attributes
of timer2.

I have seen this technique used by Peter Anderson using the CCS
compiler, so I assume it should work. Note my compiler is not CCS.

My Timer0 and Timer1 routines work fine. Am I trying to use timer2 in
a way it's not designed to be used?

Thanks for any help

Colin
--
cdb, spam_OUTcdbTakeThisOuTspambarnard.name on 31/03/2002

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\08\04@051642 by Peter Anderson

picon face
Note that Timer2 is used in conjuction with the CCP
modules only for PWM.  Triggering a S/W interrupt on
match with the value in the CCPRxH & L requires the
use of Timer1.  (and Timer 3 in the case of the
PIC18F).

However, you could use the Timer2 interrupt.  That is,
figure out the prescale and postscale values and a PR2
value that gives roughly 50 ms.

For example, if the prescale is 1:256 and PR2 is 195
and the postscale is 1:1, this is 49.92 ms for a 4.0
MHz clock.  If you are using a 20 MHz clock, the
prescale might be 1:256, PR2 = 244 and the postscale
for 1:4.  (I am tired and may have made an error
here).

***********

There is a good deal of confusion caused by the use of
the names CCP1 and CCP2 and Timer1 and Timer2 which
might falsly lead one to believe that Timer1 is
associated with CCP1 and Timer2 with CCP2.  This is
not true.  However, the PR2 register is inherently
linked with Timer2.

**************

If you subcribe to my C routines distributions, see
routine TIMER2_1.C.

Hope this helps.

Peter H Anderson, http://www/phanderson.com,
pha(at)phanderson.com



--- cdb <bodgy1spamKILLspamOPTUSNET.COM.AU> wrote:
{Quote hidden}

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2002\08\04@064717 by cdb

flavicon
face
Ah, thank you Peter,

I was using your OUT_CMP2.C routine from the 16F87X tutorial as a
guide for timer2.

All is now clear.

Colin
--
cdb, EraseMEbodgy1spam_OUTspamTakeThisOuToptusnet.com.au on 04/08/2002

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2002\08\04@075452 by Peter Anderson

picon face
I made an error in that a prescale of 256 is not
available.  But, you have the general idea;




--- cdb <@spam@bodgy1KILLspamspamOPTUSNET.COM.AU> wrote:
{Quote hidden}

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu


2002\08\04@084525 by Olin Lathrop

face picon face
>>
I am trying to use timer2 on a 16F877 to create an interrupt roughly
every 50mS.

To this end I have enabled the software interrupt in CCP2CON to
software trigger (0x0A), loaded CCPR2L with 'd' 30. T2CON I have
postscale *16, PIE2 is enabled as is PIE in INTCON (I'm using TMR1
elsewhere).
<<

That's not how timer 2 is used to create a periodic interrupt.  RTFM,
section 7.0 "Timer 2 module" on pages 55 and 56 of "PIC 16F87x Data Sheet"
(DS3029C).

In short, you set up T2CON and PR2, which periodically sets the TMR2IF bit.
As an example, see the HAL_INTR.ASPIC module at
http://www.embedinc.com/pic/hal.htm.  I'll be glad to help with specific
questions once you've done your homework.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...