I've set up the timer0 on my PIC18F2550 to record time intervals, however I am not sure how to convert this reading into seconds. The oscillator is running at 1Mhz, timer0 is set to 16bit, the prescaler is on 1:1, and the timer is using the internal oscillator. The integer value I am reading off the timer is 6153 - what do I have to do to this number to give me a number in seconds?
I've set up the timer0 on my PIC18F2550 to record time intervals, however I am not sure how to convert this reading into seconds. The oscillator is running at 1Mhz, timer0 is set to 16bit, the prescaler is on 1:1, and the timer is using the internal oscillator. The integer value I am reading off the timer is 6153 - what do I have to do to this number to give me a number in seconds?
hi,
Its usual to set the TMR0 to an integer sub multiple of a second, set the TMR0 to interrupt and use a register counter to count the interrupts until the count reaches 1second. OK.?
If all you're asking is how to convert 6153 instruction cycles into seconds, then just divide it by the instruction cycle frequency (which is fosc/4 or 250kHz). 6153/250k = 0.024612 seconds.
Thanks for the replies. I'm integrating the output from a gyroscope to give me the angular displacement at a certain time - is this method of timing going to be accurate enough? Wp100, you say I should use timer1 - is the timing crystal just more accurate?
Thanks for the replies. I'm integrating the output from a gyroscope to give me the angular displacement at a certain time - is this method of timing going to be accurate enough?
I take it the gyroscope sends digital information (I mean PWM or PPM e.g.). You probably want as much accuracy as you can get (although I've no idea how much you need for your application), as when you integrate, you're summing the error as well. Increasing the clock rate will increase the timing resolution/accuracy.
There's no reason why the crystal would be any more accurate. Also, 32kHz gives worse timing resolution than your fosc/4. Using timer 1 (or 3) allows you to utilise the CCP (compare / capture) module which lets the hardware capture the timer value when, e.g., a pin changes. This gives you better precision than if you try to capture the timer value on change in software (due to variable interrupt latencies etc.). I would recommend using the main oscillator to clock the timer (don't bother with the 32kHz one).
I've set up the timer0 on my PIC18F2550 to record time intervals, however I am not sure how to convert this reading into seconds. The oscillator is running at 1Mhz, timer0 is set to 16bit, the prescaler is on 1:1, and the timer is using the internal oscillator. The integer value I am reading off the timer is 6153 - what do I have to do to this number to give me a number in seconds?