PIC help

Status
Not open for further replies.

mr. mister

New Member
i've read the input pulse from an rf receiver into TMR0 on the PIC

i'm operating at 4MHz clock frequency, meaning 1us per instruction

thing is when i measured the pulse width with an oscilloscope, it gave the value 2.048ms

based on my calculation, a value of 1 in TMR0 will represent 1us, as i am expecting a value of 2048 to be in the TMRO, will it be too large for it???

2048 in hex and binary is way larger than 8-bits

will be timer register be able to read a value as high as this???
 
There are two solutions:
1. Use prescaller. if 2048us is a maximum, by using prescaller of 8 will result in full 8-bit number... you might loose some precision though...
2. Use Timer1 module, its able to work in 16bit mode (65535us)...
 
can i use a prescaler of 16 then? and also if 2048 will be an 8-bit number using a prescaler of 8, what will that number be in hex?? how can i find the value??
 
mr. mister said:
can i use a prescaler of 16 then? and also if 2048 will be an 8-bit number using a prescaler of 8, what will that number be in hex?? how can i find the value??
Here's list of available prescallers:
Code:
1 : 2
1 : 4
1 : 8
1 : 16
1 : 32
1 : 64
1 : 128
1 : 256
If you sellect prescaller, only every n'th pulse will be read. (where n is your prescaller value). Therefore if you receive 2048 pulses there result is:
2048/8=256 pulses and FF hex. Disadvatage of using prescaller is that you are loosing acurancy. Because only every n'th pulse is read (maximal lose is 8us accurancy)
 
basically i've used 16 as the prescaler

so 2048/16 = 128 will be the value in the TMRO assuming the pulse width read is 2.048ms, right??
 
If you search on MicroChip, there's a very old application note for a frequency counter, it has a maximum frequency of 50MHz, and auto-ranges down to low audio frequencies (where it measures the pulse width). It uses a clever way to read the full 16 bit value of the timer it uses, you could always use the same method?.

However, any remotely modern PIC (except for the really low-end ones) will have multiple timers, some of which allow you to read the full 16 bit values - TMR0 is really a pretty poor one to choose.

For that matter, why use a timer at all?, why not use a simple software loop?, you can increment as many counters as you want to give a high resolution (if you need a high resolution?).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…