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

Timer 0 problem

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








Timer 0 problem
PostPosted: Fri Mar 14, 2008 4:07 am     Reply with quote

Hi

Why is Timer_0 int not 256us.
When I mesure on A1(the pin there are toogled in the int) there are 1khz -> 2*500us. But I expect 2*256us -> 2khz??

What is wrong here??
___

Code:
#include <18F2455.h>

#FUSES NOWDT             
#FUSES INTXT             
#FUSES NOBROWNOUT
#FUSES PUT                     
#FUSES MCLR                   

#use delay(clock=4000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=com1, errors)
 
//*** led pin assign
#define led_hw_r PIN_A0
#define led_hw_g PIN_A1

//*** led macro
#define led_g_toogle output_toggle(led_hw_g)
#define led_r_on_off(on) output_bit (led_hw_r, on)
#define led_g_on_off(on) output_bit (led_hw_g, on)

 
#int_TIMER0
void  Timer_0_int(void) {
 led_g_toogle; //I expec 256 us but there are 510 us??
}


void flashled(){
 led_r_on_off(1);
 delay_ms(100);
 led_r_on_off(0);
 delay_ms(300);
}

void main(){
  int cnt=0; 
 
  setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
  setup_adc_ports(NO_ANALOGS|VSS_VDD);
     
  setup_wdt(WDT_OFF);
  setup_timer_0(RTCC_INTERNAL|RTCC_8_bit);//1u*256 = 256us.
  setup_timer_1(T1_DISABLED);
  setup_timer_2(T2_DISABLED,0,1);
     
  enable_interrupts(INT_TIMER0);
  enable_interrupts(GLOBAL);
   
 fprintf(com1,"Reset...!\r\n");

 while (1){
  flashled();
  cnt++;
  fprintf(com1," ok:%u ",cnt);
 }
}//main//



I need some help on this.
Guest








PostPosted: Fri Mar 14, 2008 7:47 am     Reply with quote

Problem is fixed!

I think it confusing that the RTCC_DIV_1 must be included.

I found the error when looking at the T0CON bit3 was not set.

That wil say T0CON_bit3 = PSA = RTCC_DIV_1.

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1|RTCC_8_bit);//1u*256 = 256us.

Just for information :-)
Matro
Guest







PostPosted: Fri Mar 14, 2008 7:52 am     Reply with quote

Is your Xtal really a 4MHz one?

Matro
Guest








PostPosted: Fri Mar 14, 2008 8:14 am     Reply with quote

Hi

I use the internal CLK at 4 mhz.
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