![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 | |
| |
| | #2 |
|
What clocks, there is no trim for TMR0. What PIC are you using?
| |
| |
| | #3 |
| | |
| |
| | #4 |
|
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. | |
| |
| | #5 | |
| Quote:
On every T0IF interrupts I reload TMR0. | ||
| |
| | #6 |
|
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.
| |
| |
| | #7 | |
|
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:
__________________ Steve Last edited by mister_e; 2nd February 2009 at 06:23 AM. | ||
| |
| | #8 |
|
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. | |
| |
| | #9 | |
| Quote:
Thanks | ||
| |
| | #10 |
|
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 Mike. | |
| |
| | #12 |
|
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. | |
| |
| | #13 | |
| Quote:
Mike. | ||
| |
| | #14 | |
| Quote:
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. | ||
| |
| | #15 |
|
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 | |
| |
|
| 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 |