I had a question...but connected the dots when I posted it.
I had a question...but connected the dots when I posted it.
Last edited by dw_picbasic; - 19th February 2014 at 21:12. Reason: tried to remove the question....got it :-]
Hi Darrel,
I'm curious about something in the code
I see that you capture the Timer1 overflow count and load it into RESULTS.[bit16-31]
Then load the remaining count in TMR0 into RESULTS.[bit8-15]
But I thought that TMR0 is a 16 bit register....how is it we're loading its value into an 8 bit location in RESULTS?
Thanks!!
Duane :-]
Hi Duane,
No, the TMR0 register is only 8 bits wide, that's why you need to use the trick with getting the remaining count out of the prescaler.
So, RESULT is a total of 4 bytes where the two most significant bytes are the number of TMR0 overflows, the next byte is the TMR0 count (where each count equals 256 transitions of the inputsignal due the 1:256 presacaler ratio) and the least significant byte is the number of transitions "stored" in the prescaler.
/Henrik.
Ah!
Thats right!!...sorry... I forgot the Timer0 is an 8 bit register.
I slipped on that one :-/
Thanks!
Can I pose another question:
Lets say that the frequency that is being measured within the 1 second gate period is 301234hz
Is it the case that the value that will be captured within T0overflow, RESULTS.[bit16-31] = (301234/256)?
Which (in integer form) would resolve to 1176 overflows of the Timer0 8 bit register?
And then the remainder value of 178, which remains within TMR0 will be loaded into T0value RESULTS.[bit8-15]?
Thanks!!
Duane
The prescaler divides by 256, and TMR0 divides by 256.
So the overflows only happen every 65536 counts.
With a frequency of 301234, there will only be 4 overflows, with 39090 remaining.
That's 152 in TMR0, and 178 in the prescaler.
Another way to look at it is to convert the Frequency to a HEX number
#301234 = $4:98B2
Now it's easy to see that there will be 4 overflows, TMR0 will have $98 = 152, and the prescaler has $B2 = 178.
HTH
DT
Thanks Darrel,
I didn't see the prescaler settings in setup code.
I see "PSA [OPTION_REG.3] set to 0 which sets the prescaller from the WDT to Timer0
But I don't see any settings for OPTION_REG.0, 1 and 2.
Are they there in the code and I missed them?
Thanks!!
Duane
Hello Darrel,
found your excellent example and i would like to build the same counter based on PIC16F870. From your above post i understand, that with prescaler 256 minimum measured frequency is 65536Hz, otherwise TMR0 will not overflow, or am i wrong? To measure lower frequencies i would have to change the OPTION_REG bits 2-0 , which will set prescaler to 1:2?
P.S. My target measurement range is 1 HZ - 1 MHz.
Last edited by Rufinus; - 16th March 2015 at 14:53.
Bookmarks