|
|
View previous topic :: View next topic |
Author |
Message |
cwcon Guest
|
Reading timer1 question |
Posted: Wed Mar 05, 2003 3:13 pm |
|
|
Can anyone tell me if the timer1_counts=get_timer1() function handles the potential lower byte overflow issue in grabbing the two-byte value from the counter?
The alternative method with which I am familiar is to read the lower byte, then the upper byte, and check the lower byte again for roll-over such as:
pulses_low_a = CCPR1L; // read low byte
pulses_high = CCPR1H; // read high byte
pulses_low_b = CCPR1L; // read low byte again
The rest of the routine would check the second byte read and compare it to the first byte read to see if the lower byte had rolled over and adjust the results accordingly.
Thanks ... CW
___________________________
This message was ported from CCS's old forum
Original Post ID: 12395 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Reading timer1 question |
Posted: Wed Mar 05, 2003 3:32 pm |
|
|
<font face="Courier New" size=-1>:=Can anyone tell me if the timer1_counts=get_timer1() function handles the potential lower byte overflow issue in grabbing the two-byte value from the counter?
:=
:=The alternative method with which I am familiar is to read the lower byte, then the upper byte, and check the lower byte again for roll-over such as:
:=
:=pulses_low_a = CCPR1L; // read low byte
:=pulses_high = CCPR1H; // read high byte
:=pulses_low_b = CCPR1L; // read low byte again
:=
------------------------------------------------------
Here is what they do in PCM 3.146, for a 16F877:
<PRE>
0000 00272 .................... timer1_counts=get_timer1();
0014 080F 00273 MOVF 0F,W // Save Timer1 MSB in temp register
0015 00FA 00274 MOVWF 7A
0016 080E 00275 MOVF 0E,W // Save Timer1 LSB in another temp register
0017 00F7 00276 MOVWF 77
<BR>
0018 080F 00277 MOVF 0F,W // Read the Timer1 MSB again
0019 027A 00278 SUBWF 7A,W // Compare current MSB to previous value
001A 1D03 00279 BTFSS 03.2 // Skip next instruction if they're equal
001B 2814 00280 GOTO 014 // If not equal, jump back to top
<BR>
// Saved Timer1 --> timer1_counts
001C 0877 00281 MOVF 77,W
001D 00A1 00282 MOVWF 21
001E 087A 00283 MOVF 7A,W
001F 00A2 00284 MOVWF 22
</PRE>
This is similar to the method that's recommended in the
Timer1 reference manual, which is available here:
<a href="http://www.microchip.com/1000/suppdoc/refernce/midrange/index.htm" TARGET="_blank"> <a href="http://www.microchip.com/1000/suppdoc/refernce/midrange/index.htm" TARGET="_blank">http://www.microchip.com/1000/suppdoc/refernce/midrange/index.htm</a></a>
However, note that they don't shut off interrupts, which
the reference manual recommends.
-------------------------------------
<PRE>
Here is their method for writing to Timer1:
0000 00286 .................... set_timer1(0x1234);
0020 3012 00287 MOVLW 12
0021 008F 00288 MOVWF 0F
0022 3034 00289 MOVLW 34
0023 008E 00290 MOVWF 0E
</PRE>
This method is not the one that's recommended in the reference
manual. It could cause problems. See example 12.3 in the
reference manual. (at link above)</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12400 |
|
|
Hans Wedemeyer Guest
|
Re: Reading timer1 question |
Posted: Wed Mar 05, 2003 4:42 pm |
|
|
Which PIC are you using ? As you mention 16 bit reads for Timer1() I suspect you are using a PIC18.
PIC18 series has a much better solution to reading timers, it buffers the high byte and takes care of all the checking which you mentioned.
.................... x = Get_Timer1();
01A8: MOVF FCE,W
01AA: MOVLB 0
01AC: MOVFF FCF,03
01B0: MOVLB 4
01B2: MOVWF xC4
01B4: MOVLB 0
01B6: MOVFF 03,4C5
From PIC18FXX2 data sheet
10.4 16-Bit Mode Timer Reads and Writes
TMR0H is not the high byte of the timer/counter in
16-bit mode, but is actually a buffered version of the
high byte of Timer0 (refer to Figure 10-2). The high byte
of the Timer0 counter/timer is not directly readable nor
writable. TMR0H is updated with the contents of the
high byte of Timer0 during a read of TMR0L. This provides
the ability to read all 16-bits of Timer0 without
having to verify that the read of the high and low byte
were valid due to a rollover between successive reads
of the high and low byte.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12404 |
|
|
cwcon Guest
|
Re: Reading timer1 question |
Posted: Thu Mar 06, 2003 8:04 am |
|
|
:=Which PIC are you using ? As you mention 16 bit reads for Timer1() I suspect you are using a PIC18.
Nope, it's a PIC16C73. I will check out the 18C as you mentioned regarding the counter buffering. The root of my question however, was actually aimed more towards how the CCS function get_timer1() worked.
Thanks ... cw
___________________________
This message was ported from CCS's old forum
Original Post ID: 12423 |
|
|
Hans Wedemeyer Guest
|
Re: Reading timer1 question |
Posted: Fri Mar 07, 2003 8:44 am |
|
|
OK.... when you said 16 bit and Timer 1 I assume PIC18, I think all PIC16's are only 8 bit for Timer 1. If needed it is possible to set PIC16 Timer1 to 8 bit mode.
Look at the LST file it will show you exactly how CCS handles it.
BTW If you plan to use External clock for Timer1 then you may have a problem with count accuracy. Check Errata sheets.
PIC18 do not have a counting problem.
PIC18F242 and 252 are pin for pin drop in's for PIC16C73.
I'm trying to stay away from everything PIC16 is possible.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12458 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|