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

Periodic interrupt 30 uS

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



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

Periodic interrupt 30 uS
PostPosted: Wed May 07, 2014 4:34 am     Reply with quote

Hi all, I've never used the CCP before, and I need to have a regular 30 uS interrupt.

I have created this code, but I don't get any interrupts.

Code:


#define T3INTERVAL 960

 void sample_init(void)
{
   
   // timer
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);
   
   // ccp
   setup_ccp3(CCP_COMPARE_INT);
   enable_interrupts(INT_CCP3);
   CCP_3 += T3INTERVAL;
}

#int_ccp3
void timer3ccpinterrupt()
{
   CCP_3 += T3INTERVAL;
}


compiler V 5.025
PIC 18F26K22
clock is 64 MHZ
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed May 07, 2014 5:17 am     Reply with quote

Your 'code' is just code..not a real program so no one here can 'cut/paste/test'.
Please post your entire program,it'll make life a lot easier.

hth
jay
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Wed May 07, 2014 6:39 am     Reply with quote

temtronic wrote:
Your 'code' is just code..not a real program so no one here can 'cut/paste/test'.
Please post your entire program,it'll make life a lot easier.

hth
jay


Heres my test program.

Code:
// testccp.c

#include <18F26K22.h>
#device CONST=ROM
#device ADC=8

#FUSES BROWNOUT                  //No brownout reset
#FUSES PUT                       //Power Up Timer
#FUSES HSM                       //External oscillator
#FUSES PLLEN                     //enable the x4 PLL
#use delay(clock=64M, crystal = 16M)           

#define CLOCK     PIN_C0
#define T3INTERVAL 960

void sample_init(void)
{
   // timer
   setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);
   
   // ccp
   setup_ccp3(CCP_COMPARE_INT);
   enable_interrupts(INT_CCP3);
   CCP_3 += T3INTERVAL;
}

#int_ccp3
void timer3ccpinterrupt()
{
   CCP_3 += T3INTERVAL;
   
   output_high(CLOCK);
   output_low(CLOCK);
}


void Initialise()
{
   delay_ms(100);

   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   
   sample_init();
   enable_interrupts(GLOBAL);
}


void main()
{
   Initialise();                       //configure uC for operation
   
   while(1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19543

View user's profile Send private message

PostPosted: Wed May 07, 2014 9:35 am     Reply with quote

Why do it with the CCP?.

Timer2. T2_DIV_BY_4. PR2=143.

Interrupt every 2304 clocks. 36uSec.

Keep it simple.

The reason it is not working, is the timer. CCP_USE_TIMER3_AND_TIMER4 is needed. Currently the CCP is running off timer1 (the default).

Best Wishes
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu May 08, 2014 1:28 am     Reply with quote

Thanks Tt.
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu May 08, 2014 3:10 am     Reply with quote

Supplementary question:-

What is the interrupt latency? is it 3 cycles + 2 to stack the PC?
Ttelmah



Joined: 11 Mar 2010
Posts: 19543

View user's profile Send private message

PostPosted: Thu May 08, 2014 3:21 am     Reply with quote

No. About 30 instructions.
_Every_ register used inside the interrupt code, has to be saved.....
The compiler (unfortunately) defaults to saving everything.

Now, if your interrupt code is simple. One interrupt, and you only do basic operations like talking to an I/O pin, or incrementing a counter, then you can elect not to save the registers, by writing the handler as 'INT_GLOBAL'. You then save just the registers you need. Still be perhaps five instructions minimum. Remember your code then also needs to clear the interrupt flag, and restore the registers before exit. On the PIC18, certain basic registers (BSR, STATUS, and WREG), are saved for you by the hardware. These are restored by the RETFIE 1 instruction at the end of the handler. Unfortunately the saving this produces is 'lost' because of the number of other registers present.

The PIC is not the chip to choose for really fast interrupt handling. Many much older chips have the ability to save all the registers with just one instruction, or have alternative register sets for interrupt use.
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu May 08, 2014 10:17 am     Reply with quote

Yikes!

Is it 30 on entry plus 30 to restore on exit?
Ttelmah



Joined: 11 Mar 2010
Posts: 19543

View user's profile Send private message

PostPosted: Thu May 08, 2014 11:30 am     Reply with quote

Actually about 28 each end. However if you reckon on 60 instruction times to get into and out of an interrupt you won't be far off....
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