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

setup_ccpX(CCP_USE_TIMER3)

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



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

setup_ccpX(CCP_USE_TIMER3)
PostPosted: Mon Oct 29, 2007 7:04 am     Reply with quote

18FXX2
no any information in CCS help file
if asinged to ccp1, still ccp1 get the content of timer 1
if asigned to ccp2, ccp2 is loaded on each interrupt with the previous containt+the new. example: first 1000 second 500, in second interrupt ccp2 is 1500. if third 2000, ccp2 is 3500 after interrupt.
this hapens also if ccp2 is cleared after moving the data !!!!!!!!!!!!!!
I test it in the simulator many times
I will apreciate a guidance
Joseph
Ttelmah
Guest







PostPosted: Mon Oct 29, 2007 8:38 am     Reply with quote

Start (always), by looking at the chip's data sheet.
There are a huge number of different CCP operations. Which do you want?.
The 'CCP_USE_TIMER3' control, specifies the clock source, but not what CCP mode is to be used. You 'or' it with the required mode. So:

CCP_COMPARE_RESET_TIMER | CCP_CAPTURE_FE

Will capture the value in the timer, when triggered. Note that this_does not reset the timer_. None of the capture modes do. This (or the RE equivalent), is what you are seeing on CCP2. On CCP1, I'd suspect the capture mode is actually 'off', so you are just seeing what used to be in the buffer.

Best Wishes
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

setup_ccpX(CCP_USE_TIMER3)
PostPosted: Tue Oct 30, 2007 3:06 am     Reply with quote

Thanks
I know how the timers are working, clearing etc'
I have other solution for my task, but again, for other people also that they maybe want to use both ccp with different timers.
18F252, 32MHz, timer increment 1us if prescaller 1:8
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_ccp1(CCP_USE_TIMER3)
setup_ccp1(CCP_CAPTURE_FE)//can be RE
still ccp1 captures timer1 and not timer3 when ccp1 interrupt occures
setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);
setup_ccp2(CCP_USE_TIMER3)
setup_ccp2(CCP_CAPTURE_FE)//can be RE
ccp2 captures timer3 and then adding (each interrupt) the new timer3 value to the previous. always "set_timer3(0);" after ccp2 interrupt.
I test it in mplab many times.
AGAIN, no mention in CCS help about (CCP_USE_TIMER3)
Joseph
Ttelmah
Guest







PostPosted: Tue Oct 30, 2007 3:15 am     Reply with quote

You don't use the setup the way you show. The last one will override the one in front. You need to use just _one_ setup line, with:

setup_ccp2(CCP_USE_TIMER3|CCP_CAPTURE_FE);

Best Wishes
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

setup_ccpX(CCP_USE_TIMER3)
PostPosted: Tue Oct 30, 2007 9:33 pm     Reply with quote

Ttelmah
I used your advice
I don't know how to attache a file. If someone have interest, I will email the zipped file CCP_TEST.rar
It will be nice to get sugestion from CCS
bellow the results:
//ccp1+timer1 works properly
//--------------------------------------
//ccp1+timer3, timer1 enabled
//ccp1=0 by instruction
//ccp1, int1, ccp1=1000, triggered after 1000us
//ccp1=0 by instruction
//ccp1, int2, ccp1=3000, triggered after 2000us
//ccp1=0 by instruction
//ccp1, int3, ccp1=6000, triggered after 3000us
//!!! ccp1 gets 1000 just if mplab closed and opened again !!!
//if just compiled, the last value before+1000
//--------------------------------------
//ccp1+timer3, timer1 disabled
//ccp1=0 by instruction
//ccp1, int1, ccp1=6000, triggered after 1000us
//ccp1=0 by instruction
//ccp1, int2, ccp1=6000, triggered after 2000us
//ccp1=0 by instruction
//ccp1, int3, ccp1=6000, triggered after 3000us
//!!! if timer1 disabled, ccp1 gets the old value of 6000 !!!
//--------------------------------------
//ccp2+timer1 works properly
//----------------------------------------
//ccp2+timer3, timer1 enabled
//ccp2=0 by instruction
//ccp2, int1, ccp2=1000, triggered after 1000us
//ccp2=0 by instruction
//ccp2, int1, ccp2=3000, triggered after 2000us
//ccp2=0 by instruction
//ccp2, int1, ccp2=6000, triggered after 3000us
//!!! ccp2 gets 1000 just if mplab closed and opened again !!!
//if just compiled, the last value before+1000
//--------------------------------------
//ccp2+timer3, timer1 disabled
//ccp2=0 by instruction
//ccp2, int1, ccp2=13000, triggered after 1000us
//ccp2=0 by instruction
//ccp2, int2, ccp2=13000, triggered after 2000us
//ccp2=0 by instruction
//ccp2, int3, ccp2=13000, triggered after 3000us
//!!! if timer1 disabled, ccp2 gets the old value of 13000 !!!
//------------------------------------------------------------
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

ccp
PostPosted: Tue Feb 12, 2008 10:04 pm     Reply with quote

PCM programmer, sorry for the new topic.
someone know how to use "CCP_USE_TIMER3" ?
I would like to use it in capture mode.
I didn't succeed, also no answer from CCS from Oct. 31, 2007.
compiler version 3.249; pic 18F252
thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 12, 2008 10:33 pm     Reply with quote

Post a short test program that shows the problem. The program must
be compilable without errors if I paste it into MPLAB and compile it.
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

ccp
PostPosted: Tue Feb 12, 2008 11:38 pm     Reply with quote

commenting out set_timer3(0); no influence
commenting out set_timer1(0); both ccp increments until overflow
joseph
Code:
#include <18F252.h>
#device adc=8
#FUSES WDT8                     //Watch Dog Timer uses 1:8 Postscale
#FUSES H4                       //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV42                   //Brownout reset at 4.2V
#FUSES PUT                      //Power Up Timer
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=32000000,RESTART_WDT)

long ccp1time=0;
long ccp2time=0;

#int_TIMER2
void TIMER2_isr()
{
   setup_timer_2(T2_DIV_BY_4,125,8);
   output_toggle(pin_C1);//triggering ccp2
   output_toggle(pin_C2);//triggering ccp1
}
#int_CCP1
void CCP1_isr()
{
   ccp1time=CCP_1;
   set_timer3(0);   
}

#int_CCP2
void CCP2_isr()
{
   ccp2time=CCP_2;
   set_timer1(0);
}

void main()
{

     setup_adc_ports(NO_ANALOGS);
      setup_adc(ADC_OFF);
      setup_spi(FALSE);
      setup_wdt(WDT_ON);
      setup_timer_0(RTCC_INTERNAL);
      setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
      setup_timer_2(T2_DIV_BY_16,255,16);
      setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);
      setup_ccp1(CCP_CAPTURE_FE|CCP_USE_TIMER3);
      setup_ccp2(CCP_CAPTURE_FE);
      enable_interrupts(INT_TIMER1);
      enable_interrupts(INT_TIMER2);
      enable_interrupts(INT_TIMER3);
      enable_interrupts(INT_CCP1);
      enable_interrupts(INT_CCP2);
      setup_oscillator(False);
   output_high(pin_C1);//starts together
   output_high(pin_C2);//starts together
   while(1)
   {
            restart_wdt();
            enable_interrupts(GLOBAL);
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 13, 2008 12:35 am     Reply with quote

Quote:

setup_ccp1(CCP_CAPTURE_FE | CCP_USE_TIMER3);
setup_ccp2(CCP_CAPTURE_FE);

You're attempting to assign Timer3 to CCP1, and Timer1 to CCP2.
But that's not allowed. The 18F452 data sheet says only three
combinations are allowed.
1. Timer1 assigned to both CCP1 and CCP2.
2. Timer3 assigned to both CCP1 and CCP2.
3. A split assignment: Timer3 for CCP2, and Timer1 for CCP1.

Here's the section from the data sheet:
Quote:

T3CCP2:T3CCP1: Timer3 and Timer1 to CCPx Enable bits
1x = Timer3 is the clock source for compare/capture CCP modules
01 = Timer3 is the clock source for compare/capture of CCP2,
Timer1 is the clock source for compare/capture of CCP1
00 = Timer1 is the clock source for compare/capture CCP modules


Try doing it this way:
Code:

setup_ccp1(CCP_CAPTURE_FE);
setup_ccp2(CCP_CAPTURE_FE  | CCP_USE_TIMER3);

This will assign:
Timer1 --> CCP1
Timer3 --> CCP2
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

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

ccp
PostPosted: Wed Feb 13, 2008 12:44 am     Reply with quote

Thank you PCM programmer and sorry for taking your's and others time for nothing. Is working perfect. I don't know how I miss this point in the data sheet!
Joseph
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