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

EX_GLINT.C what sets the time of the interupt

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



Joined: 19 Nov 2003
Posts: 45
Location: Oxford

View user's profile Send private message Visit poster's website

EX_GLINT.C what sets the time of the interupt
PostPosted: Fri Dec 19, 2003 9:51 am     Reply with quote

Embarassed Soory know its a bit of thick question. What sets the interupt time in the EX_GLINT example I know the interupt must be set to interupt every two seconds-ish

thanks

dvae
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 19, 2003 3:03 pm     Reply with quote

The frequency is set by this line:
setup_counters(RTCC_INTERNAL,RTCC_DIV_32);

and also, it's determined by the crystal frequency (divided by 4).
In addition, it's set by the size of Timer0. In the 16F series PICs,
Timer0 is 8 bits. In the 18F series it can be configured as 8 or 16 bits.
So instead of having 256 counts per interrupt, if it was configured
for 16-bits, it would take 65536 counts.
homfray



Joined: 19 Nov 2003
Posts: 45
Location: Oxford

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 23, 2003 4:58 am     Reply with quote

So in the ex_glint code I would change
Code:
long counter;

   int save_w;
   #locate save_w=0x80
   int save_status;
   #locate save_status=0xFF
   
   #byte status = 0xFD8
   #bit zero_flag = status.2
   #bit t0if = 0xFF2.2


#bit t0if = 0xFF2.2 is it this section that i change

I am still unsure I can see that the setup counter will change the timing such that it is a quater of the clock cycle and that the setup_counters(RTCC_INTERNAL,RTCC_DIV_32); is a 32nd of that. But where do I add a number to count down from

I changed

#bit t0if = 0xFF2.2

to

#bit t0if = 0x222.2

and all it seemed to do was make my code not run properly
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 23, 2003 2:11 pm     Reply with quote

Tell us exactly what you want to do.
If you want to change interrupt rate, then what rate do you want ?
homfray



Joined: 19 Nov 2003
Posts: 45
Location: Oxford

View user's profile Send private message Visit poster's website

PostPosted: Wed Dec 24, 2003 2:45 am     Reply with quote

I would like to have see how you would set an interupt

every millisecond

and an interupt every half second these two should give me the knowledge to see how to adjust the code to change set the interupt time

I am using a 4MHz clock
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 28, 2003 3:08 pm     Reply with quote

Here is the example you requested.
It contains code to setup the RTCC (Timer 0) for either 1000 Hz or 2 Hz.
To test one frequency, you have to comment out the code for the
other frequency. It's currently setup for 1000 Hz. Be aware that
in the 18F458 and similar chips, the default size of Timer 0 is 16-bits.
ie., it counts from 0 to 65535, and then rolls over to 0. In the example
below, it is configured as a 16-bit counter.

This code doesn't compensate for interrupt latency, so at a low
crystal frequency of 4 MHz, the frequency of the signal on pin B1
will be off somewhat (about 5% low, on the 1000 Hz signal).
But this is a beginners example, and you can learn about
adjusting for latency later.

Code:
#include <18F458.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)

#int_rtcc
void int_rtcc_isr(void)
{
static short state = 0;

//set_timer0(34286);     // 2 Hz reload value (pre-scaler = 16)

set_timer0(64536);   // 1000 Hz reload value (pre-scaler = 1)

// Output the current state on pin B1, and then
// toggle it to the opposite value for the next interrupt.
// On the oscilloscope, you will see a 500 Hz
// squarewave, or a 1 Hz squarewave.
output_bit(PIN_B1, state);
state = ~state;

}

//===========================================
void main()
{
output_low(PIN_B1);    // Initialize Pin B1 to a low level

// Setup the RTCC to interrupt at a rate of 2 Hz.
//setup_counters(RTCC_INTERNAL, RTCC_DIV_16);
//set_timer0(34286);

// Setup the RTCC to interrupt at a rate of 1000 Hz.
setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
set_timer0(64536);

enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

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