Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 4th May 2007, 11:43 PM   (permalink)
Default :: Timer 2 Woes ::

Hey all

ive become quite proficient with PICs, the one im using currently is the PIC16F877A...very common i know and im using TIMER1 really well... Its been quite user friendly

However i need another timer, and if i can help it, id like to use another timer and not use multiples of timer 1.

I need timer 2 OR timer 0 to count up to 0.1ms (20MHz clock) so loading the PRESCALER to 1:4 will allow this.

But Timer0 doesnt indictae how to TURN ON or TURN OFF the timer, i need to be able to control it like TIMER1. Timer 2 has this functionality but gets me a bif baffled. The use of the PR2 register, if i load this with 125, then with the values stated, i should get an interrupt at 0.1ms, but i dont

I cant see where ive gone wrong? heres the timer code

Code:
	

         BSF		T1CON, T1CKPS1				;THESE 2 LINES
	BSF		T1CON, T1CKPS0			      ;SET PRESCALER TO 8
	BCF		T1CON, T1OSCEN
	BCF 	         T1CON, TMR1CS
	BCF		T1CON, TMR1ON				;STOPS TIMER

	CLRF	T2CON
	BSF		T2CON, T2CKPS0				;POSTSCALER TO 4
	
	MOVLW	h'FE'			;reset timer1 values 0.5MS
	MOVWF	TMR1H
	MOVLW	h'C7'			;reset timer1 values 0.5MS
	MOVWF	TMR1L
	


	
	BSF		INTCON, PEIE
	BCF 	        PIR1, TMR1IF
	BCF 	         PIR1, TMR2IF

	BSF		STATUS, 5			;Change to BANK 1
	BSF		PIE1, TMR1IE	
	BSF		PIE1, RCIE
	BSF		OPTION_REG,	INTEDG	
	BCF		STATUS, 5			;Change to BANK 0

	BSF		INTCON,	INTE	;Enable EXTERNAL INTERRUPT
	BSF 	INTCON, GIE		;GLOBAL INTERRUPT ENABLE

	BSF		T2CON, TMR2ON		;STARTS TIMER
	BSF		PORTC, 1
suby786 is offline   Reply With Quote
Old 5th May 2007, 08:02 AM   (permalink)
Default

Timer2 is FAR easier, and much more useful than timer0 (which is really a bit naff!), but timer2 counts up until the value equals PR2, then starts counting from the beginning again. Check my seven segment LED tutorial at http://www.winpicprog.co.uk/pic_tutorial10.htm which uses a timer2 interrupt to multiplex the displays.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 5th May 2007, 11:13 AM   (permalink)
Default

I've done up quick examples of all three timers, and converting it back to assembly from PIC Basic would not be too hard;

http://users.tpg.com.au/gramo/Site/timers.htm

The best timer calculator I have found is here;

http://www.best-microcontroller-proj...c-timer-0.html

TMR2 is definitely the best low maintenance timer, as there is no additional code required once it is running.

Just on TMR0, you can disable TMR0 interrupts via INTCON.5 and its just as handy for mid length type delays.
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
89C52 Timer ahmedragia21 Micro Controllers 9 10th February 2007 01:55 PM
Watchdog timer in PIC elexhobby Micro Controllers 7 6th November 2005 02:51 AM
newbie needs help with presetable count down timer 7 segment zenton Electronic Projects Design/Ideas/Reviews 3 6th September 2004 04:16 AM
countdown timer code ah_Hui Micro Controllers 0 26th April 2004 05:30 PM
Double Timer, With LED Rakarin Electronic Projects Design/Ideas/Reviews 5 27th May 2003 07:14 PM



All times are GMT. The time now is 12:04 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.