CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem comprehending timer0 in a 16F88

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Woody



Joined: 11 Sep 2003
Posts: 76
Location: Warmenhuizen - NL

View user's profile Send private message

Problem comprehending timer0 in a 16F88
PostPosted: Mon Nov 06, 2006 4:06 pm     Reply with quote

Hi,

Normally all my questions are answered searching this forum but this time I seem to not be able to find a solution. Probably I acquired tunnel vision from looking too long at this.

Here's my problem:

The CPU is a 16F88. It runs on INTRC, 8MHz. I set timer 0 as using the internal clock, with a DIV_4 prescaler. TMR0 is preset to 6, getting a rollover (and an interrupt) in 250 timercounts. In the timer interrupt routine TMR0 is preset to 6 again. Then a pin is toggled.

The pulse I expected to see on the toggled pin would be:
8 MHz / ( 4 (instruction clock) * 4 (prescaler) * 250 (rollover) ) = 2000 or 1 interrupt every 500uS giving me a pulse with a period of 1 ms.
The pulse i actually see on a scope has a period of 2 ms or every 1 ms an interrupt.

I'm pretty sure my reasoning is flawed, but where?

Here's the code:

Code:

#case

#include "16F88.h"

#fuses PROTECT, NOMCLR, INTRC_IO, BROWNOUT, NOWDT, NOCPD, PUT, NOLVP

#use delay(clock=8000000)


#byte TMR0 =0x01

#byte OSCCON = 0x8F
#byte OSCTUNE = 0x90

#define RA3 PIN_A3
#define INT_TEST RA3



// Program and subroutines:

void init(void) {

   //   Internal oscillator 8 MHz
   OSCCON = 0b11100000;
   // Center frequency
   OSCTUNE = 0b00000000;


   // Set timer0
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);

   TMR0+=6;

   enable_interrupts(INT_RTCC);   // Enable timer0 interrupt
   enable_interrupts(GLOBAL);      //

}


#INT_RTCC
void clock_isr(void) {

   // Eerst de timer weer ijken op 250 counts voor interrupt
   TMR0+=6;

   output_toggle(INT_TEST);

}


void main() {

   #zero_ram

   init();

   while(TRUE) {

   } // end while true

} // end main


Compiler version is 3.248.

I hope somebody can set me straight about this. Thanks for your time.

Paul
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Mon Nov 06, 2006 4:19 pm     Reply with quote

Try reading this and see if it helps:

http://www.ccsinfo.com/forum/viewtopic.php?t=22467


John
Woody



Joined: 11 Sep 2003
Posts: 76
Location: Warmenhuizen - NL

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 2:42 pm     Reply with quote

I read that. Before. And it did not help.

But fortunately I figured it out on my own. As stated, I looked at this problem for some time, which turns out not to be too productive. Letting the project be for two days and then setting OSCCON to the right value (0b01110000 instead of 0b11100000) solved my problem. Sometimes I just fail to see the bits in the byte.

Thanks for your time,

Paul
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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