![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
pic16f688 + RTCC (Timer0 Overflow) |
Posted: Thu Feb 27, 2014 11:26 am |
|
|
Hello everybody. Well, I've been struggling with this for a while.
I want to turn on and off a pin with the timer0 interruption without luck, the time is about 1us, however, when I configure the time in the program, the result it's not the desired. Here is the code.
Code: | #include <16F688.h>
#fuses XT, NOWDT, NOBROWNOUT, NOPUT, INTRC
#use delay(clock=4000000)
#int_RTCC
void RTCC_isr(void)
{
clear_interrupt(INT_TIMER0);
output_toggle(PIN_c2);
set_rtcc(255);
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
clear_interrupt(INT_TIMER0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
set_timer0(0);
while(true){
}
} |
According to my math, with the prescaler of 1, a clock of 4MHz, I can get an overflow every 256us with a resoultion of 1us. If I set the timer0 with a value of 255 I will interrupt it every 1us. However, the oscilloscope shows that the interruption is executed every 62us, I've tried to change with known values without getting something consistent with the math.
Thank you guys. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Thu Feb 27, 2014 1:26 pm |
|
|
Thanks. It helped a lot. But to be honest, my question is not regarding how to set up a TIMER0. My questions is referred why my PIC can't toggle a pin in 1us using the TIMER0. I'm configuring my TIMER0 to overflow every 256us, I set the TIMER0 with a value of 255, in that way the next interruption will be at 1us, right?. Is there any change that the hardware is not capable of interrupting that fast?.
Regards... and thanks for your help. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Thu Feb 27, 2014 1:45 pm |
|
|
Got it. I have to speed up my clock source. damn!!!!! Thank you guys. It's a shame that everything works on paper. _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Re: pic16f688 + RTCC (Timero Overflow) |
Posted: Fri Feb 28, 2014 3:23 am |
|
|
quicksilver wrote: | Hello everybody. Well, I've been struggling with this for a while.
I want to turn on and off a pin with the timer0 interruption without luck, the time is about 1us, however, when I configure the time in the program, the result it's not the desired. Here is the code.
According to my math, with the prescaler of 1, a clock of 4MHz, I can get an overflow every 256us with a resoultion of 1us. If I set the timer0 with a value of 255 I will interrupt it every 1us. However, the oscilloscope shows that the interruption is executed every 62us, I've tried to change with known values without getting something consistent with the math.
Thank you guys. |
Depends on exactly what you're trying to do.
What you are seeing is about the best you can do using the interrupts.
It takes so many machine cycles to get in and out of the interrupt routine.
So this forces a limit on what you can/can't do.
Anything above this limit can work, anyting below will be clamped as you've found out the hard way.
(We all have to learn.)
If you want to generate a well controlled square wave with us precision in the range 1 to 255us then look at using the hardware PWM.
Your existing 4MHz clock will do the job for you.
Mike
EDIT
You will, of course, have to change to a different PIC.
Either a 14pin equivalent with PWM or a bigger PIC.
Last edited by Mike Walne on Fri Feb 28, 2014 6:59 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19383
|
|
Posted: Fri Feb 28, 2014 6:00 am |
|
|
Just as a comment, _one clock only_...
Currently the poster has both internal RC, and external crystal selected.... |
|
![](templates/subSilver/images/spacer.gif) |
quicksilver
Joined: 04 Feb 2009 Posts: 31
|
|
Posted: Fri Feb 28, 2014 8:30 am |
|
|
After setting up several TIMER0 values, I came up with the solution. There is a limit in the value that you can set up. In this case that the it's 8 bit timer, there is no way to load a value of 255 or even 254, the maximum value that you can set is 250. I have tried and I'm pushing the PIC to its limit.
My advice, by the time to work with timer, it is necessary to on hand several clocks, and try setting several timer values. if there is no way to get time desire value, try changing the prescaler and the clock.
I appreciate all your effort and comments, it helped a lot. ![Razz](images/smiles/icon_razz.gif) _________________ everything that has a beginning, has an end |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|