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
 
Tools
Old 2nd February 2009, 05:30 AM   #1
Arrow Software Trim Idea

My clocks time base is done with TMR0.

Can somebody explain me how to do a software trim for the TMR0.

Because my clocks timing is varying.

No need codes just tell me the idea

Thanks
Suraj143 is offline  
Old 2nd February 2009, 05:32 AM   #2
Default

What clocks, there is no trim for TMR0. What PIC are you using?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 2nd February 2009, 05:37 AM   #3
Default

Quote:
Originally Posted by blueroomelectronics View Post
What clocks, there is no trim for TMR0. What PIC are you using?
I'm using 16F88, I need TMR2 for another work.Thats why I used TMR0.

So I need the idea on how to do a software trim.
Suraj143 is offline  
Old 2nd February 2009, 05:50 AM   #4
Default

If you're presetting TMR0 it will be very difficult to keep it accurate, free running mode is best. Roman Black has an article on this.
Official Home Page of Roman Black
PS TMR1 has a wonderful connection to the CCP1 special interrupt (mode 14) which can form an excellent timebase for a clock.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 2nd February 2009, 05:54 AM   #5
Default

Quote:
Originally Posted by blueroomelectronics View Post
If you're presetting TMR0 it will be very difficult to keep it accurate, free running mode is best. Roman Black has an article on this.
Official Home Page of Roman Black
PS TMR1 has a wonderful connection to the CCP1 special interrupt (mode 14) which can form an excellent timebase for a clock.
Yes I'm resetting TMR0.I have every 10ms T0IF interrupts & I count 100 to generate 1 second.

On every T0IF interrupts I reload TMR0.
Suraj143 is offline  
Old 2nd February 2009, 06:21 AM   #6
Default

The problem with reloading TMR0 is it resets the prescaler and other such stuff. Allowing it to freerun is the better way to do it. It'll set TMR0IF on overflow and use Romans zero error clock algorithm for getting a 1 second timebase.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 2nd February 2009, 06:22 AM   #7
Default

Usually you just don't reload a timer with a calculated value. You add the current Timer value + your calculated value + amount of cycle it need to reload your timer.

HTH

TMR0=TMR0 + ReloadValue + SomeCallItFudgeFactor

Quote:
Originally Posted by From the datasheet
If the TMR0 register
is written, the increment is inhibited for the following
two instruction cycles. The user can work around this
by writing an adjusted value to the TMR0 register.
__________________
Steve

Last edited by mister_e; 2nd February 2009 at 06:23 AM.
mister_e is offline  
Old 2nd February 2009, 07:05 AM   #8
Default

If you set the prescaler to 32 then the timer will overflow every 8192 cycles - close to your current 10,000. Use Roman Blacks code to subtract 32 from the middle byte and add the 1,000,000 when the top bytes become zero. This will give you a very accurate clock.

Mike.
Pommie is offline  
Old 2nd February 2009, 07:19 AM   #9
Default

Quote:
Originally Posted by Pommie View Post
If you set the prescaler to 32 then the timer will overflow every 8192 cycles - close to your current 10,000. Use Roman Blacks code to subtract 32 from the middle byte and add the 1,000,000 when the top bytes become zero. This will give you a very accurate clock.

Mike.
Hi thats a good way I'll try to like that.

Thanks
Suraj143 is offline  
Old 2nd February 2009, 08:33 AM   #10
Default

I just realised that adding 32 will not work with Roman Blacks code. It needs to be modified to,
Code:
		movlw	.32		;subtract 32*256 from accumulator
		subwf	AccHi,F
		skpnc
		goto	DoneTimer
		decfsz	AccUp,F
		goto	DoneTimer

;only gets here if 1 second has passed

		movlw	low(.1000000)	;add 1 million to the accumulator
		addwf	AccLo,f
		movlw	high(.1000000)
		skpnc
		addlw	1
		addwf	AccHi,f
		skpnc
		incf	AccUp,F
		movlw	upper(.1000000)
		addwf	AccUp,F
DoneTimer	bcf	INTCON,TMR0IF
The three variables AccLo, AccHi and AccUp can be initialised to 1.

Mike.
Pommie is offline  
Old 2nd February 2009, 01:43 PM   #11
Default

What are you using TMR2 for? You might be able to use it for both your current purpose and for the RTC 'heartbeat'.

There's a brief description of a software trimmer function here (for timer 2).

Regards, Mike

Last edited by Mike, K8LH; 2nd February 2009 at 01:43 PM.
Mike, K8LH is offline  
Old 3rd February 2009, 02:55 AM   #12
Default

Hi Mike (Pommie) thanks for your new code thats the one I like to put.

Hi Mike, K8LH

I need a 2.5Khz separate frequency to drive a speaker.So I using PWM module.Thats why I cannot use TMR2.
Suraj143 is offline  
Old 3rd February 2009, 05:20 AM   #13
Default

Quote:
Originally Posted by Suraj143 View Post
I need a 2.5Khz separate frequency to drive a speaker.So I using PWM module.Thats why I cannot use TMR2.
If you set timer2s postscaler to 10 you will get an interrupt at 250Hz which you could use for the clock timebase. This will not effect your PWM output at all. To turn off the 2.5kHz signal set the pulse width to zero.

Mike.
Pommie is offline  
Old 3rd February 2009, 05:40 AM   #14
Default

Quote:
Originally Posted by Pommie View Post
If you set timer2s postscaler to 10 you will get an interrupt at 250Hz which you could use for the clock timebase. This will not effect your PWM output at all. To turn off the 2.5kHz signal set the pulse width to zero.

Mike.
Hi Mike thats a clever method.It didn't come to my mind.I can't think like you all think.Because I'm very new to this subject.

So that means I can do both works (time base + speaker output frequency) from a single TMR2.Wow thats very nice.

Thanks for the help I'm going to try that as well.
Suraj143 is offline  
Old 3rd February 2009, 05:48 AM   #15
Default

At the moment I'm studying roman blacks original code.I have got stuck with that.Sorry about that.

First it loads accumulator to 100000+256=100256uS.
Every 256uS it generates interrupt.& every 256uS interrupts he subtract 256 from accumulator.

When continue subtracting theres a point coming you cannot subtract anymore.That is 100096uS.So balance is 160uS remaining (100256uS-100096uS =160uS) .

I'm not sure what he is doing for this 160uS
Suraj143 is offline  
Reply

Tags
idea, software, trim

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Trim Pot joeyb General Electronics Chat 12 22nd January 2009 07:21 PM
Trim Pot symbol for express PCB layout Skywalker83 Electronic Projects Design/Ideas/Reviews 7 11th December 2008 10:06 PM
partial rotation trim pots, or such? Hank Fletcher Datasheet/Parts Requests 3 14th April 2008 05:23 AM
Boat trim indicator Techno Electronic Projects Design/Ideas/Reviews 13 4th August 2006 03:38 PM
replace trim cap with some kind of IC ? ModuLator Electronic Projects Design/Ideas/Reviews 4 11th February 2003 11:55 AM



All times are GMT. The time now is 09:35 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker