are you sure you have implemented
TMR0 overflow correctly for
a 16F690? i am measuring half the frequency
you quote, admittedly with a dodgy frequency counter. i am suspicious cos the 690 datasheet quotes 8 prescalers but you implement 9 including 1:1 not on datasheet.
sorry about poor typing on this phone!
TMR0 prescalers
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: TMR0 prescalers
Hello,
I've had a look through and the code for the timers is the same for pretty much all the PIC devices.
The 1:1 prescaler is not on the datasheet but what we are doing is essentially passing the prescaler to the watchdog timer and therefore the timer is clocked directly eg 1:1.
Have you set your clock speed correctly in the project options window? If this is incorrect then the quoted interrupt speed will also be incorrect.
I've had a look through and the code for the timers is the same for pretty much all the PIC devices.
The 1:1 prescaler is not on the datasheet but what we are doing is essentially passing the prescaler to the watchdog timer and therefore the timer is clocked directly eg 1:1.
Have you set your clock speed correctly in the project options window? If this is incorrect then the quoted interrupt speed will also be incorrect.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: TMR0 prescalers
I have the right 8MHz set and 1:1
prescalers.
I am using c code tmr0=55; to reload 55 so it overflows at 200instead of 255.
I not that I have to reload this at every interrupt else it defaults back to 255. is there a way to stop it defaulting?
prescalers.
I am using c code tmr0=55; to reload 55 so it overflows at 200instead of 255.
I not that I have to reload this at every interrupt else it defaults back to 255. is there a way to stop it defaulting?
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: TMR0 prescalers
Hello,
For perfect timing your 1:1 prescaler is going to cause problems. Normally with a larger pre-scaler you get at least a couple of instructions before the timer count value is incremented and therefor you can reliably alter the value of the count register. With a pre-scaler of 1:1 you may have to be careful that the timer has not already counted a few times before you even get to update the value. Therefore you may have to tweak your value a bit to give you the correct timer delay. You can see what the timer count value has reached by using the following C code at the start of your interrupt macro.
FCV_VAR = tmr0;
This should allow you to tweak the value correctly.
Timer 2 if it exists on your device normally can be given a non standard rollover value.
The timer causes an interrupt at count 256 (0) so you should probably change your count value to 56.I am using c code tmr0=55; to reload 55 so it overflows at 200instead of 255.
For perfect timing your 1:1 prescaler is going to cause problems. Normally with a larger pre-scaler you get at least a couple of instructions before the timer count value is incremented and therefor you can reliably alter the value of the count register. With a pre-scaler of 1:1 you may have to be careful that the timer has not already counted a few times before you even get to update the value. Therefore you may have to tweak your value a bit to give you the correct timer delay. You can see what the timer count value has reached by using the following C code at the start of your interrupt macro.
FCV_VAR = tmr0;
This should allow you to tweak the value correctly.
Timer 0 cannot usually be given a non standard rollover value and so it must be done manually.I not that I have to reload this at every interrupt else it defaults back to 255. is there a way to stop it defaulting?
Timer 2 if it exists on your device normally can be given a non standard rollover value.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: TMR0 prescalers
in my application I will actually count the interrupts, compare against 50hz mains and adjust TMR0 automatically to get the interrupt frequency right. it would be better to use another timer especially with 16bit register as it gives finer tuning changes but, as flowcode
does not simulate them it is harder to develop the software. Once I know the software works
I may use another timer.
does not simulate them it is harder to develop the software. Once I know the software works
I may use another timer.
Re: TMR0 prescalers
1) Are any of the interrupts TMR0, 1, 2 any faster in execution time (less processor load) than any other one? I need to execute 2 analogue reads, some calculations and the LED toggling within a 50usec interrupt time and still leave time to spare to complete other code outside the interrupt time. At moment it can do it in about 20usec so I have 30usec spare for the other code but I’d like to make it faster if possible. Clock is now 20MHz.
2) For the avoidance of doubt, when you list the interrupt frequency as say 1221Hz (equivalent to a period of 82usec) I assume you mean one call of the interrupt macro every 82usec. It is presumably not like a square wave of 50:50 mark space ratio and you are not calling the interrupt macro BOTH on the rising and falling edges of the positive half wave to give 2 interrupt macros per 82usec.
2) For the avoidance of doubt, when you list the interrupt frequency as say 1221Hz (equivalent to a period of 82usec) I assume you mean one call of the interrupt macro every 82usec. It is presumably not like a square wave of 50:50 mark space ratio and you are not calling the interrupt macro BOTH on the rising and falling edges of the positive half wave to give 2 interrupt macros per 82usec.