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 CCS Technical Support

Question about timer0

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Question about timer0
PostPosted: Wed Jan 13, 2010 8:29 am     Reply with quote

Hi, am working with a Pic16f88 to 20MHz, someone please can tell me what means ?
Code:
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);


and what is the formula to get the value of Periodo to place in
Code:
set_timer0(Periodo);   
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 13, 2010 9:26 am     Reply with quote

It means you are using the MCU clock for timer0 and using a divider of 2. Timer0 can be operated in either 8 or 16 bit mode in most(?) 16 or 18 series PICS (check the datasheet). The basic tick is (Fosc/4/divider) in frequency so if your Fosc = 20M your basic timer0 tick lasts 0.4 us in duration. In 8 bit mode timer0 counts from whatever value you set it to up to 255 so the total time is 0.4us*(255 - set_value). In 16 bit mode the total time is 0.4us*(65525- set_value). So if you know how long you want your period to be you can just use do:

Code:

set_timer0(set_value);

where set_value is int8 for 8 bit mode and int16 for 16 bit mode.
Guest








PostPosted: Mon Jan 18, 2010 10:26 am     Reply with quote

Hi, I am use a pic16f88 to 20MHz and I am use the detector RB0/Int pin to detect the Zero crossing, like I need short pulses each half cycle for that I am use the INT_TIMER0, my problem is that the pulses are outdated and do not correspond to 8.33ms as this made the calculation.
Someone can help me?

Code:
#include <16F88.h>
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOCPD,NOWRT,NODEBUG
#use delay(clock=20000000)
#use fast_io(A)
#use fast_io(B)

#byte PORTA                = 0x05
#byte PORTB                = 0x06
#bit  LED_ROJO             = PORTA.2
#byte ANSEL                = 0x9B
#byte OPTIONREG            = 0x81
#define Semi_Ciclo         156
int Contador;
int i,j;

#INT_TIMER0
void tempo0(){
   
   Contador++;
if (Contador == 208){
   LED_ROJO=1;
   Delay_us(20);
   LED_ROJO=0;
   Contador = 0;
   }
}

#INT_EXT
void CrucePor0()
{
   set_timer0(Semi_ciclo);
   if (j==0){
   j=1;
   ext_int_edge(H_TO_L);
   }
   else {
   j=0;
   ext_int_edge(L_TO_H);
   }
}


void main()
{
   set_tris_B(0b11001101);
   set_tris_A(0b00011000);
   ANSEL=0;
   OPTIONREG=OPTIONREG & 0x7F;     

   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_EXT);
   ext_int_edge(L_TO_H);
   enable_interrupts(GLOBAL);
   set_timer0(Semi_ciclo);
   
   while(1);
 }
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